Question: Exercise-2: 5 points Book class. Define a class Book that satisfies the spec below. Hints For this problem, provide just an implementation as Account Class

Exercise-2: 5 points

Book class. Define a class Book that satisfies the spec below.

Hints

For this problem, provide just an implementation as Account Class for the Book spec below, and test it using the example calls provided.

Book class

A physical book

State variables

  1. title - String, the title of a book
  2. author - String, the author of a book
  3. year - Positive integer, the year of publication of a book

Constructor

Book

3 arguments:

Two strings and a positive integer representing a year

State change:

A new object of type Book is created. The value arg1 is assigned to the state variable title, the value arg2 is assigned to the state variable author, and the value arg3 is assigned to the state variable year.

Return:

That newly created Book object.

Methods

getTitle

No arguments.

Return:

String, the value of the state variable title

getAuthor

No arguments.

Return:

String, the value of the state variable author

getYear

No arguments.

Return:

Positive integer, the value of the state variable year

setYear

One argument:

Positive integer representing a year.

State change:

The state variable year is assigned the value arg1

Return:

Positive integer, the new value of year.

Example calls:

book1 = Book('War and Peace', 'Leo Tolstoy', 1869)

book2 = Book('The Wealth of Nations', 'Adam Smith', 1778)

book1.getTitle() --> 'War and Peace'

book2.getAuthor() --> 'Adam Smith'

book2.getYear() --> 1778

book2.setYear(1776) --> 1776

book2.getYear() --> 1776

Note: insert appropriate amount of comments in your program

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!