/* Simulation of console-I/O program Interest3, using ConsoleApplet as a basis. See the file ConsoleApplet.java for more information. David Eck eck@hws.edu August 2, 1996 */ public class Interest3Console extends ConsoleApplet { public void init() { title = "Sample program \"Interest3\""; super.init(); } protected void program() { /* Program computes and prints the value of investment for each of the next five years. Initial value and interest rate are read as input from the user. */ double principal; // the value of the investment double rate; // the annual interest rate console.put("Enter the initial investment: "); principal = console.getlnDouble(); console.put("Enter the annual interest rate: "); rate = console.getlnDouble(); int years = 0; // counts the number of years tha have passed while (years < 5) { double interest = principal * rate; // compute this year's interest principal = principal + interest; // add it to principal years = years + 1; // count the current year. if (years > 1) { console.put("The value of the investment after "); console.put(years); console.put(" years is $"); } else { console.put("The value of the investment after 1 year is $"); } console.putln(principal); } // end of while loop } }