You are going to model a Book in a library. The Book class should contain a title and an author (exactly 1 author is OK). Also, a book can be checked out and returned by a student. A Book object should be able to identify the student who currently holds the book.
1.Design the public interface (public constructor and public methods) for a class Book. You can use String to represent title, author, and student.
2. Implement the class Book (instance variables and constructor+method bodies) from the previous question.
3.Suppose the library also has other items that can be checked out (e.g., DVDs). Thus we introduce a base class for all items that can be checked out.
public class LibraryItem { ... }
and thus Book can inherit from LibraryItem.
public class Book extends LibraryItem { ... }
Which of the methods of Book's public interface would you move to LibraryItem's public interface?
4.
Extend the Book class and implement a method
boolean equals(Object o) { /* YOUR CODE */ }
that tests whether a book has the same title and author than some other Book.
Below are the required classes for the given problem:
LibraryItem.java:
public class LibraryItem {
private String student, returnDate;
private boolean isCheckedOut;
public String getStudent() {
return student;
}
public void setStudent(String student) {
this.student = student;
}
public String getReturnDate() {
return returnDate;
}
public void setReturnDate(String returnDate) {
this.returnDate = returnDate;
}
public boolean isCheckedOut() {
return isCheckedOut;
}
public void setCheckedOut(boolean isCheckedOut) {
this.isCheckedOut = isCheckedOut;
}
}
Book.java:
public class Book extends LibraryItem{
private String title,author;
public Book(String title,String author) {
this.title = title;
this.author = author;
}
public String getTitle() {
return title;
}
public void setTitle(String title) {
this.title = title;
}
public String getAuthor() {
return author;
}
public void setAuthor(String author) {
this.author = author;
}
//equals to find whether a book has the same title and author than some other Book
@Override
public boolean equals(Object obj) {
//if obj is instance of Book then only we can compare the author and title
if(obj instanceof Book) {
Book temp = (Book)obj;
if(this.title.equals(temp.getTitle()) && this.author.equals(temp.getAuthor())){
return true;
}
}
return false;
}
}
You are going to model a Book in a library. The Book class should contain a...
In this assignment you will implement software for your local library. The user of the software will be the librarian, who uses your program to issue library cards, check books out to patrons, check books back in, send out overdue notices, and open and close the library. class Calendar We need to deal with the passage of time, so we need to keep track of Java. Declare this variable as private int date within the class itself, not within any...
You need to program a simple book library system. There are three java classes Book.java // book object class Library.java //library class A2.java //for testing The Book.java class represents book objects which contain the following fields title: a string which represents the book title. author: a string to hold the book author name year: book publication year isbn: a string of 10 numeric numbers. The book class will have also 3 constructors. -The default no argument constructor - A constructor...
Implement the classes in the following class diagram. The Book class implements the Comparable interface. Use implements Comparable<Book> in the class definition. Now, all book objects are instances of the java.lang.Comparable interface. Write a test program that creates an array of ten books. 1. Use Arrays.sort( Book[]l books) from the java.util package to sort the array. The order of objects in the array is determined using compareTo...) method. 2. Write a method that returns the most expensive book in the...
Suppose we have the following book base class: class book { public: book(char *, char *, int); void show_book(); private: char title[64]; char author[64]; int pages; }; Suppose that we need to derive a new class, called libraryCard class, which adds the following members to the book class: char catalog[64]; int checked out; // 1 if checked out, otherwise 0 if available libraryCard(char *, char *, int, char *, int); void show_card(); 1. Derive the new class from the base...
JAVA This PoD, builds off the Book class that you created on Monday (you may copy your previously used code). For today’s problem, you will add a new method to the class called lastName() that will print the last name of the author (you can assume there are only two names in the author name – first and last). You can use the String spilt (“\s”) method that will split the String by the space and will return an array...
C++ program
Suppose we have the following book base class: class book { public: book(char *, char *, int); void show_book(); private: char title[64]; char author[64]; int pages; }; Suppose that we need to derive a new class, called libraryCard class, which adds the following members to the book class: char catalog[64]; int checked out; // 1 if checked out, otherwise 0 if available libraryCard(char *, char *, int, char *, int); void show_card(); 1. Derive the new class from...
Subject: Java Program You are writing a simple library checkout system to be used by a librarian. You will need the following classes: Patron - A patron has a first and last name, can borrow a book, return a book, and keeps track of the books they currently have checked out (an array or ArrayList of books). The first and last names can be updated and retrieved. However, a patron can only have up to 3 books checked out at...
Please use C++
Suppose we have the following book base class: class book { public: book(char*, char *, int); void show_book(); private: char title[64]; char author[64]; int pages; }; Suppose that we need to derive a new class, called libraryCard class, which adds the following members to the book class: char catalog[64]; int checked_out; // 1 if checked out, otherwise 0 if available libraryCard(char*, char *, int, char *, int); void show_card(); 1. Derive the new class from the base...
Create an Item class, which is the abstract super class of all Items. Item class includes an attribute, description of type String for every item. [for eg. Book] A constructor to initialize its data member of Item class. Override toString() method to return details about the Item class. Create the ExtraCharge interface with the following details. Declare a constant RATE with value 0.25 Declare a method called calculateExtraCharge(), which returns a double value. Create the...
Programming language: Java
Design an application that has three classes. The first one, named Book describes book object and has title and number of pages instance variables, constructor to initialize their values, getter methods to get their values, method to String to provide String representation of book object, and method is Long that returns true if book has over 300 pages, and returns false othewise. Provide also method char firstChard) that returns first cahracter of the book's title. The second...