Overview
This lab gives you practice with the following java functionalities:
- Using while loops to perform basic validation of user input.
- Using for loops to repeat a block of code
LEGEND: Keyboard Screen
Task 1: SumOfNumbers
Based on task 1 on p. 242 of the textbook.
- Write a program that asks the user for a positive nonzero integer value. The program should use a loop to get the sum of all the integers from 1 up to the number entered. For example, if the user enters 7, the loop will find the value of 1+2+3+4+5+6+7.
- Use JOptionPane for both input and output.
- Check the user input to make sure it is greater than 0. If the user enters 0 or a negative integer, inform them of their error and prompt them to try again.
Task 2: MillionaireTimeline
Based on task 4 from page 242 of the text.
- Write a program to calculate how long it will take for the user's investment to reach a value of $1,000,000.
- User enters two values: current value of investment and percent increase per year.
- For example, if the current value is $72,000.00, and it is expected to grow by 10% per year, then after one year it will have earned $7,200.00 for a net worth of 79,200.00; then the second year it will earn $7,920...
- User input should be via JOptionPane
- User input should be checked to ensure that both values are greater than 0. If user enters an incorrect value, allow them to try again.
- Output should be a formatted summary report displayed in the Console window (System.out) including
- A summary of the parameters at the top of the report (current value & projected annual growth rate)
- A table displaying the earnings and total value for each consecutive year up until the total value is over $1,000,000.00.
Thank you for using MillionaireTimeline! Your initial parameters were: Current value: $72,000.00 Projected growth rate: 10.0% per year Year Earnings Total Value ---- -------- ----------- 0 - $72,000.00 1 $7,200.00 $79,200.00 2 $7,920.00 $87,120.00 ... 27 $85,810.87 $943,919.58 28 $94,391.96 $1,038,311.54 Congratulations! After 28 years, you will be a millionaire! Your investment will be worth $1,038,311.54.
Challenge Tasks
- Update your SumOfNumbers program from task 1 above to do more robust checking of the user input. Before parsing the input as an integer, check to make sure that it has only digits (no decimal point or other characters). If the user enters something that cannot be parsed as an integer, inform them of the specific problem and allow them to fix it.
- Update MillionaireTimeline to accept one additional item from the user: an additional amount to be invested each year. Update the chart to include the added deposits.
Thank you for using MillionaireTimeline! Your initial parameters were: Current value: $72,000.00 Annual contribution: $3,000.00 Projected growth rate: 10.0% per year Year Contribution Earnings Total Value ---- ------------ -------- ----------- 0 - - $72,000.00 1 $3,000.00 $7,200.00 $82,200.00 2 $3,000.00 $8,220.00 $93,420.00 ... 24 $3,000.00 $88.333.88 $974,672.73 25 $3,000.00 $97,467.27 $1,075,140.01 Congratulations! After 25 years, you will be a millionaire! Your investment will be worth $1,075,140.01.
