Mortgage Payment

Design a class that will determine the monthly payment on a home mortgage. The monthly payment with interest compounded monthly can be calculated as follows:

1. **Class Design**:
- The class `Mortgage_Calculator` should have member functions for setting the loan amount, interest rate, and number of years of the loan.
- It should also have member functions for returning the monthly payment amount and the total amount paid to the bank at the end of the loan period.
- Implement the class in a complete program.

2. **Input Validation**:
- Only accept numbers.
- The program will exit if the loan amount is less than 0.
- After calculating and printing out mortgage information, ask the user if they want to run the program again.
- If the user enters 'Y' or 'y', the program will prompt the user to calculate another mortgage amount.
- If the user enters anything other than 'Y' or 'y', the program will exit with "Have a nice day" printed.

3. **Example**:
- Use the sample data in the screenshot below as your input example:
- Data validation: Use "ten" as input to check for number-only validation.
- Loan amount: 250000
- Interest rate: 2.875
- Loan year: 30

4. **Program Output**:
- Your program output should be similar to the following:

```
Enter the amount of loan (<0 to quit): ten
Loan amount must be a number >0. Please re-enter:
Enter the amount of loan (<0 to quit): 250000
Enter the annual interest rate in decimal form (%): 2.875
Enter the length of the loan in years: 30

Monthly Payment: $1037.23
Total Pay Back: $373403.23

Calculate another mortgage? (Y/N): y
Enter the amount of loan (<0 to quit): -1
Have a nice day.
```

Answer :

Final answer:

To design a class for mortgage payment calculation, you need to consider the loan amount, interest rate, and number of years of the loan. The monthly payment can be calculated using the formula: Monthly Payment = (Loan Amount * Monthly Interest Rate) / (1 - (1 + Monthly Interest Rate)^(-Number of Months)). Implement the class with member functions for setting the loan amount, interest rate, and loan duration, as well as returning the monthly payment amount and the total amount paid to the bank at the end of the loan period. Include input validation to ensure only numbers are accepted and the program exits if the loan amount is less than 0. Ask the user if they want to calculate another mortgage amount and exit the program if they enter anything other than 'Y' or 'y'.

Explanation:

To design a class for mortgage payment calculation, we need to consider the loan amount, interest rate, and number of years of the loan. The monthly payment with interest compounded monthly can be calculated using the following formula:

Monthly Payment = (Loan Amount * Monthly Interest Rate) / (1 - (1 + Monthly Interest Rate)^(-Number of Months))

To implement the class, we can create member functions for setting the loan amount, interest rate, and loan duration. We can also create member functions for returning the monthly payment amount and the total amount paid to the bank at the end of the loan period. Additionally, we need to include input validation to ensure that only numbers are accepted and the program exits if the loan amount is less than 0. After calculating and printing out the mortgage information, we can ask the user if they want to calculate another mortgage amount and exit the program if they enter anything other than 'Y' or 'y'.

Learn more about designing a class for mortgage payment calculation here:

https://brainly.com/question/34896385

#SPJ14