Question: java super class Exercise 1 (1). The Author Classes A class called Author is designed as shown in the class diagram. Three private instance variables:
java super class
Exercise 1 (1). The Author Classes A class called Author is designed as shown in the class diagram.
Three private instance variables: name (String), email (String), and gender (char of either 'm' or 'f');
A toString() method that returns "author-name (gender) at email", e.g., "Tan Ah Teck (m) at ahTeck@somewhere.com".
(2). The Book Classes
A class called Book is designed as shown in the class diagram.
Four private instance variables: name (String), author (of the class Author you have just created, assume that each book has one and only one author), price (double), andqtyInStock (int);
toString() that returns "'book-name' by author-name (gender) at email". (Take note that the Author's toString() method returns "author-name (gender) at email".)
---------------- ALL I NEED help with is the book constructors that is all the 2 methods inside Book class---------------------
public class Author { protected String name; protected String email; protected char gender; public Author(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 char getGener() { return gender; } public String toString() { return ( name + "(" + gender + ")@" + email); } /** * @param args the command line arguments */ public static void main(String[] args) { // TODO code application logic here } }public class Book extends Author{ private String name; //private final String email; // private char gender; private Author author;// = new Author(name,super.email,super.gender); private double price; private int qtyInStock = 0; public Book(String name, Author author,Double price) { this.author = new author; this.name = name; this.price = price; } public Book(String name, Author author, double price, int qtyInStock) { this.name = name; this.author = author(); this.price = price; this.qtyInStock = qtyInStock; } public String getName() { return name; } public Author getAuthor() { return author; } public double getPrice() { return price; } public void setPrice(double price) { this.price = price; } public int getQtyInStock() { return qtyInStock; } public void setQtyInStock(int qtyInStock) { this.qtyInStock = qtyInStock; } public String toString() { return (name + " by " + author + "(" + super.gender + ")at" + super.email); } }
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
