Skip to content
Browse files

Added purchase price and down payment amount

  • Loading branch information...
1 parent 96f2225 commit 57cc72dd9c191dc19d1ebca978136b0d06328634 @robertgreiner committed Feb 4, 2011
View
22 LoanGeek.Tests/TestLoanData.cs
@@ -18,54 +18,60 @@ public class TestLoanData {
}
[Test]
+ public void TestPrincipalCalculation() {
+ LoanData loanData = new LoanData(200000.00, 50, 4.125, 30, 2.76, 0.8, 600.00, 743.27);
+ Assert.AreEqual(100000.00, Math.Round(loanData.Principal, 2));
+ }
+
+ [Test]
public void TestTotalMonthlyPayment() {
- LoanData loanData = new LoanData(200000.00, 4.125, 30, 2.76, 0.8, 600.00, 743.27);
+ LoanData loanData = new LoanData(200000.00, 0, 4.125, 30, 2.76, 0.8, 600.00, 743.27);
Assert.AreEqual(1674.57, Math.Round(loanData.MonthlyPayment, 2));
}
[Test]
public void TestMonthlyInterestPayment() {
- LoanData loanData = new LoanData(200000.00, 4.125, 30, 2.76, 0.8, 600.00, 743.27);
+ LoanData loanData = new LoanData(200000.00, 0, 4.125, 30, 2.76, 0.8, 600.00, 743.27);
Assert.AreEqual(687.50d, Math.Round(loanData.InterestOnlyMonthly, 2));
}
[Test]
public void TestMonthlyPrincipalPayment() {
- LoanData loanData = new LoanData(200000.00, 4.125, 30, 2.76, 0.8, 600.00, 743.27);
+ LoanData loanData = new LoanData(200000.00, 0, 4.125, 30, 2.76, 0.8, 600.00, 743.27);
double principalMonthly = Math.Round(loanData.PrincipalOnlyMonthly, 2);
Assert.AreEqual(281.80d, principalMonthly);
}
[Test]
public void TestMonthlyPrincipalAndInterestPayment() {
- LoanData loanData = new LoanData(200000.00, 4.125, 30, 2.76, 0.8, 600.00, 743.27);
+ LoanData loanData = new LoanData(200000.00, 0, 4.125, 30, 2.76, 0.8, 600.00, 743.27);
double principalAndInterest = loanData.InterestOnlyMonthly + loanData.PrincipalOnlyMonthly;
Assert.AreEqual(969.30d, Math.Round(principalAndInterest, 2));
}
[Test]
public void TestMonthlyPropertyTaxPayment() {
- LoanData loanData = new LoanData(200000.00, 4.125, 30, 2.76, 0.8, 600.00, 743.27);
+ LoanData loanData = new LoanData(200000.00, 0, 4.125, 30, 2.76, 0.8, 600.00, 743.27);
Assert.AreEqual(460.00, Math.Round(loanData.MonthlyPropertyTaxPayment, 2));
}
[Test]
public void TestMonthlyPmiPayment() {
- LoanData loanData = new LoanData(200000.00, 4.125, 30, 2.76, 0.8, 600.00, 743.27);
+ LoanData loanData = new LoanData(200000.00, 0, 4.125, 30, 2.76, 0.8, 600.00, 743.27);
Assert.AreEqual(133.33d, Math.Round(loanData.MonthlyPmiPayment, 2));
}
[Test]
public void TestMonthlyHoaPayment() {
- LoanData loanData = new LoanData(200000.00, 4.125, 30, 2.76, 0.8, 600.00, 743.27);
+ LoanData loanData = new LoanData(200000.00, 0, 4.125, 30, 2.76, 0.8, 600.00, 743.27);
double monthlyHoa = loanData.HoaDuesYearly / 12;
monthlyHoa = Math.Round(monthlyHoa, 2);
Assert.AreEqual(50.00d, monthlyHoa);
}
[Test]
public void TestMonthlyInsurancePayment() {
- LoanData loanData = new LoanData(200000.00, 4.125, 30, 2.76, 0.8, 600.00, 743.27);
+ LoanData loanData = new LoanData(400000.00, 50, 4.125, 30, 2.76, 0.8, 600.00, 743.27);
double monthlyInsurance = loanData.InsuranceYearly / 12;
monthlyInsurance = Math.Round(monthlyInsurance);
Assert.AreEqual(62.00d, monthlyInsurance);
View
BIN LoanGeek.Tests/bin/Release/LoanGeek.Tests.dll
Binary file not shown.
View
6 LoanGeek.Tests/bin/Release/LoanGeek.Tests.dll.VisualState.xml
@@ -1,11 +1,11 @@
<?xml version="1.0" encoding="utf-8"?>
<VisualState xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" ShowCheckBoxes="false">
- <TopNode>[0-1010]D:\projects\LoanGeek\LoanGeek.Tests\bin\Release\LoanGeek.Tests.dll</TopNode>
+ <TopNode>[0-1011]D:\projects\LoanGeek\LoanGeek.Tests\bin\Release\LoanGeek.Tests.dll</TopNode>
<SelectedNode>[0-1000]UnitTests.TestLoanData</SelectedNode>
<ExcludeCategories>false</ExcludeCategories>
<Nodes>
- <Node UniqueName="[0-1010]D:\projects\LoanGeek\LoanGeek.Tests\bin\Release\LoanGeek.Tests.dll" Expanded="true" />
- <Node UniqueName="[0-1011]UnitTests" Expanded="true" />
+ <Node UniqueName="[0-1011]D:\projects\LoanGeek\LoanGeek.Tests\bin\Release\LoanGeek.Tests.dll" Expanded="true" />
+ <Node UniqueName="[0-1012]UnitTests" Expanded="true" />
<Node UniqueName="[0-1000]UnitTests.TestLoanData" Expanded="true" />
</Nodes>
</VisualState>
View
BIN LoanGeek.Tests/bin/Release/LoanGeek.Tests.pdb
Binary file not shown.
View
BIN LoanGeek.Tests/bin/Release/LoanGeek.dll
Binary file not shown.
View
BIN LoanGeek.Tests/bin/Release/LoanGeek.pdb
Binary file not shown.
View
19 LoanGeek.Tests/bin/Release/TestResult.xml
@@ -1,23 +1,24 @@
<?xml version="1.0" encoding="utf-8" standalone="no"?>
<!--This file represents the results of running a test suite-->
-<test-results name="D:\projects\LoanGeek\LoanGeek.Tests\bin\Release\LoanGeek.Tests.dll" total="9" errors="0" failures="0" not-run="0" inconclusive="0" ignored="0" skipped="0" invalid="0" date="2010-09-04" time="20:29:54">
- <environment nunit-version="2.5.7.10213" clr-version="2.0.50727.4952" os-version="Microsoft Windows NT 6.1.7600.0" platform="Win32NT" cwd="C:\Program Files (x86)\NUnit 2.5.7\bin\net-2.0" machine-name="SNACKATTACK" user="Robert" user-domain="snackattack" />
+<test-results name="D:\projects\LoanGeek\LoanGeek.Tests\bin\Release\LoanGeek.Tests.dll" total="10" errors="0" failures="0" not-run="0" inconclusive="0" ignored="0" skipped="0" invalid="0" date="2011-02-04" time="13:46:22">
+ <environment nunit-version="2.5.9.10348" clr-version="2.0.50727.4952" os-version="Microsoft Windows NT 6.1.7600.0" platform="Win32NT" cwd="C:\Program Files (x86)\NUnit 2.5.9\bin\net-2.0" machine-name="SNACKATTACK" user="Robert" user-domain="Snackattack" />
<culture-info current-culture="en-US" current-uiculture="en-US" />
- <test-suite type="Assembly" name="D:\projects\LoanGeek\LoanGeek.Tests\bin\Release\LoanGeek.Tests.dll" executed="True" result="Success" success="True" time="0.099" asserts="0">
+ <test-suite type="Assembly" name="D:\projects\LoanGeek\LoanGeek.Tests\bin\Release\LoanGeek.Tests.dll" executed="True" result="Success" success="True" time="0.124" asserts="0">
<results>
- <test-suite type="Namespace" name="UnitTests" executed="True" result="Success" success="True" time="0.084" asserts="0">
+ <test-suite type="Namespace" name="UnitTests" executed="True" result="Success" success="True" time="0.105" asserts="0">
<results>
- <test-suite type="TestFixture" name="TestLoanData" executed="True" result="Success" success="True" time="0.082" asserts="0">
+ <test-suite type="TestFixture" name="TestLoanData" executed="True" result="Success" success="True" time="0.103" asserts="0">
<results>
- <test-case name="UnitTests.TestLoanData.TestMonthlyHoaPayment" executed="True" result="Success" success="True" time="0.045" asserts="1" />
+ <test-case name="UnitTests.TestLoanData.TestMonthlyHoaPayment" executed="True" result="Success" success="True" time="0.059" asserts="1" />
<test-case name="UnitTests.TestLoanData.TestMonthlyInsurancePayment" executed="True" result="Success" success="True" time="0.001" asserts="1" />
<test-case name="UnitTests.TestLoanData.TestMonthlyInterestPayment" executed="True" result="Success" success="True" time="0.001" asserts="1" />
- <test-case name="UnitTests.TestLoanData.TestMonthlyPmiPayment" executed="True" result="Success" success="True" time="0.001" asserts="1" />
+ <test-case name="UnitTests.TestLoanData.TestMonthlyPmiPayment" executed="True" result="Success" success="True" time="0.002" asserts="1" />
<test-case name="UnitTests.TestLoanData.TestMonthlyPrincipalAndInterestPayment" executed="True" result="Success" success="True" time="0.001" asserts="1" />
<test-case name="UnitTests.TestLoanData.TestMonthlyPrincipalPayment" executed="True" result="Success" success="True" time="0.001" asserts="1" />
- <test-case name="UnitTests.TestLoanData.TestMonthlyPropertyTaxPayment" executed="True" result="Success" success="True" time="0.001" asserts="1" />
+ <test-case name="UnitTests.TestLoanData.TestMonthlyPropertyTaxPayment" executed="True" result="Success" success="True" time="0.002" asserts="1" />
+ <test-case name="UnitTests.TestLoanData.TestPrincipalCalculation" executed="True" result="Success" success="True" time="0.001" asserts="1" />
<test-case name="UnitTests.TestLoanData.testRounding" executed="True" result="Success" success="True" time="0.001" asserts="1" />
- <test-case name="UnitTests.TestLoanData.TestTotalMonthlyPayment" executed="True" result="Success" success="True" time="0.000" asserts="1" />
+ <test-case name="UnitTests.TestLoanData.TestTotalMonthlyPayment" executed="True" result="Success" success="True" time="0.001" asserts="1" />
</results>
</test-suite>
</results>
View
BIN LoanGeek.Tests/obj/Release/DesignTimeResolveAssemblyReferencesInput.cache
Binary file not shown.
View
1 LoanGeek.Tests/obj/Release/LoanGeek.Tests.csproj.FileListAbsolute.txt
@@ -1,6 +1,5 @@
D:\projects\LoanGeek\LoanGeek.Tests\bin\Release\LoanGeek.Tests.dll
D:\projects\LoanGeek\LoanGeek.Tests\bin\Release\LoanGeek.Tests.pdb
-D:\projects\LoanGeek\LoanGeek.Tests\bin\Release\nunit.framework.dll
D:\projects\LoanGeek\LoanGeek.Tests\bin\Release\nunit.framework.xml
D:\projects\LoanGeek\LoanGeek.Tests\obj\Release\ResolveAssemblyReference.cache
D:\projects\LoanGeek\LoanGeek.Tests\obj\Release\LoanGeek.Tests.dll
View
BIN LoanGeek.Tests/obj/Release/LoanGeek.Tests.dll
Binary file not shown.
View
BIN LoanGeek.Tests/obj/Release/LoanGeek.Tests.pdb
Binary file not shown.
View
BIN LoanGeek.Tests/obj/Release/ResolveAssemblyReference.cache
Binary file not shown.
View
BIN LoanGeek.suo
Binary file not shown.
View
25 LoanGeek/Models/LoanData.cs
@@ -7,8 +7,11 @@
namespace LoanGeek.Models {
public class LoanData {
- [Required(ErrorMessage = "Please enter your the total loan amount.")]
- public double Principal { get; set; }
+ [Required(ErrorMessage = "Please enter your the purchase price for your new home.")]
+ public double PurchasePrice { get; set; }
+
+ [Required(ErrorMessage = "Please enter the downpayment amount.")]
+ public double DownPayment { get; set; }
[Required(ErrorMessage = "Please enter the interest rate.")]
public double InterestRate { get; set; }
@@ -28,6 +31,8 @@ public class LoanData {
[Required(ErrorMessage = "Please enter your yearly insurance premium.")]
public double InsuranceYearly { get; set; }
+ public double Principal { get; set; }
+
public double MonthlyInterestMultiplier { get; private set; }
public int AmortizedMonths { get; private set; }
public double InterestOnlyMonthly { get; private set; }
@@ -37,8 +42,9 @@ public class LoanData {
public double MonthlyPropertyTaxPayment { get; private set; }
public double MonthlyPmiPayment { get; private set; }
- public LoanData(double principal, double interest, int term, double tax, double pmi, double hoa, double insurance) {
- Principal = principal;
+ public LoanData(double purchasePrice, double downPayment, double interest, int term, double tax, double pmi, double hoa, double insurance) {
+ PurchasePrice = purchasePrice;
+ DownPayment = downPayment;
InterestRate = interest;
LoanTerm = term;
PropertyTaxPercent = tax;
@@ -50,7 +56,8 @@ public class LoanData {
}
public LoanData() {
- Principal = 200000;
+ PurchasePrice = 200000;
+ DownPayment = 7.5;
InterestRate = 4.5;
LoanTerm = 30;
PropertyTaxPercent = 3.0;
@@ -92,8 +99,9 @@ public class LoanData {
return principalAndInterest;
}
+ //Property tax is based on the appraisal value of the home. Usually, this is the same as the purchase price.
private double CalculatePropertyTax() {
- MonthlyPropertyTaxPayment = (Principal * (PropertyTaxPercent / 100)) / 12;
+ MonthlyPropertyTaxPayment = (PurchasePrice * (PropertyTaxPercent / 100)) / 12;
return MonthlyPropertyTaxPayment;
}
@@ -102,7 +110,12 @@ public class LoanData {
return MonthlyPmiPayment;
}
+ private void CalculatePrincipal() {
+ Principal = PurchasePrice - (PurchasePrice * (DownPayment / 100));
+ }
+
public void CalculateTotalMonthlyPayment() {
+ CalculatePrincipal();
MonthlyPayment = CalculatePrincipalAndInterest();
MonthlyPayment += CalculatePropertyTax();
MonthlyPayment += CalculatePmi();
View
16 LoanGeek/Views/Home/Index.aspx
@@ -26,13 +26,15 @@
<% using (Html.BeginForm()) { %>
<%: Html.ValidationSummary() %>
- <div class="label"><h3>Loan Amount ($)</h3> </h3></div> <%: Html.TextBoxFor(x => x.Principal)%><br />
- <div class="label"><h3>Loan Term (years)</h3> </div> <%: Html.TextBoxFor(x => x.LoanTerm)%><br />
- <div class="label"><h3>Interest Rate (%)</h3> </div> <%: Html.TextBoxFor(x => x.InterestRate)%><br />
- <div class="label"><h3>Property Tax (%)</h3> </div> <%: Html.TextBoxFor(x => x.PropertyTaxPercent)%><br />
- <div class="label"><h3>PMI (%)</h3> </div> <%: Html.TextBoxFor(x => x.PmiPercent)%><br />
- <div class="label"><h3>HOA ($/year)</h3> </div> <%: Html.TextBoxFor(x => x.HoaDuesYearly)%><br />
- <div class="label"><h3>Insurance ($/year)</h3> </div> <%: Html.TextBoxFor(x => x.InsuranceYearly)%><br />
+ <div class="label"><h3>Purchase Price ($)</h3> </div> <%: Html.TextBoxFor(x => x.PurchasePrice) %><br />
+ <div class="label"><h3>Down Payment (%)</h3> </div> <%: Html.TextBoxFor(x => x.DownPayment) %><br />
+ <div class="label"><h3>Loan Amount ($)</h3> </div> <%: Html.TextBox("principal") %><br />
+ <div class="label"><h3>Loan Term (years)</h3> </div> <%: Html.TextBoxFor(x => x.LoanTerm) %><br />
+ <div class="label"><h3>Interest Rate (%)</h3> </div> <%: Html.TextBoxFor(x => x.InterestRate) %><br />
+ <div class="label"><h3>Property Tax (%)</h3> </div> <%: Html.TextBoxFor(x => x.PropertyTaxPercent) %><br />
+ <div class="label"><h3>PMI (%)</h3> </div> <%: Html.TextBoxFor(x => x.PmiPercent) %><br />
+ <div class="label"><h3>HOA ($/year)</h3> </div> <%: Html.TextBoxFor(x => x.HoaDuesYearly) %><br />
+ <div class="label"><h3>Insurance ($/year)</h3> </div> <%: Html.TextBoxFor(x => x.InsuranceYearly) %><br />
<input class="button" type="submit" name="submit" value="Calculate Loan" />
<% } %>
</div>
View
BIN LoanGeek/bin/LoanGeek.dll
Binary file not shown.
View
BIN LoanGeek/bin/LoanGeek.pdb
Binary file not shown.
View
BIN LoanGeek/obj/Release/LoanGeek.dll
Binary file not shown.
View
BIN LoanGeek/obj/Release/LoanGeek.pdb
Binary file not shown.

0 comments on commit 57cc72d

Please sign in to comment.
Something went wrong with that request. Please try again.