Hi, can i please get assistance with the following Java class below, where there is "TO DO:" I would like the task to be done please. Add anything relevant if needed only. The author class and the book class description is given.
Hi, can i please get assistance with the following Java class below, where there is "TO DO:" I would like the task to be done please. Add anything relevant if needed only. The author class and the book class description is given.
public class Book {
private String title;
private double averageRating;
private String ISBN;
private int numPages;
// TO DO: insert an appropriate collection for associating Authors and initialise within constructors
public Book(){
}
public Book(String title, double averageRating, String isbn, int numPages){
this.title = title;
this.averageRating = averageRating;
this.ISBN = isbn;
this.numPages = numPages;
}
//accessors
public String getTitle(){
return title;
}
public double getAverageRating(){
return averageRating;
}
public String getISBN(){
return ISBN;
}
public int getNumPages(){
return numPages;
}
// TO DO: provide an accessor for the collection on line 9
public String getAuthorList(){
String authorList ="";
// TO DO: insert code to return all author names separated by commas if multiple authors
return authorList;
}
//mutators
public void setTitle(String title){
this.title = title;
}
public void setAverageRating(double averageRating){
this.averageRating = averageRating;
}
public void setISBN(String isbn){
this.ISBN = isbn;
}
public void setNumPages(int numPages){
this.numPages = numPages;
}
public void addAuthor(Author a){
// TO DO: complete this method
/* Inserts a new Author into the author list. No duplicates are allowed */
}
public boolean isAuthoredBy(Author a){
// TO DO: complete this method -
/* Returns true if the Book is authored by the supplied author
false otherwise */
return false;
}
//variety of String representations of a Book
public String toStringTitleFirst(){
return getTitle() + ", " + getAuthorList() + " " + getAverageRating() + ", " + getISBN() + ", " + getNumPages() + " pages.";
}
public String toStringISBNFirst(){
return getISBN() + " " + getTitle() + ", " + getAuthorList() + " " + getAverageRating() + ", " + ", " + getNumPages() + " pages.";
}
public String toStringRatingFirst(){
return getAverageRating() + " " + getTitle() + ", " + getAuthorList() + " " + getISBN() + ", " + ", " + getNumPages() + " pages.";
}
public String toStringPagesFirst(){
return getNumPages() + " pages " + getTitle() + ", " + getAuthorList() + " " + getISBN() + ", " + ", " + getAverageRating() ;
}
}
Step by step
Solved in 2 steps