Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Using simple Java (Do not use ArrayList): 1. Define a class named Book that represents a book about Java Programming Language, and it contains: An

Using simple Java (Do not use ArrayList):

1. Define a class named Book that represents a book about Java Programming Language, and it contains:

An int data field named pages that stores the number of pages in the book.

A String data field named title that represents the title of the book.

A constructor with parameters for initializing pages and title.

The getter and setter methods for all data fields.

A toString method that returns book information, including the books title and pages.

The equals method that returns true if two books have the same title and false otherwise.

The compareTo method that compares two books and returns -1 if the first book has less pages than the second one, 1 if the first book has more pages than the second one, and 0 if both books have same number of pages.

2. Write an application TestBooks that prompts the user for the number of Java books in their library, called numBooks. For each of the numBooks books, the program prompts the user for its title and pages, creates a Book object and maintains two statistics about the books:

the average number of pages of all the Book objects created

the biggest book, i.e. the Book object with the largest number of pages.

The program will lastly print these two statistics on the screen.

HINT: This program MUST make use of the compareTo method in order to find the biggest book.

Below is a sample program run:

Number of java books in your library: 4

Enter book title: Intro to Java 1 Enter number of pages: 200 Enter book title: Intro to Java 2 Enter number of pages: 150 Enter book title: Java programming Enter number of pages: 300 Enter book title: Data Structures in Java Enter number of pages: 320

Average number of pages: 242.5 Biggest book -> Title: Data Structures in Java, Pages: 320

Step by Step Solution

There are 3 Steps involved in it

Step: 1

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

Systems Analysis And Synthesis Bridging Computer Science And Information Technology

Authors: Barry Dwyer

1st Edition

0128054492, 9780128054499

More Books

Students also viewed these Databases questions

Question

3. Why are age discrimination issues growing in importance?

Answered: 1 week ago