This is the output:
Customer@682a0b20
Code:
Book class:
public class Book {
public String title;
public String author;
public int genre;
public Book(String title, String author, int genre) {
this.title = title;
this.author = author;
this.genre = genre;
}
public String getBookTitle() {
return title;
}
public String getBookAuthor() {
return author;
}
public int getBookGenre() {
return genre;
}
}
LibraryDatabase class:
import java.util.*;
public class LibraryDatabase extends Book {
ArrayList<Book> bookDatabase;
public LibraryDatabase(String title, String author, int genre) {
super("1", "2", 3);
}
public ArrayList<Book> books(ArrayList<Book> bookDatabase) {
Book book1 = new Book("Harry Potter", "J.K. Rowling", 1);
bookDatabase.add(book1);
return bookDatabase;
}
public String toString() {
return ("Title: " + this.getBookTitle() + "Author: " + this.getBookAuthor() + "Genre: " + this.getBookGenre());
}
}
Customer class:
import java.io.*;
import java.util.*;
public class Customer {
public Customer() {
}
public void run() {
borrow();
}
public void borrow() {
titlesNow();
}
public void titlesNow() {
System.out.println(toString());
}
Tester class:
import java.util.*;
import java.io.*;
public class Tester {
public static void main(String[] args) {
Customer customer = new Customer();
customer.run();
}
}
Why is the output like that? What is wrong in the code that is causing the console to print something like that for the ArrayList? I searched through many questions, and it usually seems like the problem is something to do with not having a toString() method. But I have that in the LibraryDatabase class which extends the Book class. So what's the problem?