Question: 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
Lab13B: Create a Book class which contains the following:
Fields:
o name: string
o price: double
o yearOfRelease: int
Constructor:
o Takes in 2 parameters: a string, and an integer.
o Sets the 2 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 0.
When asking for a yearOfRelease, keep prompting the user until they enter a number that is between 1500 and 2024.
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 (e.g.: 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: 1499
Year of release must be between 1500 and 2024.
Enter a year of release for the book: 1726
Enter a price for the book: -200.0
Price must be a positive number.
Enter a price for the book: 0
Price must be a positive number.
Enter a price for the book: 42.99
Gulliver's Travels (1726): $42.99

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!