Question

In: Computer Science

(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 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 overpayment 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

Remember to use Recursive techniques

Please print all dollar amounts to 2 decimal places.

Solutions

Expert Solution

import java.util.*;
class Main{
public static void main(String ar[]){
Scanner sc=new Scanner(System.in);
float principle,rate,monthlyPayment;
principle=sc.nextFloat();
rate=sc.nextFloat();
monthlyPayment=sc.nextFloat();
Loan l=new Loan(principle,rate,monthlyPayment);
l.print();
l.calculate();
}
}
class Loan{
private float principle;
private float rate;
private float monthlyPayment;
private float totalInterest;
private int time;
  
Loan(float principle,float rate,float monthlyPayment){
this.principle=principle;
this.rate=rate;
this.monthlyPayment=monthlyPayment;
}
public void print(){
System.out.println(principle);
System.out.println(rate);
System.out.println(monthlyPayment);
}
public void calculate(){
totalInterest=0;
time=0;
float x=principle*rate/1200; //interest of first month
//negative amortization if interest of first month>=monthly payment
if(x>=monthlyPayment){
System.out.print("Interest of first month is ");
System.out.printf("%.2f",x);
System.out.println();
System.out.print("Monthly payment is ");
System.out.printf("%.2f",monthlyPayment);
System.out.println();
}
// if it is positive amortization then
else{
calc(principle);
System.out.println("Time taken to pay the loan is "+time+" months");
System.out.print("Total interest paid is ");
System.out.printf("%.2f",totalInterest);
System.out.println();
}
}
private void calc(float amt){
if(amt<=0){ // if amount is <=0 then loan is paid fully
totalInterest=totalInterest-principle+amt; //Interest=paid money - (principle amount at the begining + overpayment(that will be refunded))
return;
}
amt=amt+amt*rate/1200-monthlyPayment; //principle amount for next month
time+=1; //no. of months passed till this point
totalInterest+=monthlyPayment; //paid money till now = money paid upto last month + payment of current month
calc(amt);
}
}


Related Solutions

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...
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%...
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.
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?
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...
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.46 % to 6.21 % on your $ 403 comma 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...
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.88% to 5.63% on your $419,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 5.88% APR is $_...
You are buying a new house on a 30-year, 5.2% mortgage loan of $230,000. A) How...
You are buying a new house on a 30-year, 5.2% mortgage loan of $230,000. A) How much will your monthly payments be? B) How much will go toward principal in the 75th month? How much will go toward interest in the 75th month? What will be the balance after 75 months? C) How much interest will you pay in total over the 30 years? D) If you do a 15-year loan instead of a 30-year one, how much will you...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT