Answered step by step
Verified Expert Solution
Link Copied!
Question
1 Approved Answer

Define a class named Book that represents a book about Java Programming Language, and it contains: o An int data field named pages that stores

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.


Step by Step Solution

3.46 Rating (149 Votes )

There are 3 Steps involved in it

Step: 1

Heres the implementation of the Book class along with the TestBooks application import javautilScann... blur-text-image
Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image_2

Step: 3

blur-text-image_3

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Introduction to Java Programming, Comprehensive Version

Authors: Y. Daniel Liang

10th Edition

133761312, 978-0133761313

Students explore these related Programming questions