# How to code an Amortization Table

Page 1 of 1

## 1 Replies - 26008 Views - Last Post: 08 September 2006 - 11:41 PMRate Topic: //<![CDATA[ rating = new ipb.rating( 'topic_rate_', { url: 'https://www.dreamincode.net/forums/index.php?app=forums&module=ajax&section=topics&do=rateTopic&t=18448&amp;s=bc85a864f1d3bb4f3bf5a4acdda6c0ef&md5check=' + ipb.vars['secure_hash'], cur_rating: 0, rated: 0, allow_rate: 0, multi_rate: 1, show_rate_text: true } ); //]]>

### #1 Linda_1982

Reputation: 0
• 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.*;

public class PmtCalculation2c
{
public PmtCalculation2c()
{
}

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

//Declare Method Variables
double PrincipalIn = 0;
boolean done = false;

//Loop until done
System.out.println();

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;
boolean done = false;
DecimalFormat monetary = new DecimalFormat("#,###0.00");

//loop until done

System.out.println();

//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;
boolean done = false;
System.out.println("Please Enter the Term of the Loan in Months:");

//loop until done

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 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

• Student of Life

Reputation: 421
• 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.