Mortgage Calculation Program

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • ghostrider
    New Member
    • Jan 2007
    • 34

    #1

    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!



    Code:
     import java.math.*; 
    import java.text.DecimalFormat;
    import java.util.*;
     
    public class mortgage3Loanswk5
    {
    	public static void main(String[]args)
    	{
     
    	//Declare varibles//
    	double mortgage1, mortgage2, mortgage3, ammount;
    	ammount= 200000;//Principle loan//
    	double monthlyRate1, monthlyRate2, monthlyRate3;
    double[] iRate= {0.0575, 0.0550, 0.0535};//interest rates on 3 loans//
    	int[] term= {30, 15, 7};//number of years for loans//
    	double MP=(0);
    	int year= (0);
    	int month= (0);
    	int NewInterest1= (0);
    	int NewInterest2= (0);
    	int NewInterest3= (0);
    	int amount1= 200000;
    	int amount2= 200000;
    	int amount3= 200000;
    	double interest1= 0.0575;
    	double interest2= 0.055;
    	double interest3= 0.0535;
    	double []payment={(monthlyRate1), (monthlyRate2), (monthlyRate3)};
    	double []interest={(interest1), (interest2), (interest3)}; 
     
    	String hold="";
    	Scanner scan=new Scanner(System.in);
     
     
    	DecimalFormat decimalPlaces=new DecimalFormat("0.00");
    	//Formulas used within this program//
    	monthlyRate1=(ammount*((iRate[0]/12)/(1-Math.pow((1+(iRate[0]/12)),-(term[0]*12)))));
    	interest1= amount1*(interest1/12);
    	loanamount1=(interest1+amount1)-(monthlyRate1));
     
    	monthlyRate2=(ammount*((iRate[1]/12)/(1-Math.pow((1+(iRate[1]/12)),-(term[1]*12)))));
    	loanamount2=((interest2+amount2)-monthlyRate2);
    	interest2=(amount2*(interest2/12));
     
    	monthlyRate3=(ammount*((iRate[2]/12)/(1-Math.pow((1+(iRate[2]/12)),-(term[2]*12)))));
    	interest3=(amount3*(interest3/12));
    	loanamount3=((interest3+amount3)-monthlyRate3);
     
    	double []newmonthly={(loanamount1), (loanamount2), (loanamount3)};
     
    	//loop begins here// 
     
    	for(year=1; year<=term[0]; year++)
    	{
    	System.out.println();
    	System.out.println("Press\"Enter\"to continue.");
    	hold=scan.nextLine();
     
     
    	{
     
    	}
    		}	
     
    System.out.println("The interest of the loan is: "+iRate[0]*100+"%");	
    System.out.println("Monthly Payments for the 1st is:$" +decimalPlaces.format(monthlyRate1));
    System.out.println("The term of the loan is:"+term[0]+"years{"+term[0]*12+"months}");
    System.out.println("");
    System.out.println("The interest of the loan is: "+iRate[1]*100+"%");
    System.out.println("Monthly Payments for the 2nd loan is:$" +decimalPlaces.format(monthlyRate2));
    System.out.println("The term of the loan is:"+term[1]+"years{"+term[1]*12+"months}");
    System.out.println("");
    System.out.println("The interest of the loan is: "+iRate[2]*100+"%");
    System.out.println("Monthly Payments for the 3rd loan is:$" +decimalPlaces.format(monthlyRate2));
    System.out.println("The term of the loan is:"+term[2]+"years{"+term[2]*12+"months}");
    System.out.println("");
    }
     
     
     
    }//End program//
  • r035198x
    MVP
    • Sep 2006
    • 13225

    #2
    Originally posted by ghostrider
    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!



    Code:
     import java.math.*; 
    import java.text.DecimalFormat;
    import java.util.*;
     
    public class mortgage3Loanswk5
    {
    	public static void main(String[]args)
    	{
     
    	//Declare varibles//
    	double mortgage1, mortgage2, mortgage3, ammount;
    	ammount= 200000;//Principle loan//
    	double monthlyRate1, monthlyRate2, monthlyRate3;
    double[] iRate= {0.0575, 0.0550, 0.0535};//interest rates on 3 loans//
    	int[] term= {30, 15, 7};//number of years for loans//
    	double MP=(0);
    	int year= (0);
    	int month= (0);
    	int NewInterest1= (0);
    	int NewInterest2= (0);
    	int NewInterest3= (0);
    	int amount1= 200000;
    	int amount2= 200000;
    	int amount3= 200000;
    	double interest1= 0.0575;
    	double interest2= 0.055;
    	double interest3= 0.0535;
    	double []payment={(monthlyRate1), (monthlyRate2), (monthlyRate3)};
    	double []interest={(interest1), (interest2), (interest3)}; 
     
    	String hold="";
    	Scanner scan=new Scanner(System.in);
     
     
    	DecimalFormat decimalPlaces=new DecimalFormat("0.00");
    	//Formulas used within this program//
    	monthlyRate1=(ammount*((iRate[0]/12)/(1-Math.pow((1+(iRate[0]/12)),-(term[0]*12)))));
    	interest1= amount1*(interest1/12);
    	loanamount1=(interest1+amount1)-(monthlyRate1));
     
    	monthlyRate2=(ammount*((iRate[1]/12)/(1-Math.pow((1+(iRate[1]/12)),-(term[1]*12)))));
    	loanamount2=((interest2+amount2)-monthlyRate2);
    	interest2=(amount2*(interest2/12));
     
    	monthlyRate3=(ammount*((iRate[2]/12)/(1-Math.pow((1+(iRate[2]/12)),-(term[2]*12)))));
    	interest3=(amount3*(interest3/12));
    	loanamount3=((interest3+amount3)-monthlyRate3);
     
    	double []newmonthly={(loanamount1), (loanamount2), (loanamount3)};
     
    	//loop begins here// 
     
    	for(year=1; year<=term[0]; year++)
    	{
    	System.out.println();
    	System.out.println("Press\"Enter\"to continue.");
    	hold=scan.nextLine();
     
     
    	{
     
    	}
    		}	
     
    System.out.println("The interest of the loan is: "+iRate[0]*100+"%");	
    System.out.println("Monthly Payments for the 1st is:$" +decimalPlaces.format(monthlyRate1));
    System.out.println("The term of the loan is:"+term[0]+"years{"+term[0]*12+"months}");
    System.out.println("");
    System.out.println("The interest of the loan is: "+iRate[1]*100+"%");
    System.out.println("Monthly Payments for the 2nd loan is:$" +decimalPlaces.format(monthlyRate2));
    System.out.println("The term of the loan is:"+term[1]+"years{"+term[1]*12+"months}");
    System.out.println("");
    System.out.println("The interest of the loan is: "+iRate[2]*100+"%");
    System.out.println("Monthly Payments for the 3rd loan is:$" +decimalPlaces.format(monthlyRate2));
    System.out.println("The term of the loan is:"+term[2]+"years{"+term[2]*12+"months}");
    System.out.println("");
    }
     
     
     
    }//End program//
    Explain what you have done and what you now need help with.

    Comment

    • ghostrider
      New Member
      • Jan 2007
      • 34

      #3
      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.

      Comment

      • DeMan
        Top Contributor
        • Nov 2006
        • 1799

        #4
        Not necessatrily in good java (and I'm not sure whether answering the question but...).....
        Code:
        int month = 0;
        int originalTot = loanAmount;
        while(loanAmount < monthlyAmount)
        {
          loanAmount = loanAmount - monthlyAmount;
          month ++
        }
        System.out.println("The loan of " +originalTot + "was paid off in " + (month+1) + " months, with a final payment of " + loanAmount");

        Comment

        Working...