Integrating the Amortization Table (DOC)
Shared by: fanzhongqing
-
Stats
- views:
- 0
- posted:
- 5/16/2012
- language:
- English
- pages:
- 16
Document Sample


Mortgage Calculator
1. FUNCTIONAL MODEL
1.1. ACTIVITY DIAGRAM
1.2. USE CASE DESCRIPTION
Use Case Name: Find Mortgage Payment ID: 1 Importance Level: High
Primary Actor: Mortgage Broker Use Case Type: Detail, essential
Stakeholders and Interests:
Mortgage Broker
Loan Officer
Chief Financial Officer
Brief Description:
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.
Trigger: Mortgage Broker Enters information
Type: External
Relationships:
Association: None
Include: None.
Extend: None.
Generalization: None.
Normal Flow of Events:
1. Mortgage Broker enters principal loan value, annual interest rate, and term in years.
2. Mortgage Payment is calculated
3. Mortgage Payment is displayed
4. Amortization Table is calculated
5. Amortization Table is displayed
SubFlows:
None.
Alternate/Exceptional Flows:
1. Mortgage Broker selects a predefined mortgage.
2. Mortgage Payment is calculated
3. Mortgage Payment is displayed
4. Amortization Table is calculated
5. Amortization Table is displayed
1. Mortgage broker enters invalid mortgage information
2. Error message is displayed
3. Invalid information is cleared.
1. Mortgage broker enters illegal mortgage information
2. Error message is displayed
3. Invalid information is cleared.
2. STRUCTURAL MODEL
2.1. CRC CARDS
2.1.1. MORTGAGE INFORMATION INPUT
Front:
Class Name: ID: 1 Type:
MortgageInformationInput Concrete, Domain
Description: Associated Use Cases:
Controlling class for the application, provides user Find Mortgage Payment
interface, input validation, and creates all other class
objects
Responsibilities Collaborators
Retrieves and sets predefined mortgage Amortization Table
Information Mortgage Data
Validate user input
Create Mortgage Data objects
Create Amortization Table objects
Display Mortgage Payment
Display Amortization Table
Back:
Attributes:
None
Relationships:
Generalization (a-kind-of):
Aggregation (has-parts):
Other Associations: MortgageData {0..1}, AmoritizationTable {0..1}
2.1.2. MORTGAGE DATA
Front:
Class Name: ID: 2 Type:
MortgageData Concrete, Domain
Description: Associated Use Cases:
Holds information for one mortgage Find Mortgage Payment
Responsibilities Collaborators
Calculate mortgage payment MortgageInformationInput
Format mortgage data AmortizationTable
Back:
Attributes:
Principal {1..1} (double) {0 < Principal < max principal}
Apr {1..1} (double) {0 <= Apr <= 100}
Term {1..1} (integer) {min term <= Term <= max term}
DataString {1..1} (string) {Term + “ years “ + Apr + “@ %”}
FullDataString {1..} (string) {$ + Principal + “, + Term + “ years “ + Apr + “@%”}
Relationships:
Generalization (a-kind-of):
Aggregation (has-parts):
Other Associations: MortgageInformationInput {1..1}, AmoritizationTable {0..1}
2.1.3. AMORTIZATION TABLE
Front:
Class Name: ID: 3 Type:
AmortizationTable Concrete, Domain
Description: Associated Use Cases:
Constructs the Amortization table and formats for Find Mortgage Payment
output
Responsibilities Collaborators
Calculate amortization table MortgageInformationInput
Get Amortization Table MortgageData
AmoritizationData
Back:
Attributes:
amortizationTable {0..1} (array of amortization data)
mortgageInformation {1..1} (MortgageData)
Relationships:
Generalization (a-kind-of):
Aggregation (has-parts): AmortizationData {0..*}
Other Associations: MortgageInformationInput {1..1}, MortgageData {0..1},
2.1.4. AMORTIZATION DATA
Front:
Class Name: ID: 4 Type:
AmortizationData Concrete, Domain
Description: Associated Use Cases:
Holds data for one row of the Amortization Table and Find Mortgage Payment
formats the fields for output
Responsibilities Collaborators
MortgageInformationInput
MortgageData
AmoritizationTable
Back:
Attributes:
Period {1..1} (integer} {0 <= period <= term * 12}
LoanBalance {1..1} (double} {0 <= LoanBalance <= Principal}
PrincipalBalance {1..1} (double} {0 <= PrincipalBalance <= Principal}
InterestBalance {1..1} (double) {0 <= InterestBalance <= Principal}
PrincipalPaid {1..1} (double) {0 <= PrinciplePaid <= Principal}
InterestPaid {1..1} (double) {0 <= InterestPaid <= Principal}
LoanBalance_Formatted {1..1} (string) { Currency (LoanBalance)}
PrincipalBalance_Formatted {1..1} (string) { Currency (PrincipalBalance)}
InterestBalance _Formatted {1..1} (string) { Currency (InterestBalance)}
PrincipalPaid _Formatted {1..1} (string) { Currency (PrincipalPaid)}
InterestPaid_Formatted {1..1} (string) { Currency (InterestPaid)}
Relationships:
Generalization (a-kind-of):
Aggregation (has-parts):
Other Associations: AmortizationTable {1..1}
2.2. CLASS DIAGRAM
MortgageInformationInput
+create()
-findMortgagePayment() : void
-setDefaultMortgageInformation() : void
-validatePrincipalAmount() : bool
-validateInterestRate() : bool
-validateTerm() : bool
1 -displayMortgagePayment() 1
-displayAmoritizationTable()
0..1 -creates
-creates 0..1
MortgageData
AmortizationTable +Id : int
+Principle : double
-amortizationTable : AmortizationData -uses
+APR : double
-mortgageInformation : MortgageData
+Term : int
+create() +Payment : double
+getAmorizationTable() 0..1 1
+dataString : string
-calculateAmortizationTable() +fullDataString : string
+create()
1 +setId()
+getID() : int
+setPrincipal()
+getPrincipal() : double
+setTerm()
0..* -tableRow +getTerm() : int
+setApr()
+getApr() : double
AmortizationData
+getPayment() : double
+loanBalance : double -calculateMortgagePayment()
+principalBalance : double
+interestBalance : double
+principalPaid : double
+interestPaid : double
+period : int
+create()
+getPeriod() : int
+getLoanBalance() : double
+getPrincipalBalance() : double
+getInterestBalance() : double
+getPrincipalPaid() : double
+getInterestPaid() : double
+getLoanBalance_Formatted() : string
+getPrincipalBalance_Formatted() : string
+getInterestBalance_Formatted() : string
+getInterestPaid_Formatted() : string
2.3. SEQUENCE DIAGRAM
mortgageInput
findMortgagePayment() create
mortgageData
validatePrincipalAmount()
[validPrincipal]: setPrincipal
validateInterestRate
[validAPR]: setApr
validateTerm
[validTerm]: setTerm
[validInput]: getPayment
payment calculateMortgagePayment
displayMortgagePayment()
[validInput]: create(mortgageData)
amortizationTable
getAmorizationTable
calculateAmortizationTable
[for each row in table]: create()
amortizationData
tableRow
amoritizationTable
displayAmoritizationTable
3. DESIGN
3.1. METHOD CONTRACTS
3.1.1. MORTGAGE DATA CONSTRUCTOR
Method Name: constructor Class Name: MortgageData ID: 2.1
Clients (Consumers):
MortgageInformationInput
Associated Use Cases:
Find Mortgage Payment
Description of Responsibilities:
Class calculates each row of the amortization table and formats the table for output.
Arguments Received:
id (integer)
principal (double)
apr (double)
term (integer)
Type of Value Returned: None
Pre-Conditions:
1. Loan minimum must be defined
2. Loan maximum must be defined
3. APR minimum must be defined
4. APR maximum must be defined
5. Term Minimum must be defined
6. Term Maximum must be defined
Post-Conditions:
1. ID is set to an integer value
2. Principal is set to a valid value
3. APR is set to a valid value
4. Term is set to valid value
3.1.2. GET AMORTIZATION TABLE
Method Name: Class Name: ID: 3.1
getAmoritizationTable AmortizationTable
Clients (Consumers):
MortgageInformationInput
Associated Use Cases:
Find Mortgage Payment
Description of Responsibilities:
Class calculates each row of the amortization table and formats the table for output.
Arguments Received: None
Type of Value Returned: string
Pre-Conditions:
1. All fields of the mortgage data (principal, apr, term) need to be set and within the
valid limits.
Post-Conditions:
1. Formatted amortization table is constructed or
2. Empty table is constructed
3.2. METHOD DESIGN
3.2.1. FIND MORTGAGE PAYMENT
Method Name: Class Name: ID:
findMortgagePayment MortgageInformationInput 1.1
Contract ID: 1.1 Programmer: Tevis Boulware Date Due:
Programming Language:
X Visual Basic Smalltalk C++ Java
Triggers/Events:
Invoked by btnCalculate_Click event
Arguments Received:
Data Type: Notes:
None MortgageData object is created inside this method, and thus local to
the method.
Messages Sent & Arguments Passed:
ClassName.MethodName: Data Type: Notes:
MortgageData.Principal (mortgageAmount) Value parsed from text to
numeric prior to passing
MortgageData.APR(APR) Value parsed from text to
numeric prior to passing
MortgageData.Term(term) Value parsed from text to
numeric prior to passing
This.displayPayment(MortgageData.payment) Class method
This.displayAmortizationTable(MortgageData) Class method
InputUtilities.ShowErrorMessage(prompt, title) Shared utility method
Argument Returned:
Data Type: Notes:
Algorithm Specification:
If valid Principal Amount then
Parse Principal input
Else
Clear principal input field
End if
If valid Interest rate then
Parse APR input
Else
Clear APR input field
End if
If valid term then
Parse term input
Else
Clear Term input field
End if
If valid Principal AND valid APR AND valid Term then
Create MortgageData object
Call displayPayment
Call displayAmoritizationTable
Else
Clear payment filed
If not Valid Principal then
Send Principal error message
Set focus to Principle input field
End if
If not Valid Apr then
Send APR error message
Set focus to APR input field
End if
If not Valid Term then
Send Term error message
Set focus to Term input field
End if
End if
Misc notes:
There are class methods that validate each of the input fields.
4. CONSTRUCTION
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<script LANGUAGE="JavaScript">
<!--Hide JavaScript from Java-Impaired Browsers
var irate, mi, cmi, years, tprinc, princ, paym, cpaym, osp,v,downp,downr,comp;
function calcPaym(cdn){
tprinc = round2d(parseFloat(document.smpc.tprinc.value));
downp = .01*parseFloat(document.smpc.downp.value);
downr = ceil2d(downp*tprinc);
princ = tprinc-downr;
document.smpc.princ.value = fmt2d(princ,0);
document.smpc.downr.value = fmt2d(downr,0);
if(cdn)comp="Canadian"; else comp="U.S";
document.smpc.comp.value = comp;
irate = .01*parseFloat(document.smpc.percent.value);
years=parseFloat(document.smpc.years.value);
term = parseFloat(document.smpc.term.value);
if(term > years)term=years;
if (term==0 || years==0||irate<.0001||princ<1)
{alert("values must be numeric");}
else
{
if(cdn)mi = Math.pow(1+ irate/2,1/6)
else mi = 1+(irate/12);
v = 1/mi;
paym = ceil2d(princ*(mi-1)/(1-Math.pow(mi,-(years*12))));
osp = (princ-(v*paym*(1-Math.pow(v,12*term)))/(1-v))/Math.pow(v,12*term);
if(osp<0)osp = 0;
document.smpc.paym.value=fmt2d(paym,0);
document.smpc.owed.value = fmt2d(osp,0);
}
}
function round2d(n){return(.01* Math.round(100*n));}
function floor2d(n){return(.01* Math.floor(100*n));}
function ceil2d(n){return(.01* Math.ceil(100*n));}
// format number n as string width w with 2 decimal places
function fmt2d(n,w)
{
var work,dp,sl,dl;
work = ""+floor2d(n); // force only 2 decimals
sl=work.length;
if(-1 == (dp = work.indexOf(".")))work=work+".00";
else if(3 > sl-dp)work = work+".00".substring(sl-dp,3);
sl = work.length;
if(0 != w && w !=sl)
if(w<sl){work = "*";for(sl=1;sl<w;sl++)work=work+"*";}
else for(;sl<w;sl++)work=" "+work;
return work;
}
//-->
</script>
<title>Mortgage Payment Calculator - Online Version</title>
<style type="text/css">
<!--
.style1 {color: #FF0000}
-->
</style>
</head>
<body BGCOLOR="#FFFFFF" TEXT="#000000" ONLOAD="calcPaym(1)">
<h1 class="style1">Mortgage Payment Calculator </h1>
<p><em>The mortgage calculator will allow you to calculate the monthly mortgage
payments for various types of mortgages.</em></p>
<p> </p>
<p align="center"><strong>Mortgage Calculator using either the Canadian or U.S.
Formula</strong></p>
<form NAME="smpc">
<div align="center"><center><p><b>This calculator calculates U.S. and Canadian
monthly
mortgage payments based on principal, interest and term. U.S. mortgages are
compounded
monthly while Canadian mortgages are compounded semi-annually.</b></p>
</center></div><div align="center"><center><table BORDER="0" CELLPADDING="5">
<tr>
<td ALIGN="RIGHT"><em>Amortization</em>(Years) = </td>
<td><input TYPE="TEXT" NAME="years" VALUE="25" SIZE="3"></td>
</tr>
<tr>
<td ALIGN="RIGHT"><em>Term</em> (Years) = </td>
<td><input TYPE="TEXT" NAME="term" VALUE="5" SIZE="3"></td>
</tr>
<tr>
<td ALIGN="RIGHT"><em>Yearly Interest Rate</em> (%) = </td>
<td><input TYPE="TEXT" NAME="percent" VALUE="7" SIZE="6"></td>
</tr>
<tr>
<td ALIGN="RIGHT"><em>Principal Amount</em> ($) = </td>
<td><input TYPE="TEXT" VALUE="100000" NAME="tprinc" SIZE="10"></td>
</tr>
<tr>
<td ALIGN="RIGHT"><em>Down Payment</em> (%) = </td>
<td><input TYPE="TEXT" VALUE="25" NAME="downp" SIZE="10"></td>
</tr>
<tr>
<td ALIGN="RIGHT"><input TYPE="button" VALUE="Calculate Payment (Canadian)"
ONCLICK="calcPaym(1)"></td>
<td><input TYPE="button" VALUE="Calculate Payment (U.S)"
ONCLICK="calcPaym(0)"></td>
</tr>
<tr>
<td ALIGN="RIGHT">Downpayment Required ($) =</td>
<td><input TYPE="TEXT" NAME="downr" SIZE="10"></td>
</tr>
<tr>
<td ALIGN="RIGHT">Mortgage Principal ($) =</td>
<td><input TYPE="TEXT" NAME="princ" SIZE="10"></td>
</tr>
<tr>
<td ALIGN="RIGHT">Monthly Payment ($) =</td>
<td><input TYPE="TEXT" NAME="paym" SIZE="10"><input TYPE="TEXT"
NAME="comp"
VALUE="Canadian" SIZE="10"></td>
</tr>
<tr>
<td ALIGN="RIGHT">Still Owing at End of Term ($) =</td>
<td><input TYPE="TEXT" NAME="owed" SIZE="10"></td>
</tr>
</table>
</center></div>
</form>
<p> </p>
</body>
</html>
Get documents about "