Test
Part 1 of test
class Book (Part 1) Close Book
- Define 1 argument constructor for title,
- Define toString method for id and title.
- Generate unique id for each object
- Create a public getter that has Book Count
- 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);