Answered step by step
Verified Expert Solution
Question
1 Approved Answer
JAVA Lab 1 3 B: Create a Book class which contains the following: Fields: o name: string o price: double o yearOfRelease: int Constructor: o
JAVA
LabB: Create a Book class which contains the following:
Fields:
o name: string
o price: double
o yearOfRelease: int
Constructor:
o Takes in parameters: a string, and an integer.
o Sets the parameters to the appropriate fields.
setPrice:
o Takes in a double as a parameter and returns nothing.
o Sets the price field with the value in the parameter.
toString:
o Takes in no parameters and returns a string.
o The string returned is in the following format:
name yearOfRelease: $price
In your main method, prompt the user for the name of a book and a release date. Create a Book object with that information. Then, prompt the user for a price, and use the objects setPrice to set the Book objects price. Finally, call the Book objects toString and print what is returned.
Please note the following:
When asking for a price, keep prompting the user until they enter a price that is greater than
When asking for a yearOfRelease, keep prompting the user until they enter a number that is between and
When asking for a name, keep prompting the user until they enter a name that isnt empty.
You can assume the user will never enter information of the wrong type eg: when asking for a yearOfRelease, you can assume the user will only enter integers
Sample output user input in bold:
Enter a name for the book:
Name cannot be empty.
Enter a name for the book: Gulliver's Travels
Enter a year of release for the book:
Year of release must be between and
Enter a year of release for the book:
Enter a price for the book:
Price must be a positive number.
Enter a price for the book:
Price must be a positive number.
Enter a price for the book:
Gulliver's Travels : $
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started