Provide the missing code segment in the portion with the TO DO remark in the following sample code. The Book class involved in the code is provided below: public class Book implements Comparable { protected int pages; public Book(){ pages = 1500; } public Book(int pages){ this.pages = pages; } public void setPages(int pages) { this.pages = pages; } public int getPages() { return pages; } public int compareTo(Book another) { // if same then return 0 if(this.pages == another.pages) return 0; //if current has more than return 1 else return -1 else if (this.pages > another.pages) return 1; else return -1; } }
Provide the missing code segment in the portion with the TO DO remark in the following sample code. The Book class involved in the code is provided below:
public class Book implements Comparable<Book> {
protected int pages;
public Book(){
pages = 1500;
}
public Book(int pages){
this.pages = pages;
}
public void setPages(int pages) {
this.pages = pages;
}
public int getPages() {
return pages;
}
public int compareTo(Book another) {
// if same then return 0
if(this.pages == another.pages)
return 0;
//if current has more than return 1 else return -1
else if (this.pages > another.pages)
return 1;
else
return -1;
}
}
Trending now
This is a popular solution!
Step by step
Solved in 2 steps with 1 images