Surprise Test
Surprise Testing after Cancode messed up
import java.util.ArrayList; // import the ArrayList class
import java.util.Date;
public class Book {
private int id;
private String title;
static int count = 0;
private int yearmade;
public Book(int id, String title, int yearmade) {
this.id = id;
this.title = title;
count++;
this.yearmade = yearmade;
}
public int getYear() {
return yearmade;
}
public void BooktoString() {
System.out.println("The title of the book is " + this.title);
}
public static int getCount() {
return count;
}
public static int checkouts() {
return count/20;
}
public static void main(String[] args) {
ArrayList<Book> books = new ArrayList<Book>(); // Create an ArrayList object
Book book1 = new Book(3, "Harry Potter and the Prisoner of Azkaban", 2019);
Book book2 = new Book(2, "Harry Potter and the Chamber of Secrets", 2020);
books.add(book1);
books.add(book2);
book1.BooktoString();
book2.BooktoString();
System.out.println("the num of books is " + Book.getCount());
}
}
Book.main(null);
public class Novel extends Book {
private String author;
private int i;
public Novel(int id, String title, int yearmade){
super(id, title, yearmade);
}
public void setAuthor(String newauthor) {
this.author = newAuthor;
}
public String getAuthor() {
return author;
}
public int shelflifeNovel() {
z = 2040 - this.getYear();
return z - z * this.checkouts();
}
public static void main(String[] args) {
Novel novel1 = new Novel(1, "Don Quixote", 2020);
int a = novel1.shelflife();
System.out.println("The shelf life of the novel is " + a);
}
}
Novel.main(null);
public class Textbook extends Book {
private String company;
private int i;
public Textbook(int id, String title, int yearmade){
super(id, title, yearmade);
}
public int shelflifeTextbook() {
return 2040 - this.getYear();
}
public static void main(String[] args) {
Textbook textbook1 = new Textbook(1, "McGrawHill", 2020);
int a = textbook1.shelflifeTextbook();
System.out.println("The shelf life of the textbook is " + a);
}
}
Textbook.main(null);