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
- title - String, the title of a book
- author - String, the author of a book
- 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
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started