CS 1054: Lab 6
Lab meeting 6: More sophisticated behavior
This lab has the following objectives: understand the usage of the Random and
StringTokenizer java library classes and to write documentation using the javadoc utility.
Using the Random class
-
Open the BlueJ environment.
-
Create a new project. Go to the Project menu and select "New Project....". Name
this project lab6.
-
You might want to have a copy of the
Chapter 5: More sophisticated behavior
notes open in another window (Shift+Click to open in another window).
-
To get more information about the Random library class, which we will use in
this lab, refer to the standard
Java API documentation
(Shift+Click to open in another window). In the bottom-left frame, find the
link corresponding to Random and click on it. The details about that class
should be revealed in the right frame. Perform the task mentioned in Exercise
5.13.
-
Add a new class to the project by clicking on the "New Class" button on the
left. Name this class "RandomTester". Do Exercise 5.14.
-
Perform the tasks in Exercises 5.15, 5.16, 5.17 and 5.18.
-
Show your work to the GTA.
Using the StringTokenizer class
-
Add a new class to the project by clicking on the "New Class" button on the
left. Name this class "TokenizerTest".
-
Perform the tasks specified in Exercises 5.31 and 5.32.
-
Consider the following string "John Doe,12345678,123 Lonely Lane,Blacksburg
VA,(540) 555 5555". In the TokenizerTest class, declare a instance variable of
type String. Initialized this variable to the string indicated above in the
constructor method of the class.
-
Create a method called breakupAndPrint() that has a String as its formal
parameter. The String should be in the format specified above, i.e., individual
fields separated by commas. The method should use the StringTokenizer class to
break up the input string into tokens and print them out. Make sure that you
import the correct package name at the beginning of the file to use the
StringTokenizer class.
-
Remember to use the appropriate constructor for the StingTokenizer class that
allows you to specify the delimiter as a comma.
-
If the above string was broken up, the output should be something like this
Name = John Doe
SSN = 123456789
Address = 123 Lonely Lane
City = Blacksburg
State = VA
Zip = 24060
Phone number = (540) 555 5555
-
Show your work to the GTA.
Writing Documentation with javadoc
-
For the TokenizerTest class, BlueJ has generated a little sample documentation
for you. Refer to section 5.10 for more information about using javadoc.
Complete the documentation by replacing the generic comments at the beginning
of the file and each method with more specific comments indicating the purpose
of the class and methods.
-
Replace the strings indicating author, version for the class and the @param,
@return fields for each method in the class. Refer to Exercises 5.42 and 5.43.
-
Generate the javadoc documentation by clicking on the Tools menu and selecting
"Project documentation". Examine the documentation and make sure it is
adequate. You can go back to the source code and make necessary changes.
-
Show your work to the GTA.
© Mir Farooq Ali 2003.