Modify the Loan class in Listing 10.2 to throw IllegalArgumentException if the loan amount, interest rate, or
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 to zero.
Listing
Transcribed Image Text:
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 }
Fantastic news! We've Found the answer you've been seeking!
Step by Step Answer:
Answer rating: 76% (13 reviews)
Output javalangIllega1ArgumentExpection Number of years s...View the full answer
Answered By
Jehal Shah
I believe everyone should try to be strong at logic and have good reading habit. Because If you possess these two skills, no matter what difficult situation is, you will definitely find a perfect solution out of it. While logical ability gives you to understand complex problems and concepts quite easily, reading habit gives you an open mind and holistic approach to see much bigger picture.
So guys, I always try to explain any concept keeping these two points in my mind. So that you will never forget any more importantly get bored.
Last but not the least, I am finance enthusiast. Big fan of Warren buffet for long term focus investing approach. On the same side derivatives is the segment I possess expertise.
If you have any finacne related doubt, do reach me out.
5.00+
1+ Reviews
10+ Question Solved
Related Book For
Introduction to Java Programming, Comprehensive Version
ISBN: 978-0133761313
10th Edition
Authors: Y. Daniel Liang
Question Posted:
Students also viewed these Computer science questions
-
Rewrite the Course class in Listing 10.6 to add a clone method to perform a deep copy on the students field. Listing 1 public class Course { private String courseName; private String[] students = new...
-
The Loan class in Listing 10.2 does not implement Serializable. Rewrite the Loan class to implement Serializable. Write a program that creates five Loan objects and stores them in a file named...
-
Suppose a file named Exercise17_07.dat has been created using the ObjectOutputStream. The file contains Loan objects. The Loan class in Listing 10.2 does not implement Serializable. Rewrite the Loan...
-
An investment project has annual cash inflows of $3,200, $4,100, $5,300, and $4,500, and a discount rate of 14 percent. What is the discounted payback period for these cash flows if the initial cost...
-
Compute the determinants of the elementary matrices given in Exercises 1-2. (See Section 2.2.) 1. 2. 010 10k
-
Which of the following would not be an example of metadata found in a database catalog? a. Values in a primary key field b. Table and view names c. Relationship descriptions d. Index definitions
-
When conducting an incremental analysis, what step must always be taken immediately prior to beginning the pairwise comparisons? a. Order the alternatives from highest to lowest initial investment b....
-
Auditing standards require the auditor to obtain an understanding of the entity and its environment as a basis for assessing the risks of material misstatements. Business models differ across...
-
Discuss the breath of responsibilities required of a radiographer. List the five main areas of responsibility in each specialty of radiologic technology. Discuss advantages to working in each of the...
-
A store maintains data on customers, products and purchase records in three tables: CUSTOMER, PRODUCT, PURCHASE. The store manager wants to know which product is on its maximum discount for each...
-
Programming Exercise 11.1 defined the Triangle class with three sides. In a triangle, the sum of any two sides is greater than the other side. The Triangle class must adhere to this rule. Create the...
-
Write a program that meets the following requirements: Creates an array with 100 randomly chosen integers. Prompts the user to enter the index of the array, then displays the corresponding element...
-
Suppose that I = c = 4 for the I controller with internal feedback shown in Figure 10.6.6. The performance specifications require that = 0.2. (a) Compute the required gain values for each of the...
-
The following information relates to four assets held by the company: A $m Carrying amount 120 Value in use 80 Fair value less costs to sell 90 What is the recoverable amount of each asset? Calculate...
-
What difference does it make to the poem's meaning that "Umpaowastewin" by Margaret Noodin is also in Anishinaabemowin? What does it have to do with making jam? Explain
-
The fastest man-made object is the parker solar probe, itsmaximum speed record is 430,000 mph. It the probe maintained thatspeed for a year (it wont), how much time does it lose compared toan...
-
5 The Evan ec Company's D = 2.62 } its (an be sold to net $28 next expected dividend growth rate is 7% and its Common stock now sells for 35 New stock per share of retained a) what is Evanec's cost...
-
A corporation purchases several new 5- and 7-year class personal property items throughout the current year. If the corporation wishes to take the maximum Code Sec. 179 deduction for the current...
-
Assume that Tesla decides to launch a new website to market discount bookkeeping services to consumers. This chain, named Aladin, requires $500,000 of start-up capital. The founder contributes...
-
A report from the college dean indicates that for the previous semester, the grade distribution for the Department of Psychology included 135 As, 158 Bs, 140 Cs, 94 Ds, and 53 Fs. Determine what kind...
-
A recursive method is a method that _________________. a. Contains no loops b. Is executed at least twice during program execution c. Calls itself d. Calls no other methods
-
Figure 12-20 earlier in this chapter shows the output of a program that displays any number of Os running diagonally from top left to bottom right. Now, write a program that prompts the user for a...
-
Write a program that prompts the user for two integers. Pass them to a recursive method that returns the product of the two integers without using multiplication. In other words, instead of using the...
-
(Warm-up) The mechanism for the reaction you'll perform in Lab B involves one or more carbocation rearrangement(s). Examine the carbocation rearrangement below. Provide an arrow pushing mechanism for...
-
Kaman Company purchased a building and land with a fair value of $650,000 (building, $400,000 and land, $250,000) on January 1, 2025. Kaman Company signed a 20-year, 8% mortgage payable. Kaman...
-
to questi A container has a large cylindrical lower part with a long thin cylindrical neck open at the top. The lower part of the container holds 16.8 m of water and the surface area of the bottom of...
Study smarter with the SolutionInn App