Skip to content

Latest commit

 

History

History
63 lines (53 loc) · 1.97 KB

File metadata and controls

63 lines (53 loc) · 1.97 KB

Question

There is a class Book, which has the attributes bookID, title and author. There are two categories of books, TextBooks and ReferenceBooks.
The text books can be borrowed by a user while the reference books cannot be. There is an extra attribute status (default value is Available)
and borrowedUser in the class TextBooks. There is an interface Borrowable which has methods checkIn and checkOut. The class Book implements the Borrowable interface (Think and decide whether class Book is an abstract class or not).

The functionality of the checkIn and checkOut methods in TextBooks class is as follows:
checkIn : should set status attribute as Borrowed and should set the value of borrowedUser.
checkOut : should set status attribute as Available

The functionality of the checkIn and checkOut methods in ReferenceBooks class is as follows:
checkIn : display “Invalid”
checkOut : display “Cannot be borrowed”

Sample Input and Output:

  1. Add Reference Book
  2. Add Text Book
  3. Check-Out
  4. Check-In
  5. List Books
  6. Exit

Enter your choice: 1

Enter ID, Title and Author (Line by line)
101
Data Structures and Algorithms
Cormen

Enter your choice: 2

Enter ID, Title and Author (Line by line)
102
Programming Ruby
Thomas

Enter your choice: 5

ReferenceBook: 101: Data Structures and Algorithms: Cormen
TextBook: 102: Programming Ruby: Thomas: Available

Enter your choice: 3

Enter Book ID: 101
Cannot be borrowed

Enter your choice: 3

Enter Book ID: 102
Enter Username: Ram

Enter your choice: 5

ReferenceBook: 101: Data Structures and Algorithms: Cormen
TextBook: 102: Programming Ruby: Thomas: Borrowed by Ram

Enter your choice: 4

Enter Book ID: 102

Enter your choice: 5

ReferenceBook: 101: Data Structures and Algorithms: Cormen
TextBook: 102: Programming Ruby: Thomas: Available

Enter your choice: 6