Question

In: Computer Science

Using Java: When buying a house or condo (using a mortgage), or when taking out a...

Using Java:

When buying a house or condo (using a mortgage), or when taking out a loan, you’ll usually wind up with some form of a fixed monthly payment. Mortgages and loans work this way:

  • You take out a loan from the bank or lender for
    • a specified amount of money
    • at a specified annual interest rate
    • with a specified monthly payment amount
  • At the beginning of every month, interest is added to the amount you owe the bank or lender (the outstanding balance of your mortgage or loan)
  • The amount you owe is then decreased by the your monthly payment to arrive at your new outstanding balance for the next month
  • You continue to pay the bank or lender in monthly installments until the outstanding balance is paid in full (i.e., goes down to zero)

The numbers determined at the beginning of every mortgage or loan are:

  • The original amount of the mortgage or loan
  • The annual interest rate for the life of the mortgage or loan
  • The monthly payment you’ll make until the outstanding balance is paid in full

Interest and new outstanding balance are calculated at the beginning of every month:

  • monthly interest = (annual interest rate) / 12 * current outstanding balance
  • new outstanding balance = current outstanding balance + monthly interest – monthly payment

If the new outstanding balance goes negative, then the over-payment for the last month is refunded and the mortgage is considered “paid in full”.

Write a program which uses a recursive method to determine and display the number of months required to pay off a mortgage or loan (when the new outstanding balance goes to 0.00) and the total interest paid over the life of the mortgage or loan. You may want to display the outstanding balance and monthly interest calculated at the beginning of each month, but this is not required.

Use the following test cases:

  1. Initial loan: $180,000, annual interest: 6.25%, monthly payment: $1,850.00
  2. Initial loan: $400,000, annual interest: 5.00%, monthly payment: $2,000.00

We also need to cover the case where the monthly payment amount doesn’t cover the calculated monthly interest. In this case, the balance on the loan actually goes up, not down! (This is known as “negative amortization”.) If this is the case, your recursive method should show the interest and the monthly payment for the first month, then stop.

Test case for negative amortization:

  1. Initial mortgage: $300,000, annual interest: 4.50%, monthly payment: $1,000.00

Please print all dollar amounts to 2 decimal places.

Solutions

Expert Solution

All the explanation is in the code comments. Hope it helps!

Code:

import java.util.*;

public class Main
{
public static void calcInterest(float outBal, float annRate, float monthlyPay, int months, float totalInt)
{
// base condition
if(outBal <= 0)
{
// print the months and total interest
// months - 1 because the current months is not included
System.out.println("The number of months required to pay off a mortgage or loan: " + (months - 1));
System.out.printf("The total interest paid over the life of the mortgage or loan: $%.2f\n", totalInt);
return;
}
  
System.out.println("For month " + months + " ------------------------");
// print Outstanding balance
System.out.printf("Outstanding balance: $%.2f\n", outBal);
  
// calcuate monthly interest
float monthlyInterest = annRate / (100 * 12) * outBal;
  
// print monthly interest
System.out.printf("Monthly interest: $%.2f\n", monthlyInterest);
  
// check case of negative amortization
if(monthlyPay <= monthlyInterest)
{
System.out.println("Stopping because of negative amortization");
return;
}
  
// recursive call with updated Outstanding balance
calcInterest(outBal + monthlyInterest - monthlyPay,
annRate, monthlyPay, months+1, totalInt + monthlyInterest);
}
   public static void main(String[] args) {
       // input stream
       Scanner sc = new Scanner(System.in);
      
       float initLoan, annRate, monthlyPay;
      
       // input from user
       System.out.println("Enter initial loan, annual interest and monthly payment");
       initLoan = Float.parseFloat(sc.next());
       annRate = Float.parseFloat(sc.next());
       monthlyPay = Float.parseFloat(sc.next());
      
       // call to the recursive function with number of months as 1
       // and initial total interest as 0
       calcInterest(initLoan, annRate, monthlyPay, 1, 0.0f);
      
   }
}

Sample run:

Please note that the output was very long, therefore, given just a part of it.

#1

#2

#3

Code screenshots:


Related Solutions

(In Java Using recursive techniques) When buying a house or condo (using a mortgage), or when...
(In Java Using recursive techniques) When buying a house or condo (using a mortgage), or when taking out a loan, you’ll likely wind up with some form of a fixed monthly payment. Mortgages and loans work this way: You take out a loan from the bank or lender for a specified amount of money at a specified annual interest rate with a specified monthly payment amount At the beginning of every month, interest is added to the amount you owe...
Suppose you are buying a house and have taken out a mortgage for $250,000. The mortgage...
Suppose you are buying a house and have taken out a mortgage for $250,000. The mortgage is a 30 year fixed rate mortgage with an APR of 5.25%. What is your monthly mortgage payment? Construct a loan amortization table in Excel for mortgage loan in the previous problem. You should do the problem in Excel using monthly payments and you must submit the spreadsheet with formulas.
Jayce is borrowing $148,000 to buy a house. He is taking out a 30 year mortgage...
Jayce is borrowing $148,000 to buy a house. He is taking out a 30 year mortgage with a 5.35% fixed interest rate. Property taxes are $4,975 and homeowners insurance is $1125 per year. PMI is $75 per month. Find his total monthly (PITI) payment. Show your work.
The Rialto family bought a house 10 years ago, taking out a mortgage loan for $249,500...
The Rialto family bought a house 10 years ago, taking out a mortgage loan for $249,500 at 7% interest for 30 years. They've made all of their monthly payments on time for the past 10 years. With 20 years left on the loan, how much does the Rialto family still owe on the mortgage? (Hint: first you will need to figure out the monthly payment on the 30 year loan.)
Suppose you are buying a beach house condo for $450,000. You are planning to finance the...
Suppose you are buying a beach house condo for $450,000. You are planning to finance the ENTIRE amount of the condo via a mortgage for 30 years, 5% fixed, 0-points. The HOA fees, property taxes, Annual maintenance + Upkeep of the condo = $12,000 per year. Utilities are $150/month You are planning to rent this condo, and your rental income is $40,000 per year (gross), which goes up by 2% per year. Expenses to rent out the property are 30%...
3. Bobby and Sylvia are buying a house. They have applied for a $215,000 mortgage at...
3. Bobby and Sylvia are buying a house. They have applied for a $215,000 mortgage at two companies: a. Company 1: (Canwee, Cheatum and Howe) lasting 30 years at 3.99% interest. b. Company 2: (How, Wei, Ripum and Off) lasting 25 years at 3.67% interest. c. Determine their monthly payment from each company d. How much principal and interest will be paid for the first payment from each company? e. Which is the better deal?
You apply for a mortgage loan on a $120,000 condo using 80% loan-to-value.
You apply for a mortgage loan on a $120,000 condo using 80% loan-to-value. Going interest rates are 4.00%, but after thoroughly surfing the net, you find a lender to grant you a loan at 3.25%. and jump on it. It’s a 30-year loan paid monthly. How much interest would you save during the first 10 years of the loan now that you’ve found the lower interest rate?
What is the significance of taking out inventory when using the quick ratio? When I discussed...
What is the significance of taking out inventory when using the quick ratio? When I discussed leverage in my lecture I went over a few examples of when leverage caused a higher return and some where it caused a lower return. What was it that caused it to change from making money to losing money on an investment? Why are the receivables, inventory and payable turnover ratios considered "asset management" or "efficiency" ratios?
You are buying a house and the mortgage company offers to let you pay a​ "point"...
You are buying a house and the mortgage company offers to let you pay a​ "point" ​(1.0 % of the total amount of the​ loan) to reduce your APR from 6.24% to 5.99% on your $409,000​, 30​-year mortgage with monthly payments. If you plan to be in the house for at least five​ years, should you do​ it? (Note: Be careful not to round any intermediate steps less than six decimal​ places.) The monthly mortgage payment at 6.24% APR is...
You are buying a house and the mortgage company offers to let you pay a​ "point"...
You are buying a house and the mortgage company offers to let you pay a​ "point" ​(1.0 % of the total amount of the​ loan) to reduce your APR from 5.96 % to 5.71 % on your $429,000​, 3030​-year mortgage with monthly payments. If you plan to be in the house for at least five​ years, should you do​ it? The PV of the monthly savings is $ The balance of the mortgage at the end of five years at...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT