Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

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).
image text in transcribed
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

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

More Books

Students also viewed these Databases questions

Question

Give an example of each form.

Answered: 1 week ago

Question

1. Discuss the four components of language.

Answered: 1 week ago

Question

f. What stereotypes were reinforced in the commercials?

Answered: 1 week ago