The Mortgage Calculator will calculate and displays the mortgage payment amount given the amount of the mortgage, the term of the mortgage, and the interest rate of the mortgage.
The user will be asked to enter to the amount of the mortgage loan, the term in years of the mortgage, and an annual interest rate. The amount of the mortgage loan shall be greater than 0 and not exceed 10,000,000 dollars. The minimum term for the loan is five years, with a maximum of 30 years. In addition to the user being able to supply the mortgage information the application will display three of the most commonly used mortgages and the user shall be able to select these mortgages instead of supplying the mortgage information. Once the user has provided the mortgage information, the program shall calculate the monthly mortgage payment and the amortization table for the life of the mortgage. For each month the amortization table shall display the loan period, loan balance, principal balance, interest balance, principal paid and interest paid.
Main Class that contains the main method and any supporting utility methods. The Main class will not process any mortgage or amortization table information
User input class that collects and validated user input
Class that only holds the user provided information
Mortgage information processing and formatting
Amortization table processing and formatting
Display class to present the output Program Title
Program Description
Input/Output Analysis
Class/Object Table
Class Method Pseudocode this is what iam have done so far looking for help how to finish it
/**
* A class that provides some primitive formating capabilities:
* allows strings to be left or right justified within some
* specified field width (fill character may also be specified).
* Author: Jake Foster
*/
public class Justify
{
/**
* Right justify a string, padding with spaces.
*
* @param s the string to justify
* @param width the field width to justify within
*
* @return the justified string.
*/
public static String right(String s, int width)
{
return right(s, width, ' ');
}
public static String right(String s, int width, char fillChar)
{
if (s.length() >= width)
return s;
StringBuffer sb = new StringBuffer(width);
for (int i = width - s.length(); --i >= 0; )
sb.append(fillChar);
sb.append(s);
return sb.toString();
}
}
/********************************************************************
Program Name: Mortgage Calcuator.AmortizationData
Programmers Name: Jake Foster
Program Description:
Data structure to hold amortization data for the Amortization table
Limitations: Data retrieval should be incorporated with
get properties and data validation should be incorporated.
********************************************************************/
public class AmoritizationData
{
public double loanBalance;
public double principalBalance;
public double interestBalance;
public double principalPaid;
public double interestPaid;
public int period;
public AmoritizationData(int period,
double loanBalance,
double principalBalance,
double interestBalance,
double principalPaid,
double interestPaid)
{
this.period = period;
this.loanBalance = loanBalance;
this.principalBalance = principalBalance;
this.interestBalance = interestBalance;
this.principalPaid = principalPaid;
this.interestPaid = interestPaid;
}
}
/********************************************************************
Program Name: Mortgage Calcuator.Mortgage Amortization Information
Programmers Name: Jake Foster
Program Description:
This class holds loan amortization information for an specific mortgage
loan, apr, term, and payment.
Limitations: Exception handling is not complete.
********************************************************************/
/************* import libraries ************************************/
import java.text.NumberFormat;
import java.util.Locale;
import javax.swing.*;
/*******************************************************************/
public class AmortizationTable
{
private static final int FLD_WIDTH = 11;
private AmoritizationData amoritizationTable[];
private MortgageInformation mortgageInfo;
public AmortizationTable(double principal, double term, double apr)
{
mortgageInfo = new MortgageInformation(principal, term, apr);
}
public AmortizationTable(MortgageInformation info)
{
this.mortgageInfo = info;
}
public void DisplayAmortizationTable()
{
JTextArea tableArea = new JTextArea(30, 50);
JScrollPane scrollpane;
String output = new String();
CalculateAmortizationTable();
//include the loan information as the header
output = mortgageInfo.HeaderString() + "\n\n";
//add the table
output += getAmortizationTable();
tableArea.setText(output);
scrollpane = new JScrollPane(tableArea,
ScrollPaneConstants.VERTICAL_SCROLLBAR_ALWAYS,
ScrollPaneConstants.HORIZONTAL_SCROLLBAR_ALWAYS);
JOptionPane.showMessageDialog(null,
scrollpane,
"Amortization Table",
JOptionPane.INFORMATION_MESSAGE);
}
private void CalculateAmortizationTable()
{
int numPayments = mortgageInfo.NumberPayments();
double intRate = mortgageInfo.MonthlyRate();
double principal = mortgageInfo.getPrincipal();
double payment = mortgageInfo.Payment();
double loanBalance;
double interestPaid;
double principalBalance;
double interestBalance;
double principalPaid;
double totalPaid;
double totalInterestPaid;
//calculate total paid on the loan over the entire term of the loan
totalPaid = numPayments * payment;
//calculate total interest paid over the entire term of the loan
totalInterestPaid = totalPaid - principal;
//make room for the initial entries
amoritizationTable = new AmoritizationData[numPayments + 1];
//order of arguments in constructor are:
//period, loanBalance, principalBalance, interestBalance, principal paid, interestPaid
amoritizationTable[0] = new AmoritizationData(0, totalPaid, principal, totalInterestPaid, 0, 0);
//intialized the Amortization Table to the initial loan values, so start counting at 1
for(int count = 1; count < amoritizationTable.length; count++)
{
//calculate loan balance from previous loan balance and mortgage payment
loanBalance = amoritizationTable[count-1].loanBalance - payment;
//interest payment is the product of the interest rate per period and the remaining balance
//remaining balance is the previous periods Principal Balance
interestPaid = intRate * amoritizationTable[count-1].principalBalance;
//calculate new principal balance from previous principle balance, payment, and interest paid
principalBalance = amoritizationTable[count-1].principalBalance - (payment - interestPaid);
//calculate interest balance using previous interest balance and new interest payment
interestBalance = amoritizationTable[count-1].interestBalance - interestPaid;
//Calculate principal paid using previous principle paid, payment, and interest paid
principalPaid = amoritizationTable[count-1].principalPaid + (payment - interestPaid);
//Calculate total interest paid, using the previous total interest paid and current interest paid
totalInterestPaid = amoritizationTable[count-1].interestPaid + interestPaid;
//generate new data entry in the amortization table
//period, loanBalance, principleBalance, interestBalance, principalPaid, interestPaid
amoritizationTable[count] = new AmoritizationData(count,
loanBalance,
principalBalance,
interestBalance,
principalPaid,
totalInterestPaid);
}
}
private String getAmortizationTable()
{
String output = new String();
NumberFormat mf = NumberFormat.getCurrencyInstance( Locale.US);
NumberFormat nf = NumberFormat.getNumberInstance();
nf.setMaximumFractionDigits(2);
output = "# \tLoan Balance\tPrin Balance\tInt Balance\tPrin Paid\tInt Paid\n" +
"---\t------------\t------------\t-----------\t-----------\t-----------\n";
for (int i = 0; i < amoritizationTable.length; i++)
{
output = output + amoritizationTable[i].period + "\t" +
Justify.right(mf.format(amoritizationTable[i].loanBalance), FLD_WIDTH) + "\t" +
Justify.right(mf.format(amoritizationTable[i].principalBalance), FLD_WIDTH) + "\t" +
Justify.right(mf.format(amoritizationTable[i].interestBalance), FLD_WIDTH) + "\t" +
Justify.right(mf.format(amoritizationTable[i].principalPaid), FLD_WIDTH) + "\t" +
Justify.right(mf.format(amoritizationTable[i].interestPaid), FLD_WIDTH) + "\n";
}
return output;
}
}