Test
- Define 1 argument constructor for Java for book
- Define toString method for title, and a testor method
- Generate unique id for class
- Create a public getter that has a book count
- Define tester method that intializes st least 2 books, outputs id and title, and provides a count of books in library
public class Book
{
String = title;
double = id;
int = numberOfBooks;
int1 = book1;
int2 = book2;
String () = booktitle;
{
public Book (title)
{
double bookCount = int1 + int2;
this.get = bookCount;
}
public void toString
{
this.get = bookCount;
this.generate
}
}
System.out.println("There are two books in the library");
System.out.println("")
System.out.println("The number of books is" +bookCount "in the library");
return bookCount;
}
public class Book {
private static int bookCount = 0;
private int id;
private String title;
public Book(String title) {
this.title = title;
id = ++bookCount;
}
@Override
public String toString() {
return "Title: " + title;
}
public int getId() {
return id;
}
public static int getBookCount() {
return bookCount;
}
public static void main(String[] args) {
Book book1 = new Book("Brave New World");
Book book2 = new Book("Things Fall Apart");
System.out.println(book1.toString() + ", ID: " + book1.getId());
System.out.println(book2.toString() + ", ID: " + book2.getId());
System.out.println("Total number of books: " + Book.getBookCount());
}
}
Book.main(null);
public class Fiction extends Book
{
private String title;
private String author;
private String shelfLife;
}