Question: Modify the Loan class in Listing 10.2 to throw IllegalArgumentException if the loan amount, interest rate, or number of years is less than or equal
Modify the Loan class in Listing 10.2 to throw IllegalArgumentException if the loan amount, interest rate, or number of years is less than or equal to zero.
Listing


1 public class Loan { 2 private double annualInterestRate; private int number0fYears; 3 private double loanAmount; private java.util.Date loanDate; /** Default constructor */ public Loan() { this(2.5, 1, 1000); 10 11 12 /** Construct a loan with specified annual interest rate, 13 number of years, and loan amount 14 public Loan(double annualInterestRate, int number0fYears, double loanAmount) { this.annualInterestRate = annualInterestRate; this.number0fYears = number0fYears; this.loanAmount = loanAmount; loanDate - new java.util.Date(); 15 16 17 18 19 20 21 22 23 /** Return annualInterestRate */ public double getAnnualInterestRate() { return annualInterestRate; 24 25 26 27 28 /** Set a new annualInterestRate */ public void setAnnualInterestRate(double annualInterestRate) { this. annualInterestRate - annualInterestRate; 29 30 31 32 33 /** Return number0fYears */ public int getNumber0fYears () { return number0fYears; 34 35 36 37 38 /** Set a new numberofYears */ public void setNumberofYears(int numberofYears) { this.number0fYears = numberofYears; 39 40 41 42 43 /** Return loanAmount */ public double getloanAmount () { return loanAmount; 44 45 46 47 48 49 /** Set a new 1loanAmount */ public void setLoanAmount (double loanAmount) { this.loanAmount = loanAmount; 50 51 52 /** Find monthly payment */ public double getMonthlyPayment() { double monthlyInterestRate = annualInterestRate / 1200; double monthlyPayment = loanAmount * monthlyInterestRate / (1 - (1 / Math.pow(1 + monthlyInterestRate, number0fYears * 12))); return monthlyPayment; 53 54 55 56 57 58 59 60 61 /** Find total payment */ public double get TotalPayment () { double totalPayment - getMonthlyPayment () * numberofYears * 12; return totalPayment; 62 63 64 65 66 67 /** Return loan date */ 68 69 public java.util. Date getloanDate() { return loanDate; 70 71 }
Step by Step Solution
3.33 Rating (150 Votes )
There are 3 Steps involved in it
Output javalangIllega1ArgumentExpection Number of years s... View full answer
Get step-by-step solutions from verified subject matter experts
