Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

JAVA: Kindle readers have to store information about each book that users are reading. The two main items of information are the number of pages

JAVA: Kindle readers have to store information about each book that users are reading. The two main items of information are the number of pages in the book, and the current page number the reader has reached. Write a class to create objects that store this information, and work with this simple driver class. Your class must have:

Two integer data items for storing the page information.

A constructor that receives the number of pages in the book, and sets the current page number to 1.

A toString method for printing the object.

A method to increase the current page number. If no argument is sent it increments the current page number. If an integer argument is sent it increases the current page number by that amount. (Hint: Review "Overloading" in the notes about Methods.) In both cases the method must check if the increase will take the current page number past the end of the book, in which case an error message should be issued, and the current page number set to the last page. (Hint: Use the toString method to help print the error message.)

Here's what a sample run should look like (with the keyboard input shown in italics) ...

How many pages in the book : 33 Initially : Page 1 of 33. A bit later : Page 5 of 33. After skipping 27 pages : Page 32 of 33. You were on : Page 32 of 33. Turning 8 pages would take you past the last page. You are now on : Page 33 of 33. 

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

Step: 3

blur-text-image

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

More Books

Students also viewed these Databases questions