home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
BURKS 2
/
BURKS_AUG97.ISO
/
BURKS
/
LANGUAGE
/
JAVA
/
NOTES
/
SOURCE
/
intrest2.jav
< prev
next >
Wrap
Text File
|
1996-12-20
|
1KB
|
47 lines
/* Simulation of console-I/O program Interest2,
using ConsoleApplet as a basis. See the file
ConsoleApplet.java for more information.
David Eck
eck@hws.edu
August 2, 1996
*/
public class Interest2Console extends ConsoleApplet {
public void init() {
title = "Sample program \"Interest2\"";
super.init();
}
protected void program() {
/*
Program computes the amount of interest that is
earned on $17,000 invested at an interest
rate of 0.07 for 5 years. The value of
the investment at the end of each year
is printed to standard output.
*/
double principal = 17000; // the initial value of the investment
double rate = 0.07; // the annual interest rate
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.
console.put("The value of the investment after ");
console.put(years);
console.put(" years is $");
console.putln(principal);
} // end of while loop
}
}