Question: Using Java CODE DOWN BELOW --------------------------------------------------------------------------------------------------------------------------------- public class exam4p1 { public static void main(String[] args) { try { new NewLoan(7.5, 30, -100000); //Run this program

Using Java

Using Java CODE DOWN BELOW --------------------------------------------------------------------------------------------------------------------------------- public class exam4p1 { public staticvoid main(String[] args) { try { new NewLoan(7.5, 30, -100000); //Run thisCODE DOWN BELOW

---------------------------------------------------------------------------------------------------------------------------------

public class exam4p1 { public static void main(String[] args) { try { new NewLoan(7.5, 30, -100000); //Run this program 3 times and comment this line at the 2nd run NewLoan m = new NewLoan(-1, 5, 30000); //comment this line at the 3rd run. new NewLoan(7.5, -30, 20000); } catch //complete the block System.out.println(....); //} System.out.println("End of program"); } } class NewLoan { private double annualInterestRate; private int numOfYears; private double loanAmount; /** Default constructor */ public NewLoan() { this(7.5, 30, 100000); } /** Construct a NewLoan with specified annual interest rate, number of years and loan amount */ public NewLoan(double annualInterestRate, int numOfYears, double loanAmount) { //Complete this constructor setLoanAmount(loanAmount); } public double getAnnualInterestRate() { return annualInterestRate; } /** Set a new annualInterestRate */ public void setAnnualInterestRate(double annualInterestRate) { //Complete this constructor } public int getNumOfYears() { return numOfYears; } /** Set a new numOfYears */ public void setNumOfYears(int numOfYears) { //Complete this constructor } public double getLoanAmount() { return loanAmount; } /** Set a newloanAmount */ public void setLoanAmount(double loanAmount) { if (loanAmount   Problem 1: *12.4 (llegalArgumentException) Modify the Loan class in Listing 10.2 to throw legalArgumentException if the loan amount, interest rate, or number of years is less than or equal to zero. Hirni: 1. Rename the Loan class to MyLoan and modify the constructor to throw the exception if needed as specified. Section 12.3 will be very helpful if you are not sure what to do. 2. In your main method, just use "try...catch..."pair and in the "try" block test your program by creating 3 objects of MyLoan and pass one or two illegal numbers to the constructor. Complete the missing instructions in the program "exam4p1Exercise12_04.java" so that the following output will be generated when it is run 3 times as indicated in the main method: java.lang.IllegalArgumentException: Number of years must be positive. End of program java.lang.IllegalArgumentException: Annualinterest rate must be positive. End of program iava.lang.llegalArgumentException: Loan amount must be positive. End of program 3. iava.lang.llegalArgumentException: Number of years must b

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!