Lavi M.

asked • 10/20/20

How to do this? (Java)

Composition

There are two ways to reuse existing classes, namely, composition and inheritance.

With composition (aka aggregation), you define a new class, which is composed of existing

classes. With inheritance, you derive a new class based on an existing class, with modifications or

extensions.


A class called Author is designed as shown in the class diagram. It contains:

name: String

email:String

gender: char--->'m' or'f'

Methods:

+Author (name : String, email : String,

gender: char)

Methods:

+getName():String

+get Email():String

+set Emaill(email: String) : void

+getGender (): char

+toString ():String--->"name (gender) at email"

● Three private member variables: name (String), email (String), and gender (char of

either 'm' or 'f' - you might also use a boolean variable called isMale having value

of true or false).

●A constructor to initialize the name, email and gender with the given values.

(There is no default constructor, as there is no default value for name, email and gender.)

●Public getters/setters: getName(), getEmail(), setEmail(), and getGender().

(There are no setters for name and gender, as these properties are not designed to be

changed.)

●A toString() method that returns "name (gender) at email", e.g., "Tan Ah Teck (m) at

ahTeck@somewhere.com".



A Book is written by one Author - Using an "Object" Member Variable

Book: Author:

-name: String --name:String

-author: Author -------(1)-----> --email:StrinE

-price: double --gender: char

-qty: int

Methods:

+Book(name: String, author: Author,

price: double, qty: int)

+getName () : String

+getAuthor () :Author

+getPrice(): double

+setPrice (price: double) : void

+getQty(): int

+setQty (qty: int) : void

+toString(): String--->" 'book-name' by author-name (gender) at email"

■Let's design a Book class. Assume that a book is written by one (and exactly one) author. The

Book class (as shown in the class diagram) contains the following members:

●Four private member variables: name (String), author (an instance of the Author class we

have just created, assuming that each book has exactly one author), price (double),

and qty (int).

●The public getters and

setters: getName(), getAuthor(), getPrice(), setPrice(), getQty(), setQty().

●A toString() that returns "'book-name' by author-name (gender) at email". You could reuse

the Author's toString() method, which returns "author-name (gender) at email".

Patrick B.

tutor
source code uploaded to RESOURCES section under this link.
Report

10/20/20

Lavi M.

Thanks but its missing the collection a nd the implements and especially where The program will print a selection screen where the user can choose the operation he/she wants to perform. The selection screen will be repeated after each selection until the staff type the number 4 to completely exit from the program: 1. Add an administration staff (by providing all her/his information) to the list of all administration staff 2. Add a doctor (by providing all her/his information) to the list of all doctors 3. Print all working staff (remember to differentiate between administration staff and doctors in the output printout 4. Exit the program
Report

10/31/20

1 Expert Answer

By:

Lavi M.

Thanks but its missing the collection and the implements and especially where The program will print a selection screen where the user can choose the operation he/she wants to perform. The selection screen will be repeated after each selection until the staff type the number 4 to completely exit from the program: 1. Add an administration staff (by providing all her/his information) to the list of all administration staff 2. Add a doctor (by providing all her/his information) to the list of all doctors 3. Print all working staff (remember to differentiate between administration staff and doctors in the output printout 4. Exit the program
Report

10/31/20

Still looking for help? Get the right answer, fast.

Ask a question for free

Get a free answer to a quick problem.
Most questions answered within 4 hours.

OR

Find an Online Tutor Now

Choose an expert and meet online. No packages or subscriptions, pay only for the time you need.