Define a class named Book that represents a book about Java Programming Language, and it contains: o
Question:
Define a class named Book that represents a book about Java Programming Language, and it contains:
o An int data field namedpagesthat stores the number of pages in the book.
o A String data field namedpublisherthat represents the publisher of the book.
o A constructor with parameters for initializing pages and publisher.
o The getter and setter methods for all data fields.
o A toString method that returns book information (summary), including the book's publisher and pages.
o The equals method that returns true if two books have the same publisher and the same number of pages.
o The compareTo method that compares two books and returns -1 if the first book has fewer pages than the second one, 1 if the first book has more pages than the second one, and 0 if both books have the same number of pages.
1 b . Write an application TestBooks that asks the user for a number of books to review.
- The application repeatedly creates that many Book objects with number of pages to be a random integer, 1-100, inclusive, and publisher data from the user.
- The program prints to the screen the information (summary) about the "biggest" book, (i.e. the book with the bigger number of pages), as well as the average number of pages of the Book objects created.
Note: The program must make use of the compareTo method in order to find the "biggest" book.
Introduction to Java Programming, Comprehensive Version
ISBN: 978-0133761313
10th Edition
Authors: Y. Daniel Liang