Practice

Book Class Catalogue Card

MEDIUMObject-Oriented Programming10 marks

Declare class Book with private attributes Title, Author and Year. Write the constructor NEW and getter methods. Procedure PrintBook(Item) must output <Title> by <Author> (<Year>).

The test harness reads one book and calls PrintBook.

Input: Title, author, year. Output: One formatted line.

Example:

Input:  1984
        George Orwell
        1949
Output: 1984 by George Orwell (1949)

Sample Test Cases

Test 1: Classic title
Inputs: 1984, George Orwell, 1949
Expected: 1984 by George Orwell (1949)
Test 2: Another book
Inputs: Kindred, Octavia Butler, 1979
Expected: Kindred by Octavia Butler (1979)

Premium Question

This question needs a paid plan — upgrade, or join a class from a teacher who has one. You can read the description and sample tests, but grading is locked.

Sign in to get started