Test
public class Book{
public static int id = 1;
public String bookTitle;
public static int count = 0;
public static ArrayList<Book> library = new ArrayList<Book>();
public Book(String title){
this.bookTitle= title;
count++;
this.startTime= System.nanotime();
library.add(bookTitle);
//define toString method and tester method
}
//generate unique id
public String toString(){
return "book title:" + bookTitle;
}
public static int getBookCount() {
return count;
//public getter that has bookcount
}
public static int getId() {
return id++;
}
public static void main(String[] args){
Book book1 = new Book("suprise test");
Book book2 = new Book("csa");
System.out.println("Id:" + book1.getId() + "" + book1);
System.out.println("Id:" + book2.getId() + "" + book2);
System.out.println("book count:" + Book.getBookCount());
// tester method that initializes 2 books, outputs title, has count of books in library
}
}
Book.main(null);
public class Novel extends Book {
public String author;
public int date;
public Novel(String title, String author){
super(title);
this.author=author;
}
public void setAuthor(String author){
this.author=author;
return;
}
public String getAuthor(){
return this.author;
}
public void printNovel(){
System.out.println(" Id:" + this.id + " Title:" + this.bookTitle + " Author:" + this.author + " Release Date:" + this.date);
// return(super.toString() + this.author )
}
public void setReleaseDate(int date){
this.date=date;
return;
}
public int getReleaseDate(){
return this.date;
}
public static void main(String[] args){
Novel novel1= new Novel("Pride and Prejudice", "your mom");
novel1.setReleaseDate(1929);
novel1.printNovel();
}
}
Novel.main(null);
public class Textbook extends Book {
public String company;
public String subject;
public Textbook(String title, String company){
super(title);
this.company=company;
}
public void setCompany(String company){
this.company=company;
return;
}
public String getCompany(){
return this.company;
}
public void printTextbook(){
System.out.println(" Id:" + this.id + " Title:" + this.bookTitle + " Company:" + this.company + " Subject:" + this.subject);
}
public void setSubject(String subject){
this.subject=subject;
return;
}
public String getSubject(){
return this.subject;
}
public static void main(String[] args){
Textbook textbook1= new Textbook("American Paegent", "DNHS");
textbook1.setSubject("history");
textbook1.printTextbook();
}
}
Textbook.main(null);