how to structure this piece of code out private Author author; private String isbn, title; private int
Question:
how to structure this piece of code out…
private Author author;
private String isbn, title;
private int pages;
public int compareTo(Book another)
The compareTo method that compares the author first, title second, pages third, and lastly isbn of the book
Specified by:
compareTo
in interface Comparable
<
Book
>
Parameters:
another
- The book object that is being compared to
Throws:
IllegalArgumentException
- if the parameter is null
public int compareTo(Book another){
if(another == null){
throw new IllegalArgumentException();
}
if(this.author.compareTo(another.author) == 0){
if(this.title.compareTo(another.title) == 0) {
if (this.pages.compareTo(another.pages) == 0)
return this.isbn.compareTo(another.isbn);
}else{
return this.pages.compareTo(another.pages)
}else{
return this.title.compareTo(another.title);
}
}else{
return this.author.compareTo(another.author);
}
Building Java Programs A Back To Basics Approach
ISBN: 9780135471944
5th Edition
Authors: Stuart Reges, Marty Stepp