Question: Create a new Java class called: Investment Write a program that will calculate how many years it will take to double the amount of money

Create a new Java class called: Investment

Write a program that will calculate how many years it will take to double the amount of money in an investment.

As an example, consider a bank account with an initial balance of $10,000 that earns 5% interest. The interest is computed at the end of each year on the current balance and then deposited back into the bank account. So in this example, after the first year, the account has earned $500 (5% of $10,000). The interest gets added to the bank account so the balance grows to $10,500. The next year, the interest is $525 (5% of $10,500) and so the balance grows to $11,025. Heres a partial table showing how the account grows:

Year Balance
0 $10,000.00
1 $10,500.00
2 $11,025.00
3 $11,576.25
4 $12,155.06
5 $12,762.82

Begin your program by asking the user to enter a starting balance. Note that the user should only enter numbers, and should not enter a dollar sign or any commas. Next, the user should enter an interest rate (in percentage form). After getting these two values, your program should print to the screen, the number of years it will take to double the initial investment.

The following is an example of what your MIGHT see on the screen when your program runs. The exact output depends on what values that the user types in while the program runs. The user's inputted values are shown below in italics:

Enter the starting balance: $ 10000 Enter the interest rate (in percentage): 5 The balance will be doubled in 15 years

Here is another example run:

Enter the starting balance: $ 25000 Enter the interest rate (in percentage): 10 The balance will be doubled in 8 years

Technical Notes & Requirements:

In your first prompt, if you will go ahead and print the dollar sign to the screen, the user will be less likely to try to type one when they enter the balance.

This program is similar to the sum example we did in class, except that this loop is not counter-controlled. This loop stops based on the sum (the account balance).

Your program must use a loop to compute the balance, and not some fancy math formula that would avoid the use of a loop.

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!