Design a class called Writer, which is designed to model a book's writer. It contains:
private instance variables: name(String), email(String), and gender(char of either 'm' or 'f');name, email and gender with the given values;publicWriter(String name, String email,char gender) {......}
public getters/setters: getName(), getEmail(), setEmail(), and getGender();(There are no setters for name and gender, as these attributes cannot be changed.)
toString() method that returns "Writer[name=?,email=?,gender=?]", e.g., "Writer[name=Girdhar Gopal,[email protected],gender=m]".Also, design a class called Book to model a book written by one writer. It contains:
private instance variables: name(String), writer(of the class Writer you have just created, assume that a book has one and only one writer), price(double), and qty(int);publicBook (String name, Writer writer,double price) { ...... }
publicBook (String name, Writer writer,double price,int qty) { ...... }
getName(), getPrice(), setPrice(), getQty(), setQty().toString() that returns "Book[name=?,Writer[name=?,email=?,gender=?],price=?,qty=?". You should reuse Writer’s toString().class Writer
{
private String name;
private String email;
private char gender;
public Writer(String name,String email, char gender){
this.name = name;
this.email = email;
this.gender = gender;
}
public String getName(){
return name;
}
public String getEmail(){
return email;
}
public void setEmail(String email){
this.email = email;
}
public void setGender(char gender){
this.gender = gender;
}
public String toString(){
return "Writer[name="+name+",email="+email+",gender="+gender+"]";
}
}
class Book
{
private String name;
private Writer writer;
private double price;
private int qty;
public Book(String name,Writer writer,double price){
this.name = name;
this.writer = writer;
this.price = price;
}
public Book(String name,Writer writer, double price, int qty){
this.name = name;
this.writer = writer;
this.price = price;
this.qty = qty;
}
public String getName(){
return name;
}
public double getPrice(){
return price;
}
public void setPrice(double price){
this.price = price;
}
public int getQty(){
return qty;
}
public void setQty(int qty){
this.qty = qty;
}
public String toString(){
return "Book[name="+name+","+writer.toString()+",price="+price+",qty="+qty;
}
}