468,765 Members | 946 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 468,765 developers. It's quick & easy.

Mortgage Calculation Program

I'm trying to get this program to calualte the totals of 3 different mortgages using arrays.I need the program to calculate the loans to the end of each term. Can someone point me in the right direction, before I lose my mind!



Expand|Select|Wrap|Line Numbers
  1.  import java.math.*; 
  2. import java.text.DecimalFormat;
  3. import java.util.*;
  4.  
  5. public class mortgage3Loanswk5
  6. {
  7.     public static void main(String[]args)
  8.     {
  9.  
  10.     //Declare varibles//
  11.     double mortgage1, mortgage2, mortgage3, ammount;
  12.     ammount= 200000;//Principle loan//
  13.     double monthlyRate1, monthlyRate2, monthlyRate3;
  14. double[] iRate= {0.0575, 0.0550, 0.0535};//interest rates on 3 loans//
  15.     int[] term= {30, 15, 7};//number of years for loans//
  16.     double MP=(0);
  17.     int year= (0);
  18.     int month= (0);
  19.     int NewInterest1= (0);
  20.     int NewInterest2= (0);
  21.     int NewInterest3= (0);
  22.     int amount1= 200000;
  23.     int amount2= 200000;
  24.     int amount3= 200000;
  25.     double interest1= 0.0575;
  26.     double interest2= 0.055;
  27.     double interest3= 0.0535;
  28.     double []payment={(monthlyRate1), (monthlyRate2), (monthlyRate3)};
  29.     double []interest={(interest1), (interest2), (interest3)}; 
  30.  
  31.     String hold="";
  32.     Scanner scan=new Scanner(System.in);
  33.  
  34.  
  35.     DecimalFormat decimalPlaces=new DecimalFormat("0.00");
  36.     //Formulas used within this program//
  37.     monthlyRate1=(ammount*((iRate[0]/12)/(1-Math.pow((1+(iRate[0]/12)),-(term[0]*12)))));
  38.     interest1= amount1*(interest1/12);
  39.     loanamount1=(interest1+amount1)-(monthlyRate1));
  40.  
  41.     monthlyRate2=(ammount*((iRate[1]/12)/(1-Math.pow((1+(iRate[1]/12)),-(term[1]*12)))));
  42.     loanamount2=((interest2+amount2)-monthlyRate2);
  43.     interest2=(amount2*(interest2/12));
  44.  
  45.     monthlyRate3=(ammount*((iRate[2]/12)/(1-Math.pow((1+(iRate[2]/12)),-(term[2]*12)))));
  46.     interest3=(amount3*(interest3/12));
  47.     loanamount3=((interest3+amount3)-monthlyRate3);
  48.  
  49.     double []newmonthly={(loanamount1), (loanamount2), (loanamount3)};
  50.  
  51.     //loop begins here// 
  52.  
  53.     for(year=1; year<=term[0]; year++)
  54.     {
  55.     System.out.println();
  56.     System.out.println("Press\"Enter\"to continue.");
  57.     hold=scan.nextLine();
  58.  
  59.  
  60.     {
  61.  
  62.     }
  63.         }    
  64.  
  65. System.out.println("The interest of the loan is: "+iRate[0]*100+"%");    
  66. System.out.println("Monthly Payments for the 1st is:$" +decimalPlaces.format(monthlyRate1));
  67. System.out.println("The term of the loan is:"+term[0]+"years{"+term[0]*12+"months}");
  68. System.out.println("");
  69. System.out.println("The interest of the loan is: "+iRate[1]*100+"%");
  70. System.out.println("Monthly Payments for the 2nd loan is:$" +decimalPlaces.format(monthlyRate2));
  71. System.out.println("The term of the loan is:"+term[1]+"years{"+term[1]*12+"months}");
  72. System.out.println("");
  73. System.out.println("The interest of the loan is: "+iRate[2]*100+"%");
  74. System.out.println("Monthly Payments for the 3rd loan is:$" +decimalPlaces.format(monthlyRate2));
  75. System.out.println("The term of the loan is:"+term[2]+"years{"+term[2]*12+"months}");
  76. System.out.println("");
  77. }
  78.  
  79.  
  80.  
  81. }//End program//
  82.  
Mar 1 '07 #1
3 2183
r035198x
13,262 8TB
I'm trying to get this program to calualte the totals of 3 different mortgages using arrays.I need the program to calculate the loans to the end of each term. Can someone point me in the right direction, before I lose my mind!



Expand|Select|Wrap|Line Numbers
  1.  import java.math.*; 
  2. import java.text.DecimalFormat;
  3. import java.util.*;
  4.  
  5. public class mortgage3Loanswk5
  6. {
  7.     public static void main(String[]args)
  8.     {
  9.  
  10.     //Declare varibles//
  11.     double mortgage1, mortgage2, mortgage3, ammount;
  12.     ammount= 200000;//Principle loan//
  13.     double monthlyRate1, monthlyRate2, monthlyRate3;
  14. double[] iRate= {0.0575, 0.0550, 0.0535};//interest rates on 3 loans//
  15.     int[] term= {30, 15, 7};//number of years for loans//
  16.     double MP=(0);
  17.     int year= (0);
  18.     int month= (0);
  19.     int NewInterest1= (0);
  20.     int NewInterest2= (0);
  21.     int NewInterest3= (0);
  22.     int amount1= 200000;
  23.     int amount2= 200000;
  24.     int amount3= 200000;
  25.     double interest1= 0.0575;
  26.     double interest2= 0.055;
  27.     double interest3= 0.0535;
  28.     double []payment={(monthlyRate1), (monthlyRate2), (monthlyRate3)};
  29.     double []interest={(interest1), (interest2), (interest3)}; 
  30.  
  31.     String hold="";
  32.     Scanner scan=new Scanner(System.in);
  33.  
  34.  
  35.     DecimalFormat decimalPlaces=new DecimalFormat("0.00");
  36.     //Formulas used within this program//
  37.     monthlyRate1=(ammount*((iRate[0]/12)/(1-Math.pow((1+(iRate[0]/12)),-(term[0]*12)))));
  38.     interest1= amount1*(interest1/12);
  39.     loanamount1=(interest1+amount1)-(monthlyRate1));
  40.  
  41.     monthlyRate2=(ammount*((iRate[1]/12)/(1-Math.pow((1+(iRate[1]/12)),-(term[1]*12)))));
  42.     loanamount2=((interest2+amount2)-monthlyRate2);
  43.     interest2=(amount2*(interest2/12));
  44.  
  45.     monthlyRate3=(ammount*((iRate[2]/12)/(1-Math.pow((1+(iRate[2]/12)),-(term[2]*12)))));
  46.     interest3=(amount3*(interest3/12));
  47.     loanamount3=((interest3+amount3)-monthlyRate3);
  48.  
  49.     double []newmonthly={(loanamount1), (loanamount2), (loanamount3)};
  50.  
  51.     //loop begins here// 
  52.  
  53.     for(year=1; year<=term[0]; year++)
  54.     {
  55.     System.out.println();
  56.     System.out.println("Press\"Enter\"to continue.");
  57.     hold=scan.nextLine();
  58.  
  59.  
  60.     {
  61.  
  62.     }
  63.         }    
  64.  
  65. System.out.println("The interest of the loan is: "+iRate[0]*100+"%");    
  66. System.out.println("Monthly Payments for the 1st is:$" +decimalPlaces.format(monthlyRate1));
  67. System.out.println("The term of the loan is:"+term[0]+"years{"+term[0]*12+"months}");
  68. System.out.println("");
  69. System.out.println("The interest of the loan is: "+iRate[1]*100+"%");
  70. System.out.println("Monthly Payments for the 2nd loan is:$" +decimalPlaces.format(monthlyRate2));
  71. System.out.println("The term of the loan is:"+term[1]+"years{"+term[1]*12+"months}");
  72. System.out.println("");
  73. System.out.println("The interest of the loan is: "+iRate[2]*100+"%");
  74. System.out.println("Monthly Payments for the 3rd loan is:$" +decimalPlaces.format(monthlyRate2));
  75. System.out.println("The term of the loan is:"+term[2]+"years{"+term[2]*12+"months}");
  76. System.out.println("");
  77. }
  78.  
  79.  
  80.  
  81. }//End program//
  82.  
Explain what you have done and what you now need help with.
Mar 1 '07 #2
Well what I have done is created a program that displays the monthly cost for 3 different loans. Using the same principle, but different interest rates and number of years. So now I'm trying to figure out how to make it calculate the mortgages through the life of each loan using the same arrays and a for loop. So basically I need all the loans to be zeroed out at the end of each loan term.
Mar 1 '07 #3
DeMan
1,806 1GB
Not necessatrily in good java (and I'm not sure whether answering the question but...).....
Expand|Select|Wrap|Line Numbers
  1. int month = 0;
  2. int originalTot = loanAmount;
  3. while(loanAmount < monthlyAmount)
  4. {
  5.   loanAmount = loanAmount - monthlyAmount;
  6.   month ++
  7. }
  8. System.out.println("The loan of " +originalTot + "was paid off in " + (month+1) + " months, with a final payment of " + loanAmount");
  9.  
Mar 1 '07 #4

Post your reply

Sign in to post your reply or Sign up for a free account.

Similar topics

4 posts views Thread by Michiel Alsters | last post: by
3 posts views Thread by cameron | last post: by
1 post views Thread by phjones | last post: by
1 post views Thread by phjones | last post: by
1 post views Thread by dylbin | last post: by
reply views Thread by zhoujie | last post: by
reply views Thread by Marin | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.