String Variable - Introduction Programming Methodology - Lab | CSC 120, Lab Reports of Computer Science

Material Type: Lab; Class: Intro Programming Methodology; Subject: Computer Science; University: Fayetteville State University; Term: Fall 2004;

Typology: Lab Reports

Pre 2010

Uploaded on 08/01/2009

koofers-user-481
koofers-user-481 🇺🇸

9 documents

1 / 2

Toggle sidebar

This page cannot be seen from the preview

Don't miss anything!

bg1
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.
pf2

Partial preview of the text

Download String Variable - Introduction Programming Methodology - Lab | CSC 120 and more Lab Reports Computer Science in PDF only on Docsity!

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.
  1. Add to your program, statements to output the strings outStr01, outStr02 , outStr03, outStr.
  2. Save changes, compile and run the program with the following sets of input values a. 58, 45, 89 b. 58, 58, 78 c. 45, 67, 80 d. 89, 76, 45
  3. Print your program thus far and submit to the instructor.
  4. Remove or comment out the entire if statements in the program.
  5. Add to the program, a. an appropriate if statement to assign to outStr01 , the string first integer is less than second , if aInt is less than bInt ; first integer is less than second and also less than third , if aInt is less than bInt and also less than cInt ; and first integer is greater than second and third , otherwise. b. Appropriate if statement to assign to o utStr02 , the string first integer is greater than or equal to second , if aInt is greater than bInt ; first integer is greater than or equal to second and also greater than and equal to the third , if aInt is greater and equal to bInt and also greater than and equal to cInt; and first integer is less than second and third , otherwise.
  6. Repeat steps 9-10 above.