Note: This is to lease books to read online. If the question is to buy physical copy
you’ll replace BookLeasing
by BookSell
and add basically follow online shopping strategy.
private String ISBN;
private String title;
private String subject;
private String publisher;
private String language;
private int numberOfPages;
private List<Author> authors;
One unit of a Book is a BookItem.
private String barcode;
private boolean isReferenceOnly;
private Date borrowed;
private Date dueDate;
private double price;
private BookStatus status;
public boolean checkout(String memberId) {...}
public class User {
private String name;
private Address address;
private String email;
private String phone;
}
public abstract class Account {
private String accountId;
private String password;
private AccountStatus status; //Prime, Not a prime,
private User user;
public boolean resetPassword() { ... };
//total number of books that the account current has leased;
public int getTotalBooksCheckedout() {...};
public void setTotalBooksCheckedout() {...};
//account reserving books that are currently out of stock.
public boolean reserveBookItem(BookItem bookItem) {...};
//account reserving books that are currently out of stock.
public boolean returnBookIten(BookItem bookItem) {...};
//account reserving books that are currently out of stock.
public boolean renewBookItem(BookItem bookItem) {...};
//check for fine.
void checkForFine(String bookItemBarcode) { ... }
}
public class BookReservation {
private Date creationDate;
private ReservationStatus status;
private String bookItemBarcode;
private String memberId;
public static BookReservation fetchReservationDetails(String barcode) {...};
}
public class BookLeasing {
private Date creationDate;
private Date dueDate;
private Date returnDate;
private String bookItemBarcode;
private String accountId;
private boolean isAvailable;
// lend the book to a particular accountId
public static void lendBook(String barcode, String accountId) { ... };
public static BookLeasing fetchLeasingDetails(String barcode);
//check if a particular book that is selected is available.
public boolean isBookAvailableForLease(String barcode);
}
This class will be used by the user to search respective books based on title and author or genre.
private HashMap<String, List<Book>> bookTitles;
private HashMap<String, List<Book>> bookAuthors;
private HashMap<String, List<Book>> bookGenre;
private HashMap<String, List<Book>> bookPublicationDates;
public List<Book> searchByTitle(String query) {
// return all books containing the string query in their title.
return bookTitles.get(query);
}
public List<Book> searchByAuthor(String query) {
// return all books containing the string query in their author's name.
return bookAuthors.get(query);
}
public List<Book> searchByGenre(String query) {
// return all books containing the string query in their author's name.
return bookGenre.get(query);
}
//update the catalog for a particular book if it is leased.
public int updateCatalog(Book book) {...};
//notify all the account if a particular book become available.
public List<AccountId> notifyAccounts() { ... };
private Date creationDate;
private double bookItemBarcode;
private String memberId;
public static void collectFine(String accountId, long days) { ... }
public class Payment {
String paymentId;
PaymentMode paymentMode;
PaymentStatus paymentStatus;
boolean makeTransaction() {...}
}
public class Notification {
String notificationId;
NotificationMode notificationMode;
NotificationStatus notificationStatus;
}
we will use enum class for all the Status like PaymentStatus
, NotificationStatus
, BookStatus
etc.