Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

JAVA Monday Question Implement a Book class that has the following private attributes: author (String) //note this can be two words (first and last name)

JAVA

Monday Question

Implement a Book class that has the following private attributes:

  • author (String) //note this can be two words (first and last name)
  • title (String)
  • year (int)
  • price (double)

The Book class will also have the following methods:

  • Constructor (that sets the author, title, year, and price from defined values).
  • Get and set methods.
  • toString method returns the title, author and year of the book

Then create a BookDemo class to create and use Book objects. The BookDemo class contains the main method. Use a Scanner object to read the attributes for a Book object.

Create a Book object by passing in the attributes read in by the Scanner object.

Use the toString method to print out the title, author and year of the book. Then use the getPrice method to print the price of the book.

Change the year by adding 5 years to it and then use the toString method again to print the book object.

Details

Input

An author, input in the following format:

  • first and last name
  • title
  • year and price

Example Input: Margaret Atwood The Handmaids Tale 1987 22.99

Output

Print using the toString method, use get methods to print price, and then use the toString again after adding 5 years to the date.

Example Output: The Handmaids Tale by Margaret Atwood, 1987 $22.99 The Handmaids Tale by Margaret Atwood, 1992

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

Students also viewed these Databases questions

Question

How did you come up with the (h) number?

Answered: 1 week ago