134k views
1 vote
An online library application needs to be created for two types of users/roles-Adults and children. Both of these users should be able to register an account. Any user who is less than 12 years of age will be registered as a child and they can borrow a "Kids" category book for 10 days, whereas an adult can borrow "Fiction" category books which need to be returned within 7 days. Note: In future, more users/roles might be added to the library where similar rules will be enforced. Develop Interfaces and classes for the categories mentioned above. 1. Create an interface LibraryUser. with the following methods void registerAccount() void cequestiook 2. Create 2 classes "Kidusers" and "Adultuser" which implements the LibraryUser. interface. 3. Both the classes should have two instance variables - age(int), bookJype(String) 4. The methods in the Kiduser class should perform the following logic. register Account(): if age <12, a message displaying "You have successfully registered under a Kids Account" should be displayed in the console.

User Nyzm
by
7.6k points

1 Answer

4 votes

Final answer:

An interface called LibraryUser is created with methods for account registration and book requests. Classes KidUsers and AdultUser implement this interface and contain logic based on user age for book borrowing privileges.

Step-by-step explanation:

Creating Library User Interfaces and Classes

To create an online library application that caters to both adults and children, we start with an interface called LibraryUser. This interface will declare two methods: void registerAccount() and void requestBook(). Subsequently, two classes named KidUsers and AdultUser will implement the LibraryUser interface. Both classes will have two instance variables: age (of type int) and bookType (of type String).

In the KidUser class, the registerAccount method will check if the age is less than 12. If true, it will display the message "You have successfully registered under a Kids Account" to the console. The requestBook method in this class will allow users to borrow books from the "Kids" category for a period of 10 days. In contrast, the AdultUser class will cater to users above the age of 12, allowing them to borrow "Fiction" category books to be returned within 7 days.

This approach makes the application scalable for future additions of new user roles, where similar rules can be enforced through additional classes that implement the LibraryUser interface.

User Bnicholas
by
8.1k points

No related questions found