Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

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

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

design a simple disciplinary and grievance procedure.

Answered: 1 week ago