
CSC 120: Introduction to Programming Methodology
Programming Lab
Fall 2004
1. Write a program containing the following.
a. A string variable declaration (assume the variable to be inputStr).
Initialize the variable to “Nothing”.
b. A declaration for an object of BufferedReader (name it inData).
Initialize the object to accept data from the object System.in tied to the
keyboard.
c. A declaration for an object of StringTokenizer (name it tokenizer).
d. A statement to prompt the user to enter three integers using the keyboard.
e. A statement to initialize the object tokenizer to a string of three integers
read from the keyboard using the inData.
2. Save the program to file whose name is the same as that of the class with and
extension .java. If the name of your class is TestIfDriver, the file name should be
TestIfDriver.java.
3. Compile and run your program. Debug to correct all syntactic errors, if any. Do
not continue until your program is free of errors.
4. Add to the program, declarations for three integers (name them aInt, bInt, and
cInt). Assign the tokens in the tokenizer to the integral variables.
5. Add statement(s) to output the values of the integral variables. For example, if the
input string was 4 5 6, the printed output should be
You have entered
First integer = 4
Second integer = 5
Third integer = 6
6. Save the changes and repeat step 3.
7. Add to the program,
a. declarations for string variables (name them outStr01, outStr02,
outStr03, outStr04) and assign the value “Nothing” to them.
b. appropriate if statement to assign to outStr01, the string first integer is
less than second, if aInt is less than bInt or first integer is greater than
second, otherwise.
c. appropriate if statement to outStr02, the string second integer is greater
than or equal to the third, is bInt is greater than or equal to cInt or
second integer is less than the third, otherwise.
d. appropriate if statement to assign to outStr03, the string first integer is
greater than or equal to second and third, if aInt is greater than and
equal to bInt and cInt or first integer is less than second and third,
otherwise.
e. appropriate if statement to outStr04, the string first integer is either
greater than the second or less than third, is aInt is either greater than
bInt or less than the cInt or first integer is not greater than second and
greater than the third, otherwise.