Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

please help with these two problems. i cannot add any instance variables to any class, but i can create local variables inside a method to

please help with these two problems. i cannot add any instance variables to any class, but i can create local variables inside a method to sucessfully run tasks. thank you so much! image text in transcribed
image text in transcribed
Step 1 Develop the following class: Class Name: Book Access Modifier: public Instance variables Name: name Access modifier:private Data Type: String Name: numberOfPages Access modifier: private Data Type: int Name: currentPage Access modifier: private Data Type: int Constructors: Name: Book Access modifier: public Parameters: none (default constructor) Task: sets the value of the instance variable name to the No Name Yet sets the value of the instance variable numberOfPages to 0 sets the value of the instance variable currentPage to 0 Methods Name: setName Access modifier: public Parameters: new Name Return Type: void Task: sets the value of the instance variable name to newName Step 2 Develop a class with only a main method in it: import java.util.Scanner: public class BookDemo public static void main(String[] args) { //Create a Scanner object called keyboard that takes input from //System. in //Create an object of the Book class refer to this object as //myFavoriteBook //declare a variable called option of type int / /Open a do/while loop //Prompt the user to pick one of the following options: //Press 1 to change the name of the book //Press 2 to change the number of pages in the book //Press 3 to change the current page //Press 4 to view all information about the book //Press 5 to end the program //Save the user's input into the option variable 1/if the user picks option 1, prompt the user for the name of the book //then save the name of the book in a variable called newklame //change the name of the book to newName 1/else if the user picks option 2, prompt the user for the number of //pages in the book then save the number of pages in a variable called /ewNumberOfPages 1/change the number of pages of the book to new NumberOfPages //else if the user picks option 3, prompt the user for the current 1/page and save the current page in a variable called newCurrentPage 1/change the currentPage of the book to newCurrentPage //else if the user picks option 4, display to the screen the name of the book, the number of pages in the book, and the current page of the book //else if the user picks option 5, display Goodbye. //else if the user picks any other option, display Error! //close the do/while loop and make it so that it continues to run as //long as the user does not pick option 5 } }

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

Harness The Power Of Big Data The IBM Big Data Platform

Authors: Paul Zikopoulos, David Corrigan James Giles Thomas Deutsch Krishnan Parasuraman Dirk DeRoos Paul Zikopoulos

1st Edition

0071808183, 9780071808187

More Books

Students also viewed these Databases questions