Part 1

import java.util.*;

public class Book {
    // argument constructor title?
    public String title;

    // unique id
    public String id;
    private static long idCounter = 0;

    // book count
    public static int bookCount;

    public Book (){
        this.title = null;
    }

    public Book (String title){
        this.title = title;
        this.id = createID();
    }
    
    public static synchronized String createID() {
        return String.valueOf(idCounter++);
    }

    public String toString() {
        return("Book Title: "+title+" \nBook ID: "+id+"\n");
    }

}

class Novel extends Book {
    public Novel (String title){
        this.title = title;
        this.id = createID();
    }
}

class Textbook extends Book {
    public Textbook (String title){
        this.title = title;
        this.id = createID();
    }
}

// driver class
public class Tester 
{
    public static void main(String args[]) 
    {
            Book first = new Book("Coding Stuff");
            Novel second = new Novel("Fiction");
            Textbook third = new Textbook("Nonfiction");

            Book[] books = {    // Use Array initialization to add book
                new Book("Barron's Computer Science"),  // 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()
           }

            Book.bookCount = books.length;

            System.out.println("Library Book Count: " + Book.bookCount);
        
    }
}
Tester.main(null);
Book Title: Barron's Computer Science 
Book ID: 3

Book Title: Angels and Demons 
Book ID: 4

Book Title: Lion, Witch, and a Wardrobe 
Book ID: 5

Library Book Count: 3

Part 2

import java.util.*;

public class Book {
    // argument constructor title?
    public String title;

    // unique id
    public String id;
    private static long idCounter = 0;

    // book count
    public static int bookCount;

    // shelf life
    public static int shelfLife;

    // age that determines shelf life
    public static int age;

    // # of checkouts
    public int checkouts;

    private static ArrayList<Book> library = new ArrayList<Book>();  // Library as static ArrayList
    public static final long YEAR = 1000;  // year in milliseconds, final as it does not change


    public Book (){
        this.title = null;
    }

    public Book (String title){
        this.title = title;
        this.id = createID();
        Book.library.add(this);  // library size used to set
        this.shelfLife = 0;
    }
    
    public static synchronized String createID() {
        return String.valueOf(idCounter++);
    }

    public String toString() {
        return("Book Title: "+title+" \nBook ID: "+id+" \nBook Shelf Life: "+shelfLife);
    }

    // checking whether its still fit to be on shelves
    public static boolean checkShelfLife() {
        if (shelfLife < 50) {
            return false; // book's shelf life is expired
        } else {
            return true; // book is still fine
        }
    }

    public static int ageShelfLife() {
        if (shelfLife > 50) {
            shelfLife -= 20;
        }
        return (shelfLife);
    }

    /* size is used as unique id, deletes can't occur in this implementation */
    public static int getBookCount() { // Part 1.4, Create a public getter that has Book Count
        return Book.library.size();
    }

    public static List<Book> getLibrary() {
        return Collections.unmodifiableList(Book.library);  // ArrayList should not be changed outside of this Book class
    }

    /* prints "active" books in library */
    public static void printLibrary() {
        // Here are save books, but where could this process go if I want a library of books across subclasses
        System.out.println("Active books");   
        for (Book book: Book.library) {
            if (book.checkShelfLife())  // Active book check
                System.out.println(book+"\n");
        }
    }

}

class Novel extends Book {
    
    public String author;
    
    public Novel (String title){
        super(title);
        this.id = createID();
    }

    public Novel (String title, String author, int checkouts){
        super(title);
        this.id = createID();
        this.author = author;
        this.checkouts = checkouts;
    }

    @Override
    public String toString() {
        return (super.toString()+
                "\nAuthor: "+author);
    }

    public int checkLife() {
        shelfLife = 250 - (checkouts * 2);
        return (shelfLife);
    }

}

class Textbook extends Book {
    
    public String publisher;

    public Textbook (String title){
        super(title);
        this.id = createID();
    }

    public Textbook (String title, String publisher, int age){
        super(title);
        this.id = createID();
        this.publisher = publisher;
        this.age = age;
    }

    @Override
    public String toString() {     
        return (super.toString()+
                "\nPublisher: "+publisher);
    }

    public int checkLife() {
        shelfLife = 200 - (age * 3);
        return (shelfLife);
    }

}

// driver class
public class Tester 
{
    public static void main(String args[]) 
    {
            Book first = new Book("Coding Stuff");
            Novel second = new Novel("Fiction", "Higgins", 77);
            Textbook third = new Textbook("Nonfiction", "Willoughby", 39);

            System.out.println("Library Book Count: " + Book.getBookCount());  // Notice how this method exist and works before any books are created
            
            // This shows intializing Book Array with new Book objects
            Book[] books = {    // Uses an Array to store the creation of 3 books
                new Book("Barron's Computer Science \"A\""),  // Set a new Book object as array element.
                new Book("Angels and Demons")
            };

            Novel[] novels = {    // Same technique as in Book tester
                new Novel("The Da Vinci Code", "Dan Brown", 63),
                new Novel("Pride and Prejudice", "Jane Austen", 44)
            };

            String [][] bookss = {
                { "e=MC^2 a Biography",
                  "Pan Books"},                        // row 0
      
                { "The Practice of Programming",
                  "Addison-Wesley Professional Computing" }              // row 1
            };

            // Iterates through new Book objects
            for (Book book : books) {  // Use Foreach syntax to iterate over array
                System.out.println(book);   // this is same as book.toString()
            }
            
            System.out.println("Library Book Count: " + Book.getBookCount()+"\n");

            System.out.println(first.toString()+"\n");

            System.out.println(second.toString());
            System.out.println("Shelf Life: "+second.checkLife());
            System.out.println("It stay come on the shelf: "+second.checkShelfLife()+"\n");

            System.out.println(third.toString());
            System.out.println("Shelf Life: "+third.checkLife());
            System.out.println("It stay come on the shelf: "+third.checkShelfLife()+"\n");        
    }
}
Tester.main(null);
Library Book Count: 3
Book Title: Barron's Computer Science "A" 
Book ID: 5 
Book Shelf Life: 0
Book Title: Angels and Demons 
Book ID: 6 
Book Shelf Life: 0
Library Book Count: 7

Book Title: Coding Stuff 
Book ID: 0 
Book Shelf Life: 0

Book Title: Fiction 
Book ID: 2 
Book Shelf Life: 0
Author: Higgins
Shelf Life: 96
It stay come on the shelf: true

Book Title: Nonfiction 
Book ID: 4 
Book Shelf Life: 96
Publisher: Willoughby
Shelf Life: 83
It stay come on the shelf: true

Part 3

// Library Simulation
public class LibraryManager
{
    // Part 3.1, Build a Tester Method that does a Simulation.
    public static void main(String[] args) throws InterruptedException {  
        int years = 5; // Simulation years
        Novel second = new Novel("Fiction", "Higgins", 77);
        Textbook third = new Textbook("Nonfiction", "Willoughby", 39);
        // Sleep in loop creates delay for simulation
        for (int i = 0; i < years; i++) {
            System.out.println("Year: " + i);
            Book.printLibrary();
            System.out.println();
            Thread.sleep(Book.YEAR);  // Part 3.4, Use a sleep in Java to assist with simulation
            // Loop through books in Library
            for (Book book : Book.getLibrary()) {
                if (book instanceof Novel){
                    second.checkLife();
                    book.ageShelfLife(); 
                } else if (book instanceof Textbook) {
                    third.checkLife();
                    book.ageShelfLife(); 
                } else {
                    book.ageShelfLife(); 
                }
            }
        }
        
    }
}
LibraryManager.main(null);
Year: 0
Active books
Book Title: Coding Stuff 
Book ID: 0 
Book Shelf Life: 63

Book Title: Fiction 
Book ID: 2 
Book Shelf Life: 63
Author: Higgins

Book Title: Nonfiction 
Book ID: 4 
Book Shelf Life: 63
Publisher: Willoughby

Book Title: Barron's Computer Science "A" 
Book ID: 5 
Book Shelf Life: 63

Book Title: Angels and Demons 
Book ID: 6 
Book Shelf Life: 63

Book Title: The Da Vinci Code 
Book ID: 8 
Book Shelf Life: 63
Author: Dan Brown

Book Title: Pride and Prejudice 
Book ID: 10 
Book Shelf Life: 63
Author: Jane Austen

Book Title: Fiction 
Book ID: 12 
Book Shelf Life: 63
Author: Higgins

Book Title: Nonfiction 
Book ID: 14 
Book Shelf Life: 63
Publisher: Willoughby

Book Title: Fiction 
Book ID: 16 
Book Shelf Life: 63
Author: Higgins

Book Title: Nonfiction 
Book ID: 18 
Book Shelf Life: 63
Publisher: Willoughby

Book Title: Fiction 
Book ID: 20 
Book Shelf Life: 63
Author: Higgins

Book Title: Nonfiction 
Book ID: 22 
Book Shelf Life: 63
Publisher: Willoughby

Book Title: Fiction 
Book ID: 24 
Book Shelf Life: 63
Author: Higgins

Book Title: Nonfiction 
Book ID: 26 
Book Shelf Life: 63
Publisher: Willoughby


Year: 1
Active books
Book Title: Coding Stuff 
Book ID: 0 
Book Shelf Life: 63

Book Title: Fiction 
Book ID: 2 
Book Shelf Life: 63
Author: Higgins

Book Title: Nonfiction 
Book ID: 4 
Book Shelf Life: 63
Publisher: Willoughby

Book Title: Barron's Computer Science "A" 
Book ID: 5 
Book Shelf Life: 63

Book Title: Angels and Demons 
Book ID: 6 
Book Shelf Life: 63

Book Title: The Da Vinci Code 
Book ID: 8 
Book Shelf Life: 63
Author: Dan Brown

Book Title: Pride and Prejudice 
Book ID: 10 
Book Shelf Life: 63
Author: Jane Austen

Book Title: Fiction 
Book ID: 12 
Book Shelf Life: 63
Author: Higgins

Book Title: Nonfiction 
Book ID: 14 
Book Shelf Life: 63
Publisher: Willoughby

Book Title: Fiction 
Book ID: 16 
Book Shelf Life: 63
Author: Higgins

Book Title: Nonfiction 
Book ID: 18 
Book Shelf Life: 63
Publisher: Willoughby

Book Title: Fiction 
Book ID: 20 
Book Shelf Life: 63
Author: Higgins

Book Title: Nonfiction 
Book ID: 22 
Book Shelf Life: 63
Publisher: Willoughby

Book Title: Fiction 
Book ID: 24 
Book Shelf Life: 63
Author: Higgins

Book Title: Nonfiction 
Book ID: 26 
Book Shelf Life: 63
Publisher: Willoughby


Year: 2
Active books
Book Title: Coding Stuff 
Book ID: 0 
Book Shelf Life: 63

Book Title: Fiction 
Book ID: 2 
Book Shelf Life: 63
Author: Higgins

Book Title: Nonfiction 
Book ID: 4 
Book Shelf Life: 63
Publisher: Willoughby

Book Title: Barron's Computer Science "A" 
Book ID: 5 
Book Shelf Life: 63

Book Title: Angels and Demons 
Book ID: 6 
Book Shelf Life: 63

Book Title: The Da Vinci Code 
Book ID: 8 
Book Shelf Life: 63
Author: Dan Brown

Book Title: Pride and Prejudice 
Book ID: 10 
Book Shelf Life: 63
Author: Jane Austen

Book Title: Fiction 
Book ID: 12 
Book Shelf Life: 63
Author: Higgins

Book Title: Nonfiction 
Book ID: 14 
Book Shelf Life: 63
Publisher: Willoughby

Book Title: Fiction 
Book ID: 16 
Book Shelf Life: 63
Author: Higgins

Book Title: Nonfiction 
Book ID: 18 
Book Shelf Life: 63
Publisher: Willoughby

Book Title: Fiction 
Book ID: 20 
Book Shelf Life: 63
Author: Higgins

Book Title: Nonfiction 
Book ID: 22 
Book Shelf Life: 63
Publisher: Willoughby

Book Title: Fiction 
Book ID: 24 
Book Shelf Life: 63
Author: Higgins

Book Title: Nonfiction 
Book ID: 26 
Book Shelf Life: 63
Publisher: Willoughby


Year: 3
Active books
Book Title: Coding Stuff 
Book ID: 0 
Book Shelf Life: 63

Book Title: Fiction 
Book ID: 2 
Book Shelf Life: 63
Author: Higgins

Book Title: Nonfiction 
Book ID: 4 
Book Shelf Life: 63
Publisher: Willoughby

Book Title: Barron's Computer Science "A" 
Book ID: 5 
Book Shelf Life: 63

Book Title: Angels and Demons 
Book ID: 6 
Book Shelf Life: 63

Book Title: The Da Vinci Code 
Book ID: 8 
Book Shelf Life: 63
Author: Dan Brown

Book Title: Pride and Prejudice 
Book ID: 10 
Book Shelf Life: 63
Author: Jane Austen

Book Title: Fiction 
Book ID: 12 
Book Shelf Life: 63
Author: Higgins

Book Title: Nonfiction 
Book ID: 14 
Book Shelf Life: 63
Publisher: Willoughby

Book Title: Fiction 
Book ID: 16 
Book Shelf Life: 63
Author: Higgins

Book Title: Nonfiction 
Book ID: 18 
Book Shelf Life: 63
Publisher: Willoughby

Book Title: Fiction 
Book ID: 20 
Book Shelf Life: 63
Author: Higgins

Book Title: Nonfiction 
Book ID: 22 
Book Shelf Life: 63
Publisher: Willoughby

Book Title: Fiction 
Book ID: 24 
Book Shelf Life: 63
Author: Higgins

Book Title: Nonfiction 
Book ID: 26 
Book Shelf Life: 63
Publisher: Willoughby


Year: 4
Active books
Book Title: Coding Stuff 
Book ID: 0 
Book Shelf Life: 63

Book Title: Fiction 
Book ID: 2 
Book Shelf Life: 63
Author: Higgins

Book Title: Nonfiction 
Book ID: 4 
Book Shelf Life: 63
Publisher: Willoughby

Book Title: Barron's Computer Science "A" 
Book ID: 5 
Book Shelf Life: 63

Book Title: Angels and Demons 
Book ID: 6 
Book Shelf Life: 63

Book Title: The Da Vinci Code 
Book ID: 8 
Book Shelf Life: 63
Author: Dan Brown

Book Title: Pride and Prejudice 
Book ID: 10 
Book Shelf Life: 63
Author: Jane Austen

Book Title: Fiction 
Book ID: 12 
Book Shelf Life: 63
Author: Higgins

Book Title: Nonfiction 
Book ID: 14 
Book Shelf Life: 63
Publisher: Willoughby

Book Title: Fiction 
Book ID: 16 
Book Shelf Life: 63
Author: Higgins

Book Title: Nonfiction 
Book ID: 18 
Book Shelf Life: 63
Publisher: Willoughby

Book Title: Fiction 
Book ID: 20 
Book Shelf Life: 63
Author: Higgins

Book Title: Nonfiction 
Book ID: 22 
Book Shelf Life: 63
Publisher: Willoughby

Book Title: Fiction 
Book ID: 24 
Book Shelf Life: 63
Author: Higgins

Book Title: Nonfiction 
Book ID: 26 
Book Shelf Life: 63
Publisher: Willoughby