8 Replies - 31987 Views - Last Post: 30 June 2009 - 02:40 PM Rate Topic: -----

#1 MLoper1667  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 7
  • Joined: 18-July 06

Mortgage Payment Calculator

Posted 18 July 2006 - 08:47 AM

Write the program in Java (without a graphical user interface) and have it calculate the payment amount for 3 mortgage loans:

7 year at 5.35%
15 year at 5.5%
30 year at 5.75%
Use an array for the different loans. Display the mortgage payment amount for each loan and then list the loan balance and interest paid for each payment over the term of the loan. Use loops to prevent lists from scrolling off the screen.

This is my starting point and I now trying to get this program do execute these things as well and am totally lost has I have not programming experiance. Please someone help me?

/*
	Week 5 IA:	Mortgage Payment Calculator
	Programmer:	M. Loper
	Date:		July 17, 2006
	Filename:	WK5IA.java
	Purpose:	Calculate Mortgage Payments
*/
import java.io.*;
import java.text.*;

public class WK5IA
{

	public static void main(String[] args)throws IOException
	{
		DecimalFormat twoplaces = new DecimalFormat("#,###.00");
		InputStreamReader reader = new InputStreamReader(System.in);
		BufferedReader object = new BufferedReader(reader);

			double loan = 200000.00; //Array
			int[] length = new int[3];
						length[0]=7;
						length[1]=15;
						length[2]=30;


			double [] interest = new double [3];
						interest[0] = .0535;
						interest[1] = .0550;
						interest[2] = .0575;
			int x = 0;

			do //Do Statement
			{
				double payment = (loan*(interest[x]/12))/(1-(Math.pow(1/(1+(interest[x]/12)),(length[x]*12)))); //Display Math

				System.out.println("\n\nYour Mortgage Payment " + twoplaces.format(payment) + "\n\nfor the " + length[x] + " Year Contract "); //Display Text to explane values

				x++;
			}

			while (x <3);

	}
}



Is This A Good Question/Topic? 0
  • +

Replies To: Mortgage Payment Calculator

#2 Amadeus  Icon User is offline

  • g+ + -o drink whiskey.cpp
  • member icon

Reputation: 250
  • View blog
  • Posts: 13,507
  • Joined: 12-July 02

Re: Mortgage Payment Calculator

Posted 18 July 2006 - 10:50 AM

Can you let us know what you've tried to implement? Are you familiar with the math calculations for mortgages?
Was This Post Helpful? 0
  • +
  • -

#3 MLoper1667  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 7
  • Joined: 18-July 06

Re: Mortgage Payment Calculator

Posted 18 July 2006 - 10:54 AM

View PostAmadeus, on 18 Jul, 2006 - 09:42 AM, said:

Can you let us know what you've tried to implement? Are you familiar with the math calculations for mortgages?


I am familar in that I understand the readings on what things mean like arrays, objects, inheritance, polymorphism, etc. As far as getting them in my code so they work I have no clue.
Was This Post Helpful? 0
  • +
  • -

#4 MLoper1667  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 7
  • Joined: 18-July 06

Re: Mortgage Payment Calculator

Posted 18 July 2006 - 12:17 PM

I have some code I have been working on but am having trouble getting it to compile. I will attach it so you guys can look at it and tell me what I am doing wrong.
Was This Post Helpful? 0
  • +
  • -

#5 MLoper1667  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 7
  • Joined: 18-July 06

Re: Mortgage Payment Calculator

Posted 18 July 2006 - 12:19 PM

View PostMLoper1667, on 18 Jul, 2006 - 11:09 AM, said:

I have some code I have been working on but am having trouble getting it to compile. I will attach it so you guys can look at it and tell me what I am doing wrong.


/*
	Week 5 IA:	Mortgage Payment Calculator
	Programmer:	M. Loper
	Date:		July 17, 2006
	Filename:	WK5IA2.java
	Purpose:	Calculate Mortgage Payments
*/

import java.io.*;
import java.text.*;
import java.lang.*;

public class WK5IA2

{
	int i;
	int intSelection;
	int intSelected;
	int[] intTerms = { 7*12, 15*12, 30*12 };
	double[] dblRates = { 0.0535, 0.055, 0.0575 };
	int intOption[] = {1, 2, 3};
	double dblLoanAmt = 200000;
	BufferedReader keyboardInput;

	public WK5IA2()
	{
		DecimalFormat decimalLoan = new DecimalFormat("#,000.00");
		DecimalFormat decimalPayment = new DecimalFormat("0.00");

		System.out.println("\nMortgage Payment Calculator - "+intTerms.length+" LOAN OPTIONS\n\n");
		System.out.print(" Loan Amount = $" +decimalLoan.format(dblLoanAmt) +"\n\n");
		System.out.println("#########################################################\n");

		for (int i=0; i<intTerms.length; i++)
		{
			double dblIntRates = dblRates[i];
			int intLoanLgth = intTerms[i];
			double dblDiscount = (Math.pow((1 + dblIntRates /12), intLoanLgth) -1) / (dblIntRates /12 * Math.pow((1 + dblIntRates /12), intLoanLgth));
			double dblPayment = dblLoanAmt / dblDiscount;
			System.out.println (" Option number " +intOption[i]+ ") $" +decimalPayment.format(dblPayment) + " at " +decimalPayment.format(dblRates[i]*100) +"%" + " for " +(intTerms [i] /12) +" Years\n");
			System.out.println("---------------------------------------------------------\n");
		}

		try
		{
			System.out.print("Press enter to continue\n\n");
			System.in.read();
			}catch (Exception e) {}
		}

		public void getOption()
		{
			BufferedReader keyboardInput = new BufferedReader(new InputStreamReader(System.in));System.out.println("For payment schedule -- make a selection from below \n" + "\n0) Quit \n\n1) 7 Year loan \n\n2) 15 Year loan \n\n3) 30 Year loan " );
			System.out.print("\nMake Selection: ");

			try
			{
				intSelected = Integer.parseInt(keyboardInput.readLine());
				}catch (Exception e) {}
			}

			public void select()
			{
				boolean continueRunning = true;
				while(continueRunning)
				{
					getOption();
					switch (intSelected)
					{
						case 0: continueRunning = false; System.exit(0);
						case 1: MortgageOpt1.mortgageOpt1(); System.exit(0);
						case 2: MortgageOpt2.mortgageOpt2(); System.exit(0);
						case 3: MortgageOpt3.mortgageOpt3(); System.exit(0);

						default: System.out.println("Unrecognized option. Try again.");
					}
				}
			}

			public static void main(String[] args)
			{
				WK5IA2 = new WK5IA2();
				mortg.getOption();
				mortg.select();
			}

		}

		public class WK5IA2
		{
			public static double WK5IA2 ()
			{
				double mortgageOpt1 = 0.0;
				double interest,payment;
				double balance = 0.0;
				double monthlyInt =0.0;
				double principal = 0.0;
				double loan;
				int term;

				loan=200000;
				interest=.0535;
				term=7;
				monthlyInt=(loan *(interest/12));
				payment=(loan *((interest/12)/(1-Math.pow((1+(interest/12)),-(term*12)))));
				principal =(payment - monthlyInt);
				balance = (loan - principal);

				DecimalFormat decimalPlaces = new DecimalFormat("0,000.00");
				DecimalFormat decimalMonthly = new DecimalFormat("0.00");

				System.out.println("============================================");
				System.out.println();
				System.out.println("\t\t\tMortgage Calculator");
				System.out.println();
				System.out.print("\nSUMMARY OF INITIAL TERMS");
				System.out.print("\n\nAmount financed: $"+decimalPlaces.format(loan));
				System.out.print("\n\nInterest rate: "+interest*100 +"%");
				System.out.println("\n\nNumber of years: "+term);
				System.out.println("\nNumber of months: "+ term*12);
				System.out.print("\nMonthly Payment: $"+decimalPlaces.format(payment));
				System.out.println();
				System.out.println("=============================");

				try
				{
					System.out.print("Press enter to continue\n");
					System.in.read();
					} catch (Exception e) {}

					int y = 1;
					int x = 0;
					int i;
					for (i=84;i>=0;--i)
					{
						monthlyInt=(loan *(interest/12));
						principal =(payment - monthlyInt);
						loan = loan - principal;

						System.out.println("Payment #" +y);
						System.out.print("Interest: $" + decimalMonthly.format(monthlyInt)+ "\nPrincipal: $"+ decimalMonthly.format(principal));
						System.out.println();
						System.out.print("New Balance: $");
						System.out.print(decimalPlaces.format(loan));
						System.out.println();
						System.out.println();

						++y;

						++x;
						if (x >= 6)
						{
							try
							{
								System.out.print("Press enter to continue\n");
								System.in.read();
								} catch (Exception e) {}

								x = 0;
							}
						}

						return WK5IA2;
					}
				}

Was This Post Helpful? 0
  • +
  • -

#6 MLoper1667  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 7
  • Joined: 18-July 06

Re: Mortgage Payment Calculator

Posted 19 July 2006 - 10:39 AM

Ok I finally got it down to one error can anyone help me to get this to compile.
import java.io.*;
import java.text.*;
import java.text.DecimalFormat;

public class WK5IA
{
public static void main(String[] args) throws IOException
{

// declare variables
int loanAmt = 200000; // principal loan amount
int[] loanTerm = {84, 180 ,360}; // loan term for 7 years, 15 years, and 30 years
int loanYears; // indicates the loan term in years
double[] intRate = {5.35, 5.50, 5.75}; // interest rates for 7 years, 15 years, and 30 years
double newIntRate; // displays interest rate calculation
double monthlyPay = 0; // displays monthly payment calculation
DecimalFormat money = new DecimalFormat("$#,###.00"); // displays mortgage in decimal format
DecimalFormat money2 = new DecimalFormat("0.00%"); //displays interest rate in decimal format
DecimalFormat money = new DecimalFormat("#,###.00");
InputStreamReader reader = new InputStreamReader(System.in);
BufferedReader object = new BufferedReader(reader);
double loan = 200000.00; //Array
int[] length = new int[3];
length[0]=7;
length[1]=15;
length[2]=30;


double [] interest = new double [3];
interest[0] = .0535;
interest[1] = .0550;
interest[2] = .0575;
int x = 0;

do //Do Statement
{
double payment = (loan*(interest[x]/12))/(1-(Math.pow(1/(1+(interest[x]/12)),(length[x]*12)))); //Display Math

System.out.println("\n\nYour Mortgage Payment " + twoplaces.format(payment) + "\n\nfor the " + length[x] + " Year Contract "); //Display Text to explane values

x++;

// displays messages to indicate purpose of program and conditions in the console window
System.out.println();
System.out.println("Mortgage Payment Calculator");
System.out.println();
System.out.println("Calculate three separate mortgage payments for a $" + loanAmt);
System.out.println("Length of Contract and Interest Rate: (1) 7 years @ 5.35%");
System.out.println("\t\t\t\t\t (2) 15 years @ 5.50%");
System.out.println("\t\t\t\t\t (3) 30 years @ 5.75%");
System.out.println();
System.out.println("The results:");

int i;
for (i = 0; i <= 2; i++)
{
loanTerm[i] = loanTerm[i] / 12;
intRate[i] = (intRate[i] * .01);
monthlyPay = loanAmt * intRate[i] / (1 - Math.pow(1 + intRate[i], - loanTerm[i]));

// displays results
System.out.println();
System.out.println("Mortgage Payment For $" + loanAmt + " Length of Contract " + loanTerm[i] + " years at");
System.out.println("a " + (money2.format(intRate[i]) + " Interest Rate = " + (money.format(monthlyPay))));

}

while (x <3);

}
}
}
Was This Post Helpful? 0
  • +
  • -

#7 wisco  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 1
  • Joined: 16-August 06

Re: Mortgage Payment Calculator

Posted 16 August 2006 - 09:45 AM

My program calculates first loan but then it doesn't proceed to display the subsequent payments the second loan and then to the third. It gives the payment and all the subsequent payments for the first, but then just gives the payment for the 2nd and third mortgages. My program also doesnt display the interest rates for the 2nd and third mortgages. Any help would be greatly appreciated. Thanks

package wk5arrays;
import java.text.DecimalFormat;
public class wk5arrays {
public static void main(String args[]) throws Exception
{
// declare and construct variables
int loanAmt = 200000; // principal loan amount
int[] loanTerm = {84, 180 ,360}; // loan term for 7 years, 15 years, and 30 years
double[] intRate = {5.35, 5.50, 5.75}; // interest rates for 7 years, 15 years, and 30 years
int monthNum = 85;
int monthNum2 = 181;
int monthNum3 = 361;
int loanNum = 0;
int line = 0;
double monthlyPay = 0; // displays monthly payment calculation
double newLoanBal = 200000; // loan balance
double monIntPaid = 0; // interest paid
double newIntRate = 0; // monthly interest rate
double monPrinPay; // monthly principal payment
DecimalFormat money = new DecimalFormat("$0.00"); // displays mortgage in decimal format
DecimalFormat interest = new DecimalFormat("0.00%");// displays interest rate in decimal format

// displays messages to indicate purpose of program and conditions in the console window
System.out.println();
System.out.println("Welcome to Eric's Mortgage Payment Calculator");
System.out.println();
System.out.println("This program will calculate three separate mortgage payments for a $" + loanAmt);
System.out.println("with the following loan terms and interest rates:");
System.out.println("7 years at 5.35%");
System.out.println("15 years at 5.50%");
System.out.println("30 years at 5.75%");
System.out.println();
System.out.println("Following the calculation of the payments, the program will display the");
System.out.println("mortgage payments, interest paid, and loan balance for the terms of the");
System.out.println("of the three different loans.");
System.out.println();
System.out.println("The results are as follows:");

int i;
for (i = 0; i <= 2; i++)
{
int j;
for (j = 0; j <= 2; j++)
{

// performs calculations for loan term, interest rate, and monthly payment
loanTerm[i] = loanTerm[i];
intRate[i] = (intRate[i] * .01) / 12;
monthlyPay = loanAmt * intRate[i] / (1 - Math.pow(1 + intRate[i], - loanTerm[i]));

if (loanNum <= 2)
{
loanNum++;

// displays results for each loan in the console window
System.out.println();
System.out.println("Loan " + loanNum);
System.out.println("**************************************************************************");
System.out.println();
System.out.println("The monthly mortgage payment for a $" + loanAmt + " over a " + loanTerm[i]/12 + "-year period at a " + (interest.format(intRate[i] * 12)));
System.out.println("interest rate = " + (money.format(monthlyPay)));
System.out.println();

System.out.println("The mortgage payment, interest paid, and loan balance for the loan is as");
System.out.println("follows:");
System.out.println();

}

// Begins loop
while(newLoanBal > 0)
{

if (i >= 0)

monIntPaid = intRate[i] * newLoanBal;
monPrinPay = monthlyPay - monIntPaid;
newLoanBal = newLoanBal - monthlyPay + monIntPaid;

// displays results of calculations for monthly interest paid, monthly principal paid, and new loan balance
System.out.println((money.format(monthlyPay)) + "\t" + (money.format(monIntPaid)) + "\t\t" + (money.format(newLoanBal)) + "\tPayment(s) completed.");

// decrements monthly count one month at a time until count reaches zero
monthNum--;


// to pause console window, then continue calculations
if (line == 20)
{
line = 0;
try
{
Thread.sleep(2000);
}
catch (InterruptedException e)
{
}

}
}
}
}
}
}
Was This Post Helpful? 0
  • +
  • -

#8 MLoper1667  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 7
  • Joined: 18-July 06

Re: Mortgage Payment Calculator

Posted 16 August 2006 - 10:48 AM

Do you have windows live messenger? If so my name is [email protected], and will be more than happy to help you through IM's.
Was This Post Helpful? 0
  • +
  • -

#9 yogiprogrammer  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 1
  • Joined: 30-June 09

Re: Mortgage Payment Calculator

Posted 30 June 2009 - 02:40 PM

View PostMLoper1667, on 18 Jul, 2006 - 07:47 AM, said:

Write the program in Java (without a graphical user interface) and have it calculate the payment amount for 3 mortgage loans:

7 year at 5.35%
15 year at 5.5%
30 year at 5.75%
Use an array for the different loans. Display the mortgage payment amount for each loan and then list the loan balance and interest paid for each payment over the term of the loan. Use loops to prevent lists from scrolling off the screen.

This is my starting point and I now trying to get this program do execute these things as well and am totally lost has I have not programming experiance. Please someone help me?

/*
	Week 5 IA:	Mortgage Payment Calculator
	Programmer:	M. Loper
	Date:		July 17, 2006
	Filename:	WK5IA.java
	Purpose:	Calculate Mortgage Payments
*/
import java.io.*;
import java.text.*;

public class WK5IA
{

	public static void main(String[] args)throws IOException
	{
		DecimalFormat twoplaces = new DecimalFormat("#,###.00");
		InputStreamReader reader = new InputStreamReader(System.in);
		BufferedReader object = new BufferedReader(reader);

			double loan = 200000.00; //Array
			int[] length = new int[3];
						length[0]=7;
						length[1]=15;
						length[2]=30;


			double [] interest = new double [3];
						interest[0] = .0535;
						interest[1] = .0550;
						interest[2] = .0575;
			int x = 0;

			do //Do Statement
			{
				double payment = (loan*(interest[x]/12))/(1-(Math.pow(1/(1+(interest[x]/12)),(length[x]*12)))); //Display Math

				System.out.println("\n\nYour Mortgage Payment " + twoplaces.format(payment) + "\n\nfor the " + length[x] + " Year Contract "); //Display Text to explane values

				x++;
			}

			while (x <3);

	}
}


Was This Post Helpful? 0
  • +
  • -

Page 1 of 1