Question: Below code is what I have done so far. Please help me. public class Loan implements Serializable { private double annualInterestRate; private int numberOfYears; private

 Below code is what I have done so far. Please help

Below code is what I have done so far. Please help me.

public class Loan implements Serializable { private double annualInterestRate; private int numberOfYears; private double loanAmount; private int loanID; private java.util.Date loanDate;

/** Default constructor */ public Loan() { this(-1, 2.5, 1, 1000); }

// Construct a loan with specified annual interest rate, number of years and loan amount public Loan(int loanID, double annualInterestRate, int numberOfYears, double loanAmount ) { this.loanID = loanID; this.annualInterestRate = annualInterestRate; this.numberOfYears = numberOfYears; this.loanAmount = loanAmount; loanDate = new java.util.Date(); }

private Loan(int i, double d, int i0, int i1) { throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates. }

//Return loanID public int getLoanID(){ return loanID; } //set a new loanId public void setLoanID(int loanID){ this.loanID = loanID; } // Return annualInterestRate public double getAnnualInterestRate() { return annualInterestRate; }

// Set a new annualInterestRate public void setAnnualInterestRate(double annualInterestRate) { if(annualInterestRate

//Return numberOfYears public int getNumberOfYears() { return numberOfYears; }

// Set a new numberOfYears public void setNumberOfYears(int numberOfYears) { if(numberOfYears

// Return loanAmount public double getLoanAmount() { return loanAmount; }

// Set a newloanAmount public void setLoanAmount(double loanAmount) { if(loanAmount

//Find monthly payment public double getMonthlyPayment() { double monthlyInterestRate = annualInterestRate / 1200; double monthlyPayment = loanAmount * monthlyInterestRate / (1 - (Math.pow(1 / (1 + monthlyInterestRate), numberOfYears * 12))); return monthlyPayment; }

// Find total payment public double getTotalPayment() { double totalPayment = getMonthlyPayment() * numberOfYears * 12; return totalPayment; }

// Return loan date public java.util.Date getLoanDate() { return loanDate; } @Override public String toString(){ } public static void main(String [] argv) { Loan loan1 = new Loan(); Loan loan2 = new Loan(123,7.5,30,100000); Loan loan3 = new Loan(222,5.5,40,0); System.out.println(loan1); System.out.println(loan2); System.out.println(loan3); ArrayList al = new ArrayList(Arrays.asList(loan1,loan2,loan3)); Collections.sort(al); System.out.print(al); } }

1) fix the method that if you handed it in unmodified I'd ding you! 2) modify the appropriate setters to check that the loan amount, interest rate, and number of years are each greater than zero. Add a property called error set to true if any of these are zero or less, but still store any erroneous data in its associated property. Your getMonthlyPayment() method should return 0 if error is set. Output the appropriate one of the following messages if erroneous data is encountered: Error: Annual interest rate must be greater than zero!" Error: Number of years must be greater than zero!" "Error: Loa n amount must be greater than zero! 1 3) add new loanlD property (int) and associated getters and setters and a default value of -1. Update the constructor(s) to take the loanlD as the first formal parameter 4) override the toString method to output a loan record as follows: LoanlD: 123 Annual Interest rate: 7.50% Term: 30 Loan Amount: $100000.00 Monthly Payment: $699.21 Origination Date: Thu Nov 01 12:34:39 PDT 2018 5) make your class Serializeable and Comparable (based on monthly payment) 6) add the main method below to test your class. You should get the output below when you run the main. public static void main String I argv) i Loan loan 1 = new Loan(); Loan loan2 - new Loan 123,7.5,30,100000) Loan loan3 new Loan 222,5.5,40,0); System.out.printin(loan1): System.out.printInfloan2); System.out.printin(loan3); ArrayList al- new ArrayList(Arrays.asList loan1,loan2,loan3): Collections.sort(al) System.out.print(al)

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!