Answered step by step
Verified Expert Solution
Link Copied!

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
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

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

Professional SQL Server 2012 Internals And Troubleshooting

Authors: Christian Bolton, Justin Langford

1st Edition

1118177657, 9781118177655

More Books

Students also viewed these Databases questions

Question

Compute each of the following. 270.00 - (1+ 0.035)-* 0.035

Answered: 1 week ago

Question

Explain the global implications for recruitment.

Answered: 1 week ago

Question

Describe what competencies and competency modeling are.

Answered: 1 week ago

Question

Summarize job design concepts.

Answered: 1 week ago