In this exercise, you will be completing part of the MortgageCalc class. The MortgageCalc class is a class containing static methods to help calculate elements related to home loans, such as a payment calculator, principal payment calculator, and a remaining principal balance calculator. You will write two methods of the class.     public class MortgageCalc {   /** * This method calculates the monthly payments for a mortgage payment * @param principal Initial amount of the loan * @param numPayments number of months in the loan * @return the monthly payment for the loan */   public static double payment(double principal, int numPayments) { /* To Be implemented in part A */ }   /** * This method returns the remaining balance for a given month * in the loan. * @param originalBal original balance of the loan * @param numPayments original number of months in the loan * @param currPeriod the month to calculate the remaining balance * @return the remaining balance on the loan */ public static double remainingPrincipal(double originalBal, int numPayments, int currPeriod) { /* To be implemented in part B */ }   /** * This method returns the current annual interest rate * @return decimal value of the annual interest rate * example: 4% interest is returned as 0.04 */   public static double currentRate() { /* Implementation not shown */ }   /** * This method returns the amount of principal paid for a given month * in the loan. * @param originalBal original balance of the loan * @param numPayments original number of months in the loan * @param currPeriod the month to calculate the principal payment * @return the amount of the payment that is applied to the * principal balance for the currPeriod */ public static double principalPayment(double originalBal, int numPayments, int currPeriod) { /* Implementation not shown */ } }   Part A   Write the static method payment which takes the initial amount of the loan (principal) and the number of payments (in months) and returns the monthly payment as a double.   To calculate the payment, you will also need the monthly interest rate, which can be calculated from the static currentRate() method that returns the current annual interest rate.   The formula for calculating the payment is:       Where P is the principal, r is the monthly interest rate, and n is the number of payments (in months).

Database System Concepts
7th Edition
ISBN:9780078022159
Author:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Chapter1: Introduction
Section: Chapter Questions
Problem 1PE
icon
Related questions
Question

Mortgage Calculator

 

In this exercise, you will be completing part of the MortgageCalc class. The MortgageCalc class is a class containing static methods to help calculate elements related to home loans, such as a payment calculator, principal payment calculator, and a remaining principal balance calculator. You will write two methods of the class.

 

 

public class MortgageCalc {

 

/**

* This method calculates the monthly payments for a mortgage payment

* @param principal Initial amount of the loan

* @param numPayments number of months in the loan

* @return the monthly payment for the loan

*/

 

public static double payment(double principal, int numPayments)

{

/* To Be implemented in part A */

}

 

/**

* This method returns the remaining balance for a given month

* in the loan.

* @param originalBal original balance of the loan

* @param numPayments original number of months in the loan

* @param currPeriod the month to calculate the remaining balance

* @return the remaining balance on the loan

*/

public static double remainingPrincipal(double originalBal, int numPayments, int currPeriod)

{

/* To be implemented in part B */

}

 

/**

* This method returns the current annual interest rate

* @return decimal value of the annual interest rate

* example: 4% interest is returned as 0.04

*/

 

public static double currentRate()

{

/* Implementation not shown */

}

 

/**

* This method returns the amount of principal paid for a given month

* in the loan.

* @param originalBal original balance of the loan

* @param numPayments original number of months in the loan

* @param currPeriod the month to calculate the principal payment

* @return the amount of the payment that is applied to the

* principal balance for the currPeriod

*/

public static double principalPayment(double originalBal, int numPayments, int currPeriod)

{

/* Implementation not shown */

}

}

 

Part A

 

Write the static method payment which takes the initial amount of the loan (principal) and the number of payments (in months) and returns the monthly payment as a double.

 

To calculate the payment, you will also need the monthly interest rate, which can be calculated from the static currentRate() method that returns the current annual interest rate.

 

The formula for calculating the payment is:

 

 

 

Where P is the principal, r is the monthly interest rate, and n is the number of payments (in months).

 

Part B

 

Write the static method remainingPrincipal which takes the original balance of the loan, the number of payments (in months), and the current period and returns the remaining balance of the loan as a double.

 

To calculate the remaining balance, you can use the principalPayment() static method which returns the amount of principal that was paid in a given month. The remaining balance will be the initial balance minus the principal paid for all the month up to the current month.

 

Expert Solution
trending now

Trending now

This is a popular solution!

steps

Step by step

Solved in 2 steps with 2 images

Blurred answer
Knowledge Booster
Class
Learn more about
Need a deep-dive on the concept behind this application? Look no further. Learn more about this topic, computer-science and related others by exploring similar questions and additional content below.
Similar questions
  • SEE MORE QUESTIONS
Recommended textbooks for you
Database System Concepts
Database System Concepts
Computer Science
ISBN:
9780078022159
Author:
Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:
McGraw-Hill Education
Starting Out with Python (4th Edition)
Starting Out with Python (4th Edition)
Computer Science
ISBN:
9780134444321
Author:
Tony Gaddis
Publisher:
PEARSON
Digital Fundamentals (11th Edition)
Digital Fundamentals (11th Edition)
Computer Science
ISBN:
9780132737968
Author:
Thomas L. Floyd
Publisher:
PEARSON
C How to Program (8th Edition)
C How to Program (8th Edition)
Computer Science
ISBN:
9780133976892
Author:
Paul J. Deitel, Harvey Deitel
Publisher:
PEARSON
Database Systems: Design, Implementation, & Manag…
Database Systems: Design, Implementation, & Manag…
Computer Science
ISBN:
9781337627900
Author:
Carlos Coronel, Steven Morris
Publisher:
Cengage Learning
Programmable Logic Controllers
Programmable Logic Controllers
Computer Science
ISBN:
9780073373843
Author:
Frank D. Petruzella
Publisher:
McGraw-Hill Education