class Book (Part 1) Close Book

  1. Define 1 argument constructor for title,
  2. Define toString method for id and title.
  3. Generate unique id for each object
  4. Create a public getter that has Book Count
  5. Define tester method that initializes at least 2 books, outputs id and title, and provides a count of books in library.
public class Book {
    String title;
    private static int bookCount;

    public Book (String title){ // constructor that gets the title
        this.title = title;
        bookCount++;
    }

    public String toString() {
        return this.title;
    }

    public String toHashCode() {
        return Integer.toString (this.hashCode());
    }

    public static int getCount(){
        return Book.bookCount;
    }

    public static void main(String[] args) {
        Book book1 = new Book("Big Bird");
        Book book2 = new Book("Frankenstein");
        System.out.println("title: " + book1 + " id: " + book1.toHashCode());
        System.out.println("title: " + book2 + " id: " + book2.toHashCode());
        System.out.println("the number of books is " + Book.getCount());
    }
}

Book.main(null);
title: Big Bird id: 273922929
title: Frankenstein id: 342637987
the number of books is 2