Kindle readers have to store information about
each book that a user is 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 your 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.
You must ...
- Write the Kindle class (1.0%)
- Push your labtask to GitHub
Answer