I have 3 java class named Author, Book, and DisplayBook. Author class is for setting the name of the author. Book class is for geting details(title, author, price) of the book and DisplayBook is for displaying the output (title, author, price) in the console window.
This is what I have done so far but it displays a random text (Author@2f2c9b19) for the author. These are my codes with respective set and get methods.
Author class
private String firstName;
private String lastName;
public Author(String fname, String lname)
{
firstName = fname;
lastName = lname;
}
Book class
private String title;
private Author author;
private double price;
public Book(String bTitle, Author bAuthor, double bPrice)
{
title = bTitle;
author = bAuthor;
price = bPrice;
}
public void printBook()
{
System.out.print("Title: " + title + "\nAuthor: " + author + "\nPrice: " + price);
}
DisplayBook class
public static void main(String[] args) {
Author author = new Author("Jonathan", "Rod");
Book book = new Book("My First Book", author, 35.60);
book.printBook();
}
This is the output
How do I get Jonathan Rod
to display beside Author:
?