**I am having trouble with a lab assignment. We are to create a user-defined Loan class and its client class, LoanTest. I also have a Date class already created .**

Each loan object should store the following information:

a. Annual Interest Rate

b. Number of Years

c. Loan Amount

d. Loan Date (You would be specifying Loan Date of the type Date class you created earlier)

Here are the different operations that could be done on any Loan object...

Operation that returns the annual interest rate

Operation that returns the number of years

Operation that returns the loan amount

Operation that returns the Loan Date as a String value providing the date information.

Operation that sets a new annual interest rate

Operation that sets a new number of years

Operation that sets a new loan amount

Operation that calculates and returns the monthly payment

(Calculate the monthly payment using the following formulas:

Monthly payment = (mIR * M) / (1 – (1 / (1 + mIR)(12*nOY) ))

where:

mIR = monthly interest rate (annual interest rate / 12)

nOY = number of years

M = Loan amount

Operation that calculates the total payment amount over the life of the loan

Operation that returns the overpayment amount

For the client LoanTest class, I am instructed to:

Prompt the user for the annual interest rate.

Prompt the user for the number of years the loan will be held

Prompt the user for a number representing the loan amount borrowed from the bank.

Prompt the user for the start date of the loan.

Include necessary checks to validate the above input values.

Create the Loan object

Output a summary of the mortgage problem as follows:

The annual interest rate in percent notation

The mortgage amount in dollars

The monthly payment in dollars, with only two significant digits after the decimal point

The total payment over the years, with only two significant digits after the decimal point

The overpayment with only two significant digits after the decimal point

The overpayment as a percentage (in percent notation) of the mortgage amount

I keep trying to calculate and return the total payment, overpayment, and the percent of overpayment of the mortgage amount and they are wrong. I think it is a problem with my getOverpayment method in the Loan class and I cannot figure it out! Help! Here is my Loan class code:

Each loan object should store the following information:

a. Annual Interest Rate

b. Number of Years

c. Loan Amount

d. Loan Date (You would be specifying Loan Date of the type Date class you created earlier)

Here are the different operations that could be done on any Loan object...

Operation that returns the annual interest rate

Operation that returns the number of years

Operation that returns the loan amount

Operation that returns the Loan Date as a String value providing the date information.

Operation that sets a new annual interest rate

Operation that sets a new number of years

Operation that sets a new loan amount

Operation that calculates and returns the monthly payment

(Calculate the monthly payment using the following formulas:

Monthly payment = (mIR * M) / (1 – (1 / (1 + mIR)(12*nOY) ))

where:

mIR = monthly interest rate (annual interest rate / 12)

nOY = number of years

M = Loan amount

Operation that calculates the total payment amount over the life of the loan

Operation that returns the overpayment amount

For the client LoanTest class, I am instructed to:

Prompt the user for the annual interest rate.

Prompt the user for the number of years the loan will be held

Prompt the user for a number representing the loan amount borrowed from the bank.

Prompt the user for the start date of the loan.

Include necessary checks to validate the above input values.

Create the Loan object

Output a summary of the mortgage problem as follows:

The annual interest rate in percent notation

The mortgage amount in dollars

The monthly payment in dollars, with only two significant digits after the decimal point

The total payment over the years, with only two significant digits after the decimal point

The overpayment with only two significant digits after the decimal point

The overpayment as a percentage (in percent notation) of the mortgage amount

I keep trying to calculate and return the total payment, overpayment, and the percent of overpayment of the mortgage amount and they are wrong. I think it is a problem with my getOverpayment method in the Loan class and I cannot figure it out! Help! Here is my Loan class code:

public class Loan { private double rate; private int years; private double amount; private Date loanDate; private double mPayment; public Loan(double r, int y, double a, Date d) { rate = r; years = y; amount = a; loanDate = d; } public double getRate() { return rate; } public int getYears() { return years; } public double getAmount() { return amount; } public Date getLoanDate() { return loanDate; } public void setRate(double newRate) { rate = newRate; } public void setYears(int newYears) { years = newYears; } public void setAmount(double newAmount) { amount = newAmount; } public double getMPayment() { double mRate = rate/12; double mPayment = (mRate*amount)/(1-(1/Math.pow((1+mRate),(12*years)))); return mPayment; } public double getOverpayment() { double overpayment = ((mPayment*(12*years)) - amount); return overpayment; } }

**Here is my LoanTest class code:**

import java.util.Scanner; //Import the Scanner format class from the java.util package import java.text.NumberFormat; public class LoanTest { public static void main(String [] args) { Scanner scan = new Scanner(System.in); //Instantiate a Scanner object to read from the InputStream System.in. System.out.print("Please enter the loan rate: "); //Write a prompt for user to input the loan rate. double rate = scan.nextDouble(); System.out.print("Please enter the number of years: "); //Write a prompt for user to input the number of years for the loan. int years = scan.nextInt(); System.out.print("Please enter the loan amount: "); //Write a prompt for user to input the amount of the loan. double amount = scan.nextDouble(); System.out.print("Please enter the loan date: (MM DD YYYY)"); //Write a prompt for user to input the date. int m = scan.nextInt(); int d = scan.nextInt(); int y = scan.nextInt(); Date lDate = new Date (m,d,y); Loan myLoan = new Loan(rate,years,amount,lDate); NumberFormat percentFormat = NumberFormat.getPercentInstance(); percentFormat.setMaximumFractionDigits(2); NumberFormat currencyFormat = NumberFormat.getCurrencyInstance(); System.out.println(myLoan.getOverpayment()); System.out.println("The annual interest rate is " +percentFormat.format(rate)); System.out.println("The mortgage amount is: " +currencyFormat.format(amount)); System.out.println("The monthly payment is: " +currencyFormat.format(myLoan.getMPayment())); System.out.println("The total payment over the " +years+ " year span is: " +currencyFormat.format(amount+(myLoan.getOverpayment()))); System.out.println("The total amount of overpayment on the loan is: " +currencyFormat.format(myLoan.getOverpayment())); System.out.println("Therefore, the amount of overpayment is " +percentFormat.format((myLoan.getOverpayment())/amount)+" of the total mortgage amount"); } }

**Any suggestions to what I am doing wrong would be greatly appreciated! Also, this is more basic. We have not made it into any arrays or things like that yet so I will not understand any of those. Thanks!**