CSE 1020 - Programming test 1

Phase 1

Present the user with the following prompt.
The amount of gold in grams:
The entry has to be made on the same line as the prompt.

Phase 2

Next, expand your program to read the entered amount. You may assume that the user always enters a nonnegative integer.

Here is a sample run (including the integer entered by the user):

The amount of gold in grams: 950

Phase 3

Next, expand your program to print the current value of that amount of gold. To determine the value, you have to use the class GoldPrice, whose API can be found here. Print the value using two digits of precision.

Here is a sample run (including the output and input of the earlier phases as well):

The amount of gold in grams: 950
The current value is $ 28722.83

Phase 4

Next, expand your program by prompting the user with the following.
The number of weeks ago?

Phase 5

Next, expand your program to read the entered number. You may assume that the user always enters a nonnegative integer.

Here is a sample run (including the output and input of the earlier phases as well):

The amount of gold in grams: 950
The current value is $ 28722.83
The number of weeks ago? 7

Phase 6

Finally, expand your program to print the difference between the current value and the value of the amount of gold the given number of weeks ago. Again, you have to use the class GoldPrice. If the current value is greater, then a positive number is printed. If the current value is smaller, the a negative number is printed. Print the difference using two digits of precision.

Here is a sample run (including the output and input of the earlier phases as well):

The amount of gold in grams: 950
The current value is $ 28722.83
The number of weeks ago? 7
The difference is $ -1887.05

Here is another sample run (including the output and input of the earlier phases as well):

The amount of gold in grams: 1250
The current value is $ 37793.20
The number of weeks ago? 4
The difference is $ 2860.20