Homework 2 CMP12a Winter 2002 (Ira Pohl and Scott Brandt)

Due 1/21/2002, before midnight.

Conditionals - Converting Currency - Revisited

This graded assignment is your own work.
-Ira Pohl and Scott Brandt

This is a further elaboration of Homework 1.

Now that Europe has converted to the Euro we wish to provide a program that tells how to convert from Euros to dollars and vice versa. We will write a program to find Euro to Dollars and Dollars to Euros for several values. Assume that each Euro is worth $0.87.

We want to know how many dollars we get for an inputted number of Euros.

We also want to know how many Euros our dollars convert to.

Unlike Homework 1 we want the user to be prompted for console input. Make sure that your prompt is readable and easily understood by a user.

The user should be asked first whether they want dollars to Euros or Euros to dollars.

Then they should be asked for the amount.

Keep in mind that you should code your java program and debug its logic before coming to the terminal. Writing
programs at the terminal is guaranteed to take you longer than writing them on paper with the book open for consultation.

Do this problem with double variables so that the answers will include cents. This program will involve both input, conditional and loop statements and so it generalizes Homework 1.

You should in your initial prompt customize by saying something like

"Welcome to Betty's Bank of Commerce in gorgeous Luxembourg."

"Here are your instructions: Enter 1 for Euro's to Dollars, .... "

"Enter How many ..."

After the input is done the program should write out the answer. "You get xxx for yyy"

The program should ask about a further transaction - this should be done with a simple while loop.

The program should terminate when the typed in input is 0 (dollars or Euros). Such a value is called a sentinel value. The loop looks for this value to terminate. This is an important programming technique.

Hints: Read about if-else statements. Then code the problem for one request without a loop. As usual do this away from the terminal and hand simulate your code. Then enter your java source file and debug this version of the code. When done submit this code. Then start revising the code to include the while loop. Again read in chapter 3 about while loops. Understand how they work and try out some simple examples. Then modify your code to execute the conversion as a loop. Submit this code. It will supercede the simpler program.