I created an Author object that I used in the method signature of a constructor: public Book [String name, Author author1........]
However, the assignment I'm doing requires that I change the Author (instance variable) to a Author[]
. Of course, now my previous constructor won't work. Here is the code
public class Author {
private String name;
private String email;
private char gender;
public String getName() {
return name;
}
public void setEmail(String email){
this.email = email;
}
public String getEmail(){
return email;
}
public char getGender(){
return gender;
}
public Author(String name, String email, char gender){
this.name = name;
this.email = email;
this.gender = gender;
}
public String toString(){
return "Author[name = " + this.name + ", email = " + this.email + ", gender = " + this.gender + "]";
}
}
public class Book {
private String name;
private Author[] author;
private double price;
private int quantity;
// Getters and Setters
public String getName(){
return name;
}
public Author[] getAuthor(){
return author;
}
public void setPrice(double price){
this.price = price;
}
public double getPrice(){
return price;
}
public void setQuantity(int quantity){
this.quantity = quantity;
}
public int getQuantity(){
return this.quantity;
}
// Constructors
public Book(String name, Author[] author, int quantity){
this.name = name;
this.author = author;
this.price = price;
}
public class BookTest {
public static void main(String[] args){
Author author2 = new Author("Ben", "Ben@hgmail.com", 'm');
Author author3 = new Author("Jennie", "Jennie@hgmail.com", 'f');
Book theIdiot = new Book("The Idiot", [author2, author3], 44.5, 33);
}
}
I apologize for any inconvenience if the way I've uploaded this was unsatisfactory. I have yet to learn to use Stack Overflow.
Thank you!