Lab 5
Using lab 4 and the programs presented in lecture 6 as a model,
write the following program to practice Java IO.
Modify your lab 4 program so that if the user enters A or a,
a function is called to allow the user to enter an integer.
Your function will read in the integer into a local variable
and echo print it to the screen as shown in the execution below.
If the user enters B or b, call a function that allows the user
to enter a double. The function should read the double into a
local variable and print it to the screen with 2 places after the
decimal.
If the user enters C or c, call a function that allows the user
to enter a string. The function should read the string into a local
variable and convert it to all capital letters and then print the
converted string to the screen.
The user should be able to continue making choices until s/he wants to
quit.
Notice how we proceeded with this problem. With lab 4, we began
with a plan that broke a big problem down into smaller problems.
This is called "top down design." We implemented this as a skeleton
program and tested it. We then defined the tasks to be performed
by each function. This is called "step-wise" refinement. We
encourage you to implement each of these functions one at a time
to make debugging easier.
In order to get any credit,
you must create a typescript file with your listing, compilation and execution
and email it
to your TA.
Click here for help making a
typescript.
Sample Execution
Use the values in the sample execution above.
Your execution should match the one given.
> java iopractice This program is is practice with Java IO. Please enter A to practice ints, B to practice doubles, C to practice strings, or Q to quit: a Please enter an integer: 99 You entered: 99 Please enter A to practice ints, B to practice doubles, C to practice strings, or Q to quit: B Please enter a double: 3.14159 Your number with 2 places after the decimal is: 3.14 Please enter A to practice ints, B to practice doubles, C to practice strings, or Q to quit: c Please enter a word in lower case:java Your word in all caps is: JAVA Please enter A to practice ints, B to practice doubles, C to practice strings, or Q to quit: b Please enter a double: 762.8899 Your number with 2 places after the decimal is: 762.89 Please enter A to practice ints, B to practice doubles, C to practice strings, or Q to quit: x Error in input, try again. Please enter A to practice ints, B to practice doubles, C to practice strings, or Q to quit: q Program Over, Bye!!!