import java.time.LocalDateTime;
import java.util.Calendar;
import java.util.GregorianCalendar;

public class Book{
    private static HashMap<String, Book> library = new HashMap<String, Book>();

    private String bookTitle;
    private int bookID;
    private long shelfLife = 100000;
    private static int Counter;

    private long start;
    private static long finish = 0;
    private static long totalTimePass = 0;

    public Book(String Title){
        library.put(Title, this);
        this.bookTitle = Title;
        this.start = finish;
        this.bookID = ++Counter; //there is a static int instance called counter under the class Book. Each time the class object is created, counter plus 1;
    };

    public String getTitle(){
        return bookTitle;
    }

    public void setTitle(String newTitle){
        bookTitle = newTitle;
    }

    public int getID(){
        return bookID;
    }

    public long getShelfLife(){
        return shelfLife;
    }

    public long getBookEnter(){
        return start;
    }

    public long getBookExit(){
        return finish;
    }

    public static int getBookCount(){
        return Counter; //return the book count
    }

    public static long getCurrentShelfLife(Book check){
        return check.getShelfLife() - (check.getBookExit() - check.getBookEnter());
    }

    public static boolean isInShelfLife(Book check){
        return ((check.getShelfLife() - (check.getBookExit() - check.getBookEnter())) >= 0);
    }

    public static void borrowBook(String bookTitle){
        library.remove(bookTitle);
    }

    public static void timePass(long timePass){
        totalTimePass += timePass;
        finish = totalTimePass;
    }

    public String toString(){
        return "Book name: " + getTitle() + ", ID: " + getID() + ", current ShelfLife: " + getCurrentShelfLife(this);
    };


    public static void main(String[] args) {
        boolean checkUser = true;
        while(true){
            while (checkUser){
                Scanner scanner = new Scanner(System.in);
                System.out.println("Enter your book into our school library, your book name: ");
                String bookName = scanner.nextLine();
                Book book = new Book(bookName);
                Scanner scanner2 = new Scanner(System.in);
                System.out.println("Want to enter more book? Enter yes or no: ");
                String userChose = scanner2.nextLine();
                if (userChose.equals("yes")){
                    System.out.println("Ok, let's enter more books");
                    System.out.println();
                }
                else{
                    checkUser = false;
                }
            }
            Scanner timeMachine = new Scanner(System.in);
            System.out.println("This is a time machine, how many days do you want to skip ahead? Enter: ");
            long timePass = timeMachine.nextLong();
            timePass(timePass);

            Scanner borrowBook = new Scanner(System.in);
            System.out.println("Ok, now the time has passed, do you want to borrow any books from the library? If yes, enter the book name, if no, type no: ");
            System.out.println();
            String userChose2 = borrowBook.nextLine();

            if(userChose2.equals("no") !=true){
                library.get(userChose2);
                if(isInShelfLife(library.get(userChose2))){
                    System.out.println("The book you chose is: " + userChose2 + ", the remaining shelfLife is :" + getCurrentShelfLife(library.get(userChose2)));
                    System.out.println();
                    borrowBook(userChose2);
                }
                else {
                    System.out.println("The book you chose is already out of shelfLife, and was remove from the library");
                    library.remove(userChose2);
                    System.out.println("The number of books left in the library:" + getBookCount());
                    System.out.println();
                }
            }


            Scanner bookList = new Scanner(System.in);
            System.out.println("Want to check the books in the library? Type yes or no: ");
            String userChose3 = bookList.nextLine();

            if(userChose3.equals("yes")){
                if(library.size() == 0){
                    System.out.println("There is no book store in the library!");
                    System.out.println();
                }
                else{
                    for (Map.Entry entry : library.entrySet()) {
                        System.out.println(entry.getValue());
                    }
                    System.out.println();
                }

            }

            Scanner backToTop = new Scanner(System.in);
            System.out.println("Want to add more books into the library? Type yes or no: ");
            String userChose4 = backToTop.nextLine();

            if (userChose4.equals("yes")){
                System.out.println("Ok, let's enter more books");
                System.out.println();
                checkUser = true;
            }
            else{
                System.out.println();
            }

        }

    }

}

Book.main(null);
Enter your book into our school library, your book name: 
Want to enter more book? Enter yes or no: 
Ok, let's enter more books

Enter your book into our school library, your book name: 
Want to enter more book? Enter yes or no: 
This is a time machine, how many days do you want to skip ahead? Enter: 
Ok, now the time has passed, do you want to borrow any books from the library? If yes, enter the book name, if no, type no: 

The book you chose is: 1, the remaining shelfLife is :99995

Want to check the books in the library? Type yes or no: 
Book name: 2, ID: 10, current ShelfLife: 99995

Want to add more books into the library? Type yes or no: 
Ok, let's enter more books

Enter your book into our school library, your book name: 
Want to enter more book? Enter yes or no: 
This is a time machine, how many days do you want to skip ahead? Enter: 
Ok, now the time has passed, do you want to borrow any books from the library? If yes, enter the book name, if no, type no: 

Want to check the books in the library? Type yes or no: 
Book name: 2, ID: 10, current ShelfLife: 99990
Book name: 3, ID: 11, current ShelfLife: 99995

Want to add more books into the library? Type yes or no: 

This is a time machine, how many days do you want to skip ahead? Enter: 
---------------------------------------------------------------------------
java.util.InputMismatchException: null
	at java.base/java.util.Scanner.throwFor(Scanner.java:939)
	at java.base/java.util.Scanner.next(Scanner.java:1594)
	at java.base/java.util.Scanner.nextLong(Scanner.java:2373)
	at java.base/java.util.Scanner.nextLong(Scanner.java:2328)
	at Book.main(#15:1)
	at .(#22:1)
public class Novel extends Book{
    private String bookAuthor;
    
    public Novel(String author, String Title){
        super(Title);
        this.bookAuthor = author;
    }

    public String getAuthor(){
        return bookAuthor;
    }

    public void setAuthor(String newAuthor){
        bookAuthor = newAuthor;
    }

    public String toString(){
        return super.toString() + ", Author: " + getAuthor();
    };

    public static void main(String[] args) {
        Book[] novel = {new Novel("author1", "titlename1"), new Novel("author2","titlename2")};
        for(Book num : novel){
            System.out.println(num);
            System.out.println("Current shelfLife: " + getCurrentShelfLife(num) + " days");
        }
        System.out.println(getBookCount());
    }

}
Novel.main(null);
Book name: titlename1, ID: 15, Time the book entered the library: 2023/4/21, Author: author1
Current shelfLife: 10 days
Book name: titlename2, ID: 16, Time the book entered the library: 2023/4/21, Author: author2
Current shelfLife: 10 days
17
public class Textbook extends Book{
    private String bookCompany;

    public Textbook(String company, String Title){
        super(Title);
        this.bookCompany = company;
    }

    public String getbookCompany(){
        return bookCompany;
    }

    public void setbookCompany(String newBookCompany){
        bookCompany = newBookCompany;
    }

    public String toString(){
        return super.toString() + ", Company: " + getbookCompany();
    };

    public static void main(String[] args) {
        Book[] textbook = {new Textbook("company1", "titlename1"), new Textbook("company2","titlename2")};
        for(Book num : textbook){
            System.out.println(num);
            System.out.println("Current shelfLife: " + getCurrentShelfLife(num) + " days");
        }
        System.out.println(getBookCount());
    }
}
Textbook.main(null);

// Thread.sleep(4000);
Book name: titlename1, ID: 17, Time the book entered the library: 2023/4/21, Company: company1
Current shelfLife: 10 days
Book name: titlename2, ID: 18, Time the book entered the library: 2023/4/21, Company: company2
Current shelfLife: 10 days
19
Book[] book = {new Book("bookname1"), new Novel("author1", "bookname2"), new Textbook("company1","bookname3")};