Question: Java - Write a test class to test your program with two books, one magazine and one newspaper. Calculate and print the total charge for

Java - Write a test class to test your program with two books, one magazine and one newspaper. Calculate and print the total charge for all items for 100 days each.
In your test class, You should handle WrongNumberOfDaysException (by using try- catch).
 Java - Write a test class to test your program with

1. The purpose of this program is to create a hierarchy of classes for a library system. For this purpose a. Define a new Custom Checked-Exception named wrongNumberofDaysException b. Define an abstract class Libraryitem that has a: . name, ISBN (The number at the back of the book above the bar code), maximumLoanPeriod (number of days) chargePerDay (in Kuwaiti Dinar) as instance variables. Select appropriate data types for these variables. Create appropriate constructor(s) which throws a WrongNumberOfDaysException if given number of days is less than one, accessor and mutator methods as needed. The class works as follows: If a library item is loaned by a user and he returns it back within the maximumLoanPeriod no extra charge is calculated. However, if the item is returned back after the maximumLoanPeriod, a chargePerDay is to be paid by the user based on the number of days exceeding the maximumLoanPeriod. You may define an abstract method . double calculateCharge (int numberOfDays) //Here the numberofDays is the total number of days for which the item was kept. Also include a tostring method that prints the name of the item, the ISBN, the maximum loan period and the charge per day for the item. Now define three subclasses of LibraryItem. c. Book: The chargePerDay is 1.00 KWD and the maximumLoanPeriod is 90 days . Magazine: The chargePerDay is 2.00 KWD and the maximumLoanPeriod is 30 days. The total charge obtained by the method double calculateCharge (int numberOfDays) is fixed to a maximum of 100 KWD o NewsPaper (subclass of Magazine): The total charge obtained by the method double calculateCharge (int numberofDays) is fixed to 10.00 KWD and the maximumLoanPeriod is one day. There is no chargePerDay For each of these classes, implement the calculatecharge method to calculate the correct charge. Also modify the toString ) method to print the type of the library item (e.g Book, Magazine, etc.) and the total charge which is found by invoking calculateCharge (int numberofDays). Provide the code of the equals method for each of the three subclasses

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!