/* * CompoundingDemo.java * * Created on March 18, 2002, 11:04 PM */ /** * * @author mike * @version */ public class CompoundingDemo { /** Creates new CompoundingDemo */ public CompoundingDemo() { } public static final double INTRATE = 0.05; public static final double INITBAL = 5000; /** * @param args the command line arguments */ public static void main (String args[]) { double dailyInt; double monthlyInt; RevisedAccount testDaily = new RevisedAccount(); // could ask user for the initial amounts but just did the quick way for demo testDaily.setBal(INITBAL); testDaily.setIntRate(INTRATE); // also need to set interest rate – something new RevisedAccount testMonthly = new RevisedAccount(); testMonthly.setBal(INITBAL); testMonthly.setIntRate(INTRATE); // also need to set interest rate // how accurate do we want this? – lets do it approximately - assume 30 days every month // do 12 months for (int mon = 0; mon < 12; mon++) { // do 30 days within the month for (int day = 0; day < 30; day++) { dailyInt = testDaily.payInterest(1); System.out.println("Daily interest for day " + (day+1) + " is: " + dailyInt); } monthlyInt = testMonthly.payInterest(30); System.out.println("Monthly interest for month " + (mon+1) + " is: " + monthlyInt); System.out.println("type any letter to continue"); char junk = SavitchIn.readLineNonwhiteChar(); } System.out.println("final balance with daily compounding is: " + testDaily.getBal()); System.out.println("final balance with monthly compounding is: " + testMonthly.getBal()); } }