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).

Microsoft Visual C#
7th Edition
ISBN:9781337102100
Author:Joyce, Farrell.
Publisher:Joyce, Farrell.
Chapter10: Introduction To Inheritance
Section: Chapter Questions
Problem 6RQ
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
Microsoft Visual C#
Microsoft Visual C#
Computer Science
ISBN:
9781337102100
Author:
Joyce, Farrell.
Publisher:
Cengage Learning,