import java.util.*;

public class Book {
    protected static ArrayList<Book> library = new ArrayList<Book>();
    protected int id;
    protected static int bookCount = 0;
    protected String title;
    protected long shelfLife;
    protected long time;
    
    public static String getLibrary() {
        return library.toString();
    }
    public boolean getExpired() {
        boolean expired = this.getTimeLeft() <= 0;
    //     if (expired) {
    //         this.library.remove()
    //     }
        return expired;
    }
    public long getShelfLife() {
        return this.shelfLife;
    }
    public long getTime() {
        return this.time;
    }
    public long getTimeLeft() {
        return this.time + this.shelfLife - System.nanoTime();
    }
    public Book(String title) {
        this.title = title;
        this.id = this.bookCount;
        this.bookCount++;
        this.shelfLife = 0;
    }
    public String toString() {
        return "{title: " + title + "}";
    }
    public static int getBookCount() {
        return bookCount;
    }
    public static void tester() {
        System.out.println("Libary Book Count: " + Book.getBookCount());  // Notice how this method exist and works before any books are created
        Book[] books = {    // Use Array iniitialization to add book
                    new Book("Barron's Computer Science \"A\""),  // Set a new Book object as array element.
                    new Book("Angels and Demons"),
                    new Book("Lion, Witch, and a Wardrobe")
        };
        for (Book book : books) {  // Use Foreach syntax to iterate over array
            System.out.println(book);   // this is same as book.toString()
        }
        System.out.println("Libary Book Count: " + Book.getBookCount());
    }
}
Book.tester();
Libary Book Count: 0
{title: Barron's Computer Science "A"}
{title: Angels and Demons}
{title: Lion, Witch, and a Wardrobe}
Libary Book Count: 3
public class Novel extends Book {
    private String author;
    public void addShelfLife() {
        super.shelfLife += (long)1000000000*10;
    }
    public Novel(String title) {
        super(title);
        this.time = System.nanoTime();
        this.addShelfLife();
        super.library.add(this);
    }
    public String getAuthor() {
        return this.author;
    }
    public void setAuthor(String author) {
        this.author = author;
    }
    public void returnBook() {
        this.addShelfLife();
    }
    public static void testerN() throws InterruptedException{
        Novel novel1 = new Novel("novel1");
        Novel novel2 = new Novel("novel2");
        System.out.println(novel1.toString());
        System.out.println(Novel.getBookCount());
        novel1.setAuthor("me");
        System.out.println(novel1.getAuthor());
        System.out.println(novel1.getShelfLife());
        System.out.println(novel1.getTime());
        System.out.println(novel1.getTimeLeft());
        System.out.println(novel1.getExpired());
        Thread.sleep(5000);
        System.out.println(novel1.getTimeLeft());
        System.out.println(novel1.getExpired());
        novel2.returnBook();
        Thread.sleep(5500);
        System.out.println(novel1.getTimeLeft());
        System.out.println(novel1.getExpired());
        System.out.println(novel2.getTimeLeft());
        System.out.println(novel2.getExpired());
        System.out.println(Novel.getLibrary());
    }
}
Novel.testerN();
{title: novel1}
5
me
10000000000
32817596657688
9993062450
false
4990939661
false
-512375623
true
9484054638
false
[{title: novel1}, {title: novel2}]
public class Textbook extends Book {
    private String publishingCompany;
    public void addShelfLife() {
        super.shelfLife += (long)1000000000*10;
    }
    public Textbook(String title) {
        super(title);
        this.time = System.nanoTime();
        this.addShelfLife();
        super.library.add(this);
    }
    public String getPublishingCompany() {
        return this.publishingCompany;
    }
    public void setPublishingCompany(String publishingCompany) {
        this.publishingCompany = publishingCompany;
    }
    public static void testerT() throws InterruptedException {
        Novel tb1 = new Novel("tb1");
        Novel tb2 = new Novel("tb2");
        System.out.println(tb1.toString());
        System.out.println(tb1.getBookCount());
        tb1.setAuthor("me");
        System.out.println(tb1.getAuthor());
        System.out.println(tb1.getShelfLife());
        System.out.println(tb1.getTime());
        System.out.println(tb1.getTimeLeft());
        System.out.println(tb1.getExpired());
        Thread.sleep(5000);
        System.out.println(tb1.getTimeLeft());
        System.out.println(tb1.getExpired());
        Thread.sleep(5500);
        System.out.println(tb1.getTimeLeft());
        System.out.println(tb1.getExpired());
        System.out.println(Novel.getLibrary());
    }
}
Textbook.testerT();
{title: tb1}
7
me
10000000000
32850670176550
9996827872
false
4995532203
false
-507085905
true
[{title: novel1}, {title: novel2}, {title: tb1}, {title: tb2}]