import java.util.Random;
import java.lang.Thread;
public class Book{

    private String titlle;
    private int bookId;
    private static int BookCounter = 0;
    private long startTime;

    public Book(String title){
        titlle = title;
        BookCounter++;
        uniqueBookId();
        startTime = System.nanoTime();
    }

    public String toString(){
        return "Booktitle: " + titlle + " Id: " + bookId + " Super: " + super.toString();
    }

    public void testBook(){
        System.out.println(this);
    }

    private int uniqueBookId(){
        Random randid = new Random();
        bookId = randid.nextInt(9999);
        return bookId;
    }

    public static int getBookCount(){
        return BookCounter;
    }
   
    public long getshelfLife()
    {
        return System.nanoTime() - startTime; // difference from start to current
    }

    public static void main(String[] args){
       
        System.out.println("Bookcount: " + Book.getBookCount());

        Book book1 = new Book("Book1");
        Book book2 = new Book("Book2");

        System.out.println(book1);
        System.out.println(book2);

        System.out.println("Bookcount: " + Book.getBookCount());
        
        // testing for book 1
        try{
            Thread.sleep(5000); // milliseconds
            System.out.println("Book1 shelflife: " + book1.getshelfLife());
        }
        catch (Exception e) {
           
            // catching the exception if there is an interruption
            System.out.println(e);
        }

        Book[] bookss = {    // 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 : bookss) {  // for each syntax to iterate over array
             System.out.println(book);   // same as book.toString()
        }

        System.out.println("Libary Book Count: " + Book.getBookCount());


        //------------------------------------------------------------------------------
        String [][] books = {
            { "e=MC^2 a Biography",
              "Pan Books (January 1, 2001)"},                        // row 0

            { "The Practice of Programming",
              "Addison-Wesley Professional Computing" }              // row 1
        };

        TextBook[] txtbooks= new TextBook[books.length];
       
        for (int k =0; k<books.length; k++)
        {
            txtbooks[k] = new TextBook(books[k][0]);
            txtbooks[k].setPublisher(books[k][1]);

            try{
            Thread.sleep(5000);
            System.out.println("------Textbook------");
            System.out.println(txtbooks[k]);
            System.out.println("Publisher : " + txtbooks[k].getPublisher());
            System.out.println("shelflife textbook: " + txtbooks[k].getshelfLife());
            System.out.println("textbook expires: " + txtbooks[k].shelfLifeExpiry()); // only for textbook
            }
            catch (Exception e) {
               
                // catching the exception
                System.out.println(e);
            }
        }
       
       
        //---------------------------------------------------------------------------------------
       
        String [][] novelbooks = {
            { "novel1 ",
              "authorofnovel1"},                        // row 0
 
            { "novel2",
              "authorofnovel2" }              // row 1
        };
       
        Novel[] novbooks= new Novel[novelbooks.length] ;;
       
        for (int k =0; k<novelbooks.length; k++)
        {
            novbooks[k] = new Novel(novelbooks[k][0]);
            novbooks[k].setAuthor(novelbooks[k][1]);
        }
       
       
        for (int i =0; i<novbooks.length; i++)
        {
            System.out.println("------Novel------");
            System.out.println(novbooks[i]);
            System.out.println("Author: " + novbooks[i].getAuthor());
            System.out.println("Expiry: " + novbooks[i].shelfLifeExpiry(4));
        }

    }
}

Book.main(null);
Bookcount: 0
Booktitle: Book1 Id: 8027 Super: REPL.$JShell$16G$Book@1b2e4e9a
Booktitle: Book2 Id: 786 Super: REPL.$JShell$16G$Book@fa73688
Bookcount: 2
Book1 shelflife: 5007731458
Booktitle: Barron's Computer Science "A" Id: 2653 Super: REPL.$JShell$16G$Book@63bb21ee
Booktitle: Angels and Demons Id: 7505 Super: REPL.$JShell$16G$Book@6001dfbf
Booktitle: Lion, Witch, and a Wardrobe Id: 1971 Super: REPL.$JShell$16G$Book@517350c8
Libary Book Count: 5
------Textbook------
Booktitle: e=MC^2 a Biography Id: 9039 Super: REPL.$JShell$13D$TextBook@33ca166e
Publisher : Pan Books (January 1, 2001)
shelflife textbook: 5006280250
textbook expires: true
------Textbook------
Booktitle: The Practice of Programming Id: 5674 Super: REPL.$JShell$13D$TextBook@7874f5cf
Publisher : Addison-Wesley Professional Computing
shelflife textbook: 5007632667
textbook expires: true
------Novel------
Booktitle: novel1  Id: 5397 Super: REPL.$JShell$12D$Novel@2e0c3b36
Author: authorofnovel1
Expiry: true
------Novel------
Booktitle: novel2 Id: 6802 Super: REPL.$JShell$12D$Novel@357dea04
Author: authorofnovel2
Expiry: true
public class Novel extends Book{

    private String author;
    private final int SHELFLIFEEXPIRY = 3;

    public Novel(String title){
        super(title);
    }

    public void setAuthor(String authorName){
        author = authorName;
    }

    public String getAuthor(){
        return author;
    }

    public boolean shelfLifeExpiry(int returnstamp){
        if (returnstamp < SHELFLIFEEXPIRY){
            return false;
        }
        return true;
    }
}
public class TextBook extends Book{

    private String publishingcomp;
    private final long SHELFLIFEEXPIRY = 3000;


    public TextBook(String title){
        super(title);
        
    }

    public void setPublisher(String publisher){
        publishingcomp = publisher;
    }

    public String getPublisher(){
        return publishingcomp;
    }
    
    public boolean shelfLifeExpiry(){
        if (getshelfLife() < SHELFLIFEEXPIRY){
            return false; // returns that it is not expired
        }
        return true;
    }
    

}