Computer Science Canada Mortgage program |
Author: | LOL123 [ Mon Mar 22, 2010 5:22 pm ] |
Post subject: | Mortgage program |
Hello I have to make a program that calculates when a presons mortgage will be paid off A homeowner takes a mortgage for $120 000 at 10 3/4% per year. At the end of each year an amount of $24 000 is paid. Write a program to show how the mortgage is paid off, year by year until the mortagage is paid off. Heres my code: Quote: import java.io.*; class mortgageproj { public static void main (String args []) throws java.io.IOException { BufferedReader br = new BufferedReader (new InputStreamReader (System.in)); int year = 2010; double mortgage = 120000; int yearPay = 24000; double intrest = 10.75; double payedOff = 0; double intMortgage = 0; double newMortgage = 0; System.out.println ("The Original Mortgage is $" + mortgage); System.out.println ("The rate of intrest is " + intrest); System.out.println ("The mortgage was started in " + year); // This selection checks if (mortgage >= (payedOff)) { System.out.println (" "); System.out.println (year++); intMortgage = mortgage + intrest; newMortgage = intMortgage - yearPay; System.out.print ("After this years payment the mortgage "); System.out.println ("is equal to $" + newMortgage); } else if (mortgage == (payedOff)) { System.out.println ("The mortgage is paid off!"); } } } When the program is run it doesnt go down to zero it only does the calculations once? would I need to use a loop to make it keep repeating? |
Author: | jbking [ Mon Mar 22, 2010 5:43 pm ] |
Post subject: | Re: Mortgage program |
LOL123 @ Mon Mar 22, 2010 3:22 pm wrote: When the program is run it doesnt go down to zero it only does the calculations once? would I need to use a loop to make it keep repeating?
Have you traced the program to notice that you aren't telling it to repeat any instructions and thus it doesn't repeat anything? Yes, a loop is a common way to make a program repeat, though not the only way as you could do recursive calls for another way to resolve the problem if you want a different approach. |
Author: | LOL123 [ Mon Mar 22, 2010 6:57 pm ] |
Post subject: | Re: Mortgage program |
So do while loop would work right? How should I set it up like this: while mortgage > 0 do all steps is that correct? |