0% found this document useful (0 votes)
13 views

Assignment 2 2017 Dec

Uploaded by

lakmal bandara
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
13 views

Assignment 2 2017 Dec

Uploaded by

lakmal bandara
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 2

ITE 1101 - Fundamentals of Programming

Level 01 Semester 01

Assignment 02

Deadline of Submission: 01st January 2018

1. Create a class called Author (as shown in the following class diagram) is designed to
model a book's author. It contains:
a. Three private instance variables: name (String), email (String),and
gender (char of either 'm' or 'f');
b. One constructor to initialize the name, email and gender with the given values;
public Author (String name, String email, char gender) {......}
(There is no default constructor for Author, as there are no defaults for name, email
and gender.)
c. public getters/setters: getName(), getEmail(), setEmail(), and getGender();
(There are no setters for name and gender, as these attributes cannot be changed.)
d. A toString() method that returns "Author[name=?,email=?,gender=?]",
e.g., "Author[name=Tan Ah Teck,[email protected],gender=m]".

2. Also write a test class called TestAuthor to test all the public methods.
3. Create a class called Book is designed (as shown in the following class diagram) to
model a book written by one author. It contains:
a. Four private instance variables: name (String), author (of the class Author you
have just created, assume that a book has one and only one
author), price (double), and qty (int);
b. Two constructors:
public Book (String name, Author author, double price) { ...... }
public Book (String name, Author author, double price, int qty) { ...... }
c. public methods getName(), getAuthor(), getPrice(), setPrice(), getQty(), setQty().
d. A toString() that returns
"Book[name=?,Author[name=?,email=?,gender=?],price=?,qty=?".
You should reuse Author’s toString().

4. Write a test class called TestBook to test all the public methods in the class Book.

You might also like