1 Replies - 22358 Views - Last Post: 08 September 2006 - 11:41 PM Rate Topic: -----

#1 Linda_1982  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 1
  • Joined: 08-September 06

How to code an Amortization Table

Posted 08 September 2006 - 06:24 PM

I have been assigned the task of creating an Amortization table using or adding to my last weeks program. I am at a serious loss as to how to get this done. I would like to know what is the simplest way to create an amortization table?

/*
	Week 3: 	Individual Assignment Mortgage Calculator part 2
	Programmer:	Michelle Carter
	Date:		August 30, 2006
	Filename:	PmtCalculation2c.java
	Purpose:	This external class will ask for, read and calculate the monthly mortgage payment based on user input.
			This program will then pass the calculated output to class MortgageCaclpt2.
*/

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

//Class Header
public class PmtCalculation2c
{
	//Public method header
	public PmtCalculation2c()
	{
	}

	//Get user input
	public double loanAmt() throws IOException
	{

		//Declare Method Variables
		double PrincipalIn = 0;
		String answer;
		boolean done = false;
		BufferedReader dataIn = new BufferedReader(new InputStreamReader(System.in));


		//Loop until done
					System.out.println();
			System.out.print("\t\t\tPlease Enter the Loan Amount:$");
			answer = dataIn.readLine();
			PrincipalIn = Double.parseDouble(answer);

		try
		{
			if(PrincipalIn <= 0) throw new NumberFormatException();

			else done = true;
		}

			catch(NumberFormatException nfe)
			{
				System.out.println("\t\t\tYou Have Entered An Invalid Response.");
				System.out.println();
			}

		return PrincipalIn;
	}

		//Get user input for interest rate
		public float loanRate() throws IOException
		{
			//Declare method variables
			float InterestIn = 0;
			String InterestAnswer;
			boolean done = false;
			BufferedReader dataIn = new BufferedReader(new InputStreamReader(System.in));
			DecimalFormat monetary = new DecimalFormat("#,###0.00");

			//loop until done

				System.out.println();
				System.out.print("\t\t\tPlease Enter Interest Rate %:");
				InterestAnswer = dataIn.readLine();
				InterestIn = Float.parseFloat(InterestAnswer);

				//System.out.println("\t\t\tThe Interest Rate of Your Loan Is %" + percentage.format(InterstIn));

				try
				{
					if(InterestIn <=0) throw new NumberFormatException();

					else done = true;
				}

				catch(NumberFormatException nfe)
				{
					System.out.println("\t\t\tYou Have Entered An Invalid Reponse.");
					System.out.println();
				}


			return InterestIn;
	}

	//get user input for Term
	public double loanTerm() throws IOException
	{
		//Declare mehtod Variables
		double TermIn = 0;
		String TermAnswer;
		boolean done = false;
System.out.println("Please Enter the Term of the Loan in Months:");
		BufferedReader dataIn = new BufferedReader(new InputStreamReader(System.in));

		//loop until done


				TermAnswer = dataIn.readLine();
				TermIn = Double.parseDouble(TermAnswer);
			try
			{
				if(TermIn <= 0) throw new NumberFormatException();
				else done = true;
			}
			catch(NumberFormatException nfe)
			{
				System.out.println("\t\t\tYou Have Entered An Invalid Response.");
				System.out.println();
			}

		return TermIn;
	}
		//Calculation of Monthly Mortgage Payment
		public double CalcAmt(float loanRate, double loanTerm, double loanAmt)
		{
			double NP, PV;
			float IR;
			NP = loanTerm/12;
			IR = loanRate/100/12;
			PV = loanAmt;

		//Calculation Formula for the Loan
		return (PV * IR) / (1 - Math.pow(1 + IR, - NP));
		}
	}




/*	Week 3: 	Individual Assignment Mortgage Calculator part 2
	Programmer:	Michelle Carter
	Date:		August 30, 2006
	Filename:	MortgageCalcpt2c.java
	Purpose:		This program will call an external class (PmtCalculation2) to calculate the monthly mortgage payment
			based on user input. The returned output will then be formatted and displayed to the user.
*/

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



public class MortgageCalcpt2c
{


	//Public method header
	public static void main(String[] args) throws IOException
	{


		//Displays Title of Program
		System.out.println("\t\tMortgage Monthly Payment Calculator");
		System.out.println();

		//Calls the external class PmtCalculation2
			PmtCalculation2c CalcAmt= new PmtCalculation2c();

		double loanTerm = CalcAmt.loanTerm();
		float loanRate = CalcAmt.loanRate();
		double loanAmt = CalcAmt.loanAmt();


		//Displays and formats the class output
		DecimalFormat monetary = new DecimalFormat("$#,###.00");

		System.out.println();
		System.out.println();
		System.out.println("\t\t\tThe Monthly Payment For Your Loan Amount Is:$"+monetary.format(CalcAmt.CalcAmt(loanRate,loanTerm,loanAmt)));
	}
}

Attached File(s)



Is This A Good Question/Topic? 0
  • +

Replies To: How to code an Amortization Table

#2 Jayman  Icon User is offline

  • Student of Life
  • member icon

Reputation: 418
  • View blog
  • Posts: 9,532
  • Joined: 26-December 05

Re: How to code an Amortization Table

Posted 08 September 2006 - 11:41 PM

You may want to use the search feature in the upper right corner. There have been a lot of posts on this very subject and I am certain you will find your answer. :)

As a suggestion use "Java Mortgage" as your search term.
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1