Here is the interest program Interest.java we looked at in the class.
public class Interest { /* This program computes the value of an investment of $1000.0 invested at an interest rate of 0.02 for one year. */ public static void main(String[] args) { /* Declare the variables. */ double principal; // The value of the investment. double rate; // The annual interest rate. double interest; // Interest earned in one year. /* Do the computations. */ principal = 1000.0; rate = 0.02; interest = principal * rate; // Compute the interest. principal = principal + interest; // Compute value of investment after one year, with interest. // (Note: The new value replaces the old value of principal.) /* Output the results. */ System.out.print("The interest earned is $"); System.out.println(interest); System.out.print("The value of the investment after one year is $"); System.out.println(principal); } // end of main() } // end of class Interest
Add to this program so that it first asks the user
to enter the principal and the interest rate.
Then your program should compute and print out
the investment after the first and second years.