class Author
{
String name;
String email;
char gender;
Author(String name,String email,char gender)
{
this.name = name;
this.email = email;
this.gender = gender;
}
}
class Book
{
String name;
Author author;
double price;
int qtyInStock;
Book(String name,Author author,double price,int qtyInStock)
{
this.name = name;
this.author = author;
this.price = price;
this.qtyInStock = qtyInStock;
}
void setName(String name)
{
this.name = name;
}
void setAuthor(Author author)
{
this.author = author;
}
void setPrice(double price)
{
this.price = price;
}
void setQtyInStock(int qtyInStock)
{
this.qtyInStock = qtyInStock;
}
String getName()
{
return name;
}
Author getAuthor()
{
return author;
}
double getPrice()
{
return price;
}
int getQtyInStock()
{
return qtyInStock;
}
}
public class HOA1
{
public static void main(String[] args)
{
Author author = new Author("Javed","[email protected]",'M');
Book book = new Book("WiproS",author,500.99,3);
book.setName("JavaWorld");
System.out.println(book.getName());
String[] authDetails = book.getAuthor().toString();
for(String strr: authDetails)
{
System.out.println(strr);
}
}
}
In the above code, I have to provide solution for the question stated as
"Create a class Author with the following information. Member variables : name (String), email (String), and gender (char) Parameterized Constructor: To initialize the variables Create a class Book with the following information. Member variables : name (String), author (of the class Author you have just created), price (double), and qtyInStock (int) [Assumption: Each book will be written by exactly one Author] Parameterized Constructor: To initialize the variables Getters and Setters for all the member variables In the main method, create a book object and print all details of the book (including the author details) "
I am not able to solve it ! I want to print author details using book object .Please help.