Permalink
Browse files

Complete.

  • Loading branch information...
1 parent fe7fd92 commit 00ad54e5e81876d9ed74b8a302b4074fa7be84bc BBK-PiJ-2012-00 committed Oct 14, 2012
Showing with 37 additions and 17 deletions.
  1. +37 −17 mortgage.groovy
View
@@ -1,23 +1,43 @@
-class Mortgage {
- double borrowed;
- double interestRate;
- double years;
- double rateMultiplier;
- double
+double totalCostCalculator(double borrowed, double interestRate) {
+ double rateMultiplier = 1 + (interestRate / 100);
+ double cost = borrowed * rateMultiplier;
+ result = cost;
+ return result;
}
-double totalCost (Mortgage rateMultiplier,tage, rate, result) {
- rateMultiplier = 1 + (rate / 100)
- result = borrowed x percentage
+double repaymentsCalculator(double mortgageCost, double years) {
+ double yearlyPayment = mortgageCost / years;
+ result = yearlyPayment;
return result;
}
-println "The total cost is: " + totalCost()
-println "Please enter the total amount borrowed: "
+double interestTimeCalculator(double mortgageCost, double borrowed, double repaymentRate) {
+ double interestAmount = mortgageCost - borrowed;
+ double interestTime
+ double repaymentMonthly = repaymentRate / 12
+ for (interestTime = 0; interestAmount > 0; interestTime++) {
+ interestAmount = interestAmount - repaymentMonthly;
+ }
+ result = interestTime;
+ return result;
+}
+println "This program calculates the total mortgage amount to be paid, the money to be repaid every year, and the number of years before the interest is paid and only the initial capital remains. Please begin by entering the following: "
+print "Total amount borrowed: "
double borrowed = Double.parseDouble(System.console().readLine())
-println "Please enter the interest rate: "
-double rate = Double.parseDouble(System.console().readLine())
-println "Please enter the number of years you have to pay it back: "
-double years = Double.parseDouble(System.console().readLine())
+print "Years to pay it back: "
+double years = Double.parseDouble(System.console().readLine())
+print "The interest rate: "
+double interestRate = Double.parseDouble(System.console().readLine())
+double mortgageCost = totalCostCalculator(borrowed, interestRate);
+println "The total cost of your mortgage is: £" + mortgageCost
+double repaymentRate = repaymentsCalculator(mortgageCost, years);
+println "You will need to repay £" + repaymentRate + " every year."
+double interestAlone = interestTimeCalculator(mortgageCost, borrowed, repaymentRate);
+if (interestAlone >= 12) {
+ double interestYearly = interestAlone / 12
+ println "It will take you " + interestYearly + " years to pay off the interest alone."
+}
+else if (interestAlone < 12) {
+ println "It will take you " + interestAlone + " months to pay off the interest alone."
+}
+
-Mortgage.borrowed = Double.parseDouble(System.console().readLine())
-Mortgage.rate = Double.parseDouble(System.console().readLine))

0 comments on commit 00ad54e

Please sign in to comment.