28.7k views
5 votes
JAVA

Create an object-oriented program that allows a user to keep track of the book they are currently reading. The program should allow the user to change the name of the book, change the number of pages in the book, and the current page they are currently on in the book. The number of pages in a
book must be greater than 0 and also greater than or equal to the current page the reader is currently on.The current page must be greater than 0 and also less than or equal to number of pages in the book. Any time a user enters an invalid value that value will be ignored and will not be saved.

Since this program is object-oriented it must be developed as a class called Book. This class should store name of the book, the number of pages, and current page as instance variables. There should be an instance variable for each these. These instance variables should be made private to
prevent invalid values from being stored in them, but there should be ways to access and mutate these instance variables using public non-static methods. There should be a separate method to access each instance variable. There should be a separate method to mutate each instance variable. This class should also have a default constructor which sets name instance variable to No Name Yet and sets number of pages instance variable to 0 and sets current page instance variable to 0

The second part of this program should be developed in a class called BookDemo. This class will have a main method inside of it where an object of the Book class will be created. Then the user will be given options to update the name, number of pages, and the current page. There should be an
option for each of these. Finally, there should be an option to look at all the information about the book. This main method should also have a loop to allow this program to continue running until the user chooses the last option which is to exit the program. If the user chooses an invalid option then an
error message should be printed to the screen. The program should continue executing until the user chooses to exit the program.

User Buzzsaw
by
8.0k points

1 Answer

4 votes

Final answer:

To create an object-oriented program to keep track of a book, we can define a class called Book. This class will have private instance variables for the name of the book, the number of pages, and the current page.

The class should also provide methods to change the name, number of pages, and current page.

Step-by-step explanation:

To create an object-oriented program to keep track of a book, we can define a class called Book. This class will have private instance variables for the name of the book, the number of pages, and the current page.

To meet the program requirements, the class should also provide methods to change the name, number of pages, and current page. The class should have a default constructor to set initial values for these variables.

Additionally, we can create a separate class called BookDemo with a main method to allow the user to interact with the Book class and update the book's information.

To create an object-oriented program to keep track of a book, we can define a class called Book. This class will have private instance variables for the name of the book, the number of pages, and the current page.

The class should also provide methods to change the name, number of pages, and current page.

User Ifeanyi Idiaye
by
8.5k points