What kind of data is the colors of the cars around the gym in the scenario

This

01/02/2014
09/12/2099
Month: 12
Day: 9
Year: 2099
03/04/2016
2 class does not have a
01/02/2014
09/12/2099
Month: 12
Day: 9
Year: 2099
03/04/2016
4 method. Hence, it cannot be run directly. This
01/02/2014
09/12/2099
Month: 12
Day: 9
Year: 2099
03/04/2016
2 class is a “building block” and is meant to be used in another program.

Let us write a test program called

01/02/2014
09/12/2099
Month: 12
Day: 9
Year: 2099
03/04/2016
6 (in another source file called
01/02/2014
09/12/2099
Month: 12
Day: 9
Year: 2099
03/04/2016
7) which uses the
01/02/2014
09/12/2099
Month: 12
Day: 9
Year: 2099
03/04/2016
2 class, as follows:

Now, run the

01/02/2014
09/12/2099
Month: 12
Day: 9
Year: 2099
03/04/2016
6 and study the results.

More Basic OOP Concepts
  1. Constructor: Modify the class
    01/02/2014
    09/12/2099
    Month: 12
    Day: 9
    Year: 2099
    03/04/2016
    2 to include a third constructor for constructing a
    01/02/2014
    09/12/2099
    Month: 12
    Day: 9
    Year: 2099
    03/04/2016
    2 instance with two arguments - a
    Account[id=A101,name=Tan Ah Teck,balance=88]
    Account[id=A102,name=Kumar,balance=0]
    ID: A101 
    Name: Tan Ah Teck
    Balance: 88 
    Account[id=A101,name=Tan Ah Teck,balance=188]
    Account[id=A101,name=Tan Ah Teck,balance=138]
    Amount exceeded balance
    Account[id=A101,name=Tan Ah Teck,balance=138]
    Account[id=A101,name=Tan Ah Teck,balance=38]
    Account[id=A102,name=Kumar,balance=100]
    2 for
    Account[id=A101,name=Tan Ah Teck,balance=88]
    Account[id=A102,name=Kumar,balance=0]
    ID: A101 
    Name: Tan Ah Teck
    Balance: 88 
    Account[id=A101,name=Tan Ah Teck,balance=188]
    Account[id=A101,name=Tan Ah Teck,balance=138]
    Amount exceeded balance
    Account[id=A101,name=Tan Ah Teck,balance=138]
    Account[id=A101,name=Tan Ah Teck,balance=38]
    Account[id=A102,name=Kumar,balance=100]
    1 and a
    Account[id=A101,name=Tan Ah Teck,balance=88]
    Account[id=A102,name=Kumar,balance=0]
    ID: A101 
    Name: Tan Ah Teck
    Balance: 88 
    Account[id=A101,name=Tan Ah Teck,balance=188]
    Account[id=A101,name=Tan Ah Teck,balance=138]
    Amount exceeded balance
    Account[id=A101,name=Tan Ah Teck,balance=138]
    Account[id=A101,name=Tan Ah Teck,balance=38]
    Account[id=A102,name=Kumar,balance=100]
    4 for
    Account[id=A101,name=Tan Ah Teck,balance=88]
    Account[id=A102,name=Kumar,balance=0]
    ID: A101 
    Name: Tan Ah Teck
    Balance: 88 
    Account[id=A101,name=Tan Ah Teck,balance=188]
    Account[id=A101,name=Tan Ah Teck,balance=138]
    Amount exceeded balance
    Account[id=A101,name=Tan Ah Teck,balance=138]
    Account[id=A101,name=Tan Ah Teck,balance=38]
    Account[id=A102,name=Kumar,balance=100]
    3. Modify the test program
    01/02/2014
    09/12/2099
    Month: 12
    Day: 9
    Year: 2099
    03/04/2016
    6 to construct an instance of
    01/02/2014
    09/12/2099
    Month: 12
    Day: 9
    Year: 2099
    03/04/2016
    2 using this constructor.
  2. Getter: Add a getter for variable
    Account[id=A101,name=Tan Ah Teck,balance=88]
    Account[id=A102,name=Kumar,balance=0]
    ID: A101 
    Name: Tan Ah Teck
    Balance: 88 
    Account[id=A101,name=Tan Ah Teck,balance=188]
    Account[id=A101,name=Tan Ah Teck,balance=138]
    Amount exceeded balance
    Account[id=A101,name=Tan Ah Teck,balance=138]
    Account[id=A101,name=Tan Ah Teck,balance=38]
    Account[id=A102,name=Kumar,balance=100]
    3 for retrieving the
    Account[id=A101,name=Tan Ah Teck,balance=88]
    Account[id=A102,name=Kumar,balance=0]
    ID: A101 
    Name: Tan Ah Teck
    Balance: 88 
    Account[id=A101,name=Tan Ah Teck,balance=188]
    Account[id=A101,name=Tan Ah Teck,balance=138]
    Amount exceeded balance
    Account[id=A101,name=Tan Ah Teck,balance=138]
    Account[id=A101,name=Tan Ah Teck,balance=38]
    Account[id=A102,name=Kumar,balance=100]
    3 of this instance. Modify the test program to test this method.
  3. public vs. private: In
    01/02/2014
    09/12/2099
    Month: 12
    Day: 9
    Year: 2099
    03/04/2016
    6, can you access the instance variable
    Account[id=A101,name=Tan Ah Teck,balance=88]
    Account[id=A102,name=Kumar,balance=0]
    ID: A101 
    Name: Tan Ah Teck
    Balance: 88 
    Account[id=A101,name=Tan Ah Teck,balance=188]
    Account[id=A101,name=Tan Ah Teck,balance=138]
    Amount exceeded balance
    Account[id=A101,name=Tan Ah Teck,balance=138]
    Account[id=A101,name=Tan Ah Teck,balance=38]
    Account[id=A102,name=Kumar,balance=100]
    1 directly (e.g.,
    Ball[(1.1,2.2),speed=(3.3,4.4)]
    Ball[(80.0,35.0),speed=(4.0,6.0)]
    x is: 80.0
    y is: 35.0
    radius is: 5
    xDelta is: 4.0
    yDelta is: 6.0
    Ball[(84.0,41.0),speed=(4.0,6.0)]
    Ball[(88.0,47.0),speed=(4.0,6.0)]
    Ball[(92.0,41.0),speed=(4.0,-6.0)]
    Ball[(96.0,35.0),speed=(4.0,-6.0)]
    Ball[(92.0,29.0),speed=(-4.0,-6.0)]
    Ball[(88.0,23.0),speed=(-4.0,-6.0)]
    Ball[(84.0,17.0),speed=(-4.0,-6.0)]
    Ball[(80.0,11.0),speed=(-4.0,-6.0)]
    Ball[(76.0,5.0),speed=(-4.0,-6.0)]
    Ball[(72.0,-1.0),speed=(-4.0,-6.0)]
    Ball[(68.0,5.0),speed=(-4.0,6.0)]
    Ball[(64.0,11.0),speed=(-4.0,6.0)]
    Ball[(60.0,17.0),speed=(-4.0,6.0)]
    Ball[(56.0,23.0),speed=(-4.0,6.0)]
    Ball[(52.0,29.0),speed=(-4.0,6.0)]
    2); or assign a new value to
    Account[id=A101,name=Tan Ah Teck,balance=88]
    Account[id=A102,name=Kumar,balance=0]
    ID: A101 
    Name: Tan Ah Teck
    Balance: 88 
    Account[id=A101,name=Tan Ah Teck,balance=188]
    Account[id=A101,name=Tan Ah Teck,balance=138]
    Amount exceeded balance
    Account[id=A101,name=Tan Ah Teck,balance=138]
    Account[id=A101,name=Tan Ah Teck,balance=38]
    Account[id=A102,name=Kumar,balance=100]
    1 (e.g.,
    Ball[(1.1,2.2),speed=(3.3,4.4)]
    Ball[(80.0,35.0),speed=(4.0,6.0)]
    x is: 80.0
    y is: 35.0
    radius is: 5
    xDelta is: 4.0
    yDelta is: 6.0
    Ball[(84.0,41.0),speed=(4.0,6.0)]
    Ball[(88.0,47.0),speed=(4.0,6.0)]
    Ball[(92.0,41.0),speed=(4.0,-6.0)]
    Ball[(96.0,35.0),speed=(4.0,-6.0)]
    Ball[(92.0,29.0),speed=(-4.0,-6.0)]
    Ball[(88.0,23.0),speed=(-4.0,-6.0)]
    Ball[(84.0,17.0),speed=(-4.0,-6.0)]
    Ball[(80.0,11.0),speed=(-4.0,-6.0)]
    Ball[(76.0,5.0),speed=(-4.0,-6.0)]
    Ball[(72.0,-1.0),speed=(-4.0,-6.0)]
    Ball[(68.0,5.0),speed=(-4.0,6.0)]
    Ball[(64.0,11.0),speed=(-4.0,6.0)]
    Ball[(60.0,17.0),speed=(-4.0,6.0)]
    Ball[(56.0,23.0),speed=(-4.0,6.0)]
    Ball[(52.0,29.0),speed=(-4.0,6.0)]
    4)? Try it out and explain the error messages.
  4. Setter: Is there a need to change the values of
    Account[id=A101,name=Tan Ah Teck,balance=88]
    Account[id=A102,name=Kumar,balance=0]
    ID: A101 
    Name: Tan Ah Teck
    Balance: 88 
    Account[id=A101,name=Tan Ah Teck,balance=188]
    Account[id=A101,name=Tan Ah Teck,balance=138]
    Amount exceeded balance
    Account[id=A101,name=Tan Ah Teck,balance=138]
    Account[id=A101,name=Tan Ah Teck,balance=38]
    Account[id=A102,name=Kumar,balance=100]
    1 and
    Account[id=A101,name=Tan Ah Teck,balance=88]
    Account[id=A102,name=Kumar,balance=0]
    ID: A101 
    Name: Tan Ah Teck
    Balance: 88 
    Account[id=A101,name=Tan Ah Teck,balance=188]
    Account[id=A101,name=Tan Ah Teck,balance=138]
    Amount exceeded balance
    Account[id=A101,name=Tan Ah Teck,balance=138]
    Account[id=A101,name=Tan Ah Teck,balance=38]
    Account[id=A102,name=Kumar,balance=100]
    3 of a
    01/02/2014
    09/12/2099
    Month: 12
    Day: 9
    Year: 2099
    03/04/2016
    2 instance after it is constructed? If so, add two
    Account[id=A101,name=Tan Ah Teck,balance=88]
    Account[id=A102,name=Kumar,balance=0]
    ID: A101 
    Name: Tan Ah Teck
    Balance: 88 
    Account[id=A101,name=Tan Ah Teck,balance=188]
    Account[id=A101,name=Tan Ah Teck,balance=138]
    Amount exceeded balance
    Account[id=A101,name=Tan Ah Teck,balance=138]
    Account[id=A101,name=Tan Ah Teck,balance=38]
    Account[id=A102,name=Kumar,balance=100]
    7 methods called setters for changing the
    Account[id=A101,name=Tan Ah Teck,balance=88]
    Account[id=A102,name=Kumar,balance=0]
    ID: A101 
    Name: Tan Ah Teck
    Balance: 88 
    Account[id=A101,name=Tan Ah Teck,balance=188]
    Account[id=A101,name=Tan Ah Teck,balance=138]
    Amount exceeded balance
    Account[id=A101,name=Tan Ah Teck,balance=138]
    Account[id=A101,name=Tan Ah Teck,balance=38]
    Account[id=A102,name=Kumar,balance=100]
    1 and
    Account[id=A101,name=Tan Ah Teck,balance=88]
    Account[id=A102,name=Kumar,balance=0]
    ID: A101 
    Name: Tan Ah Teck
    Balance: 88 
    Account[id=A101,name=Tan Ah Teck,balance=188]
    Account[id=A101,name=Tan Ah Teck,balance=138]
    Amount exceeded balance
    Account[id=A101,name=Tan Ah Teck,balance=138]
    Account[id=A101,name=Tan Ah Teck,balance=38]
    Account[id=A102,name=Kumar,balance=100]
    3 of a
    01/02/2014
    09/12/2099
    Month: 12
    Day: 9
    Year: 2099
    03/04/2016
    2 instance as follows: Modify the
    01/02/2014
    09/12/2099
    Month: 12
    Day: 9
    Year: 2099
    03/04/2016
    6 to test these methods, e.g.,
  5. Keyword "this": Instead of using variable names such as
    public Ball(float x, float y, int radius, int speed, int directionInDegree)
    3 (for
    Account[id=A101,name=Tan Ah Teck,balance=88]
    Account[id=A102,name=Kumar,balance=0]
    ID: A101 
    Name: Tan Ah Teck
    Balance: 88 
    Account[id=A101,name=Tan Ah Teck,balance=188]
    Account[id=A101,name=Tan Ah Teck,balance=138]
    Amount exceeded balance
    Account[id=A101,name=Tan Ah Teck,balance=138]
    Account[id=A101,name=Tan Ah Teck,balance=38]
    Account[id=A102,name=Kumar,balance=100]
    1) and
    public Ball(float x, float y, int radius, int speed, int directionInDegree)
    5 (for
    Account[id=A101,name=Tan Ah Teck,balance=88]
    Account[id=A102,name=Kumar,balance=0]
    ID: A101 
    Name: Tan Ah Teck
    Balance: 88 
    Account[id=A101,name=Tan Ah Teck,balance=188]
    Account[id=A101,name=Tan Ah Teck,balance=138]
    Amount exceeded balance
    Account[id=A101,name=Tan Ah Teck,balance=138]
    Account[id=A101,name=Tan Ah Teck,balance=38]
    Account[id=A102,name=Kumar,balance=100]
    3) in the methods' arguments, it is better to use variable names
    Account[id=A101,name=Tan Ah Teck,balance=88]
    Account[id=A102,name=Kumar,balance=0]
    ID: A101 
    Name: Tan Ah Teck
    Balance: 88 
    Account[id=A101,name=Tan Ah Teck,balance=188]
    Account[id=A101,name=Tan Ah Teck,balance=138]
    Amount exceeded balance
    Account[id=A101,name=Tan Ah Teck,balance=138]
    Account[id=A101,name=Tan Ah Teck,balance=38]
    Account[id=A102,name=Kumar,balance=100]
    1 (for
    Account[id=A101,name=Tan Ah Teck,balance=88]
    Account[id=A102,name=Kumar,balance=0]
    ID: A101 
    Name: Tan Ah Teck
    Balance: 88 
    Account[id=A101,name=Tan Ah Teck,balance=188]
    Account[id=A101,name=Tan Ah Teck,balance=138]
    Amount exceeded balance
    Account[id=A101,name=Tan Ah Teck,balance=138]
    Account[id=A101,name=Tan Ah Teck,balance=38]
    Account[id=A102,name=Kumar,balance=100]
    1) and
    Account[id=A101,name=Tan Ah Teck,balance=88]
    Account[id=A102,name=Kumar,balance=0]
    ID: A101 
    Name: Tan Ah Teck
    Balance: 88 
    Account[id=A101,name=Tan Ah Teck,balance=188]
    Account[id=A101,name=Tan Ah Teck,balance=138]
    Amount exceeded balance
    Account[id=A101,name=Tan Ah Teck,balance=138]
    Account[id=A101,name=Tan Ah Teck,balance=38]
    Account[id=A102,name=Kumar,balance=100]
    3 (for
    Account[id=A101,name=Tan Ah Teck,balance=88]
    Account[id=A102,name=Kumar,balance=0]
    ID: A101 
    Name: Tan Ah Teck
    Balance: 88 
    Account[id=A101,name=Tan Ah Teck,balance=188]
    Account[id=A101,name=Tan Ah Teck,balance=138]
    Amount exceeded balance
    Account[id=A101,name=Tan Ah Teck,balance=138]
    Account[id=A101,name=Tan Ah Teck,balance=38]
    Account[id=A102,name=Kumar,balance=100]
    3) and use the special keyword "
    public Author (String name, String email, char gender) {......}
    1" to resolve the conflict between instance variables and methods' arguments. For example, Modify ALL the constructors and setters in the
    01/02/2014
    09/12/2099
    Month: 12
    Day: 9
    Year: 2099
    03/04/2016
    2 class to use the keyword "
    public Author (String name, String email, char gender) {......}
    1".
  6. Method toString(): Every well-designed Java class should contain a
    Account[id=A101,name=Tan Ah Teck,balance=88]
    Account[id=A102,name=Kumar,balance=0]
    ID: A101 
    Name: Tan Ah Teck
    Balance: 88 
    Account[id=A101,name=Tan Ah Teck,balance=188]
    Account[id=A101,name=Tan Ah Teck,balance=138]
    Amount exceeded balance
    Account[id=A101,name=Tan Ah Teck,balance=138]
    Account[id=A101,name=Tan Ah Teck,balance=38]
    Account[id=A102,name=Kumar,balance=100]
    7 method called
    public Author (String name, String email, char gender) {......}
    5 that returns a description of the instance (in the return type of
    Account[id=A101,name=Tan Ah Teck,balance=88]
    Account[id=A102,name=Kumar,balance=0]
    ID: A101 
    Name: Tan Ah Teck
    Balance: 88 
    Account[id=A101,name=Tan Ah Teck,balance=188]
    Account[id=A101,name=Tan Ah Teck,balance=138]
    Amount exceeded balance
    Account[id=A101,name=Tan Ah Teck,balance=138]
    Account[id=A101,name=Tan Ah Teck,balance=38]
    Account[id=A102,name=Kumar,balance=100]
    4). The
    public Author (String name, String email, char gender) {......}
    5 method can be called explicitly (via
    public Author (String name, String email, char gender) {......}
    8) just like any other method; or implicitly through
    public Author (String name, String email, char gender) {......}
    9. If an instance is passed to the
    Rectangle[length=1.2,width=3.4]
    Rectangle[length=1.0,width=1.0]
    Rectangle[length=5.6,width=7.8]
    length is: 5.6
    width is: 7.8
    area is: 43.68
    perimeter is: 26.80
    00 method, the
    public Author (String name, String email, char gender) {......}
    5 method of that instance will be invoked implicitly. For example, include the following
    public Author (String name, String email, char gender) {......}
    5 methods to the
    01/02/2014
    09/12/2099
    Month: 12
    Day: 9
    Year: 2099
    03/04/2016
    2 class: Try calling
    public Author (String name, String email, char gender) {......}
    5 method explicitly, just like any other method:
    public Author (String name, String email, char gender) {......}
    5 is called implicitly when an instance is passed to
    public Author (String name, String email, char gender) {......}
    9 method, for example,

The final class diagram for the

01/02/2014
09/12/2099
Month: 12
Day: 9
Year: 2099
03/04/2016
2 class is as follows:

What kind of data is the colors of the cars around the gym in the scenario

Ex: Yet Another Circle Class

A class called

01/02/2014
09/12/2099
Month: 12
Day: 9
Year: 2099
03/04/2016
2, which models a circle with a radius, is designed as shown in the following class diagram. Write the
01/02/2014
09/12/2099
Month: 12
Day: 9
Year: 2099
03/04/2016
2 class.

What kind of data is the colors of the cars around the gym in the scenario

Below is a Test Driver to test your

01/02/2014
09/12/2099
Month: 12
Day: 9
Year: 2099
03/04/2016
2 class.

The expected output is:

Circle[radius=1.1]
Circle[radius=1.0]
Circle[radius=2.2]
radius is: 2.2
area is: 15.21
circumference is: 13.82

Ex: The Rectangle Class

A class called

Rectangle[length=1.2,width=3.4]
Rectangle[length=1.0,width=1.0]
Rectangle[length=5.6,width=7.8]
length is: 5.6
width is: 7.8
area is: 43.68
perimeter is: 26.80
11, which models a rectangle with a length and a width (in
Rectangle[length=1.2,width=3.4]
Rectangle[length=1.0,width=1.0]
Rectangle[length=5.6,width=7.8]
length is: 5.6
width is: 7.8
area is: 43.68
perimeter is: 26.80
12), is designed as shown in the following class diagram. Write the
Rectangle[length=1.2,width=3.4]
Rectangle[length=1.0,width=1.0]
Rectangle[length=5.6,width=7.8]
length is: 5.6
width is: 7.8
area is: 43.68
perimeter is: 26.80
11 class.

What kind of data is the colors of the cars around the gym in the scenario

Below is a test driver to test the

Rectangle[length=1.2,width=3.4]
Rectangle[length=1.0,width=1.0]
Rectangle[length=5.6,width=7.8]
length is: 5.6
width is: 7.8
area is: 43.68
perimeter is: 26.80
11 class:

The expected output is:

Rectangle[length=1.2,width=3.4]
Rectangle[length=1.0,width=1.0]
Rectangle[length=5.6,width=7.8]
length is: 5.6
width is: 7.8
area is: 43.68
perimeter is: 26.80

Ex: The Employee Class

A class called

Rectangle[length=1.2,width=3.4]
Rectangle[length=1.0,width=1.0]
Rectangle[length=5.6,width=7.8]
length is: 5.6
width is: 7.8
area is: 43.68
perimeter is: 26.80
15, which models an employee with an ID, name and salary, is designed as shown in the following class diagram. The method
Rectangle[length=1.2,width=3.4]
Rectangle[length=1.0,width=1.0]
Rectangle[length=5.6,width=7.8]
length is: 5.6
width is: 7.8
area is: 43.68
perimeter is: 26.80
16 increases the salary by the given percentage. Write the
Rectangle[length=1.2,width=3.4]
Rectangle[length=1.0,width=1.0]
Rectangle[length=5.6,width=7.8]
length is: 5.6
width is: 7.8
area is: 43.68
perimeter is: 26.80
15 class.

What kind of data is the colors of the cars around the gym in the scenario

Below is a test driver to test the

Rectangle[length=1.2,width=3.4]
Rectangle[length=1.0,width=1.0]
Rectangle[length=5.6,width=7.8]
length is: 5.6
width is: 7.8
area is: 43.68
perimeter is: 26.80
15 class:

The expected out is:

Employee[id=8,name=Peter Tan,salary=2500]
Employee[id=8,name=Peter Tan,salary=999]
id is: 8
firstname is: Peter
lastname is: Tan
salary is: 999
name is: Peter Tan
annual salary is: 11988
1098
Employee[id=8,name=Peter Tan,salary=1098]

Ex: The InvoiceItem Class

A class called

Rectangle[length=1.2,width=3.4]
Rectangle[length=1.0,width=1.0]
Rectangle[length=5.6,width=7.8]
length is: 5.6
width is: 7.8
area is: 43.68
perimeter is: 26.80
19, which models an item of an invoice, with ID, description, quantity and unit price, is designed as shown in the following class diagram. Write the
Rectangle[length=1.2,width=3.4]
Rectangle[length=1.0,width=1.0]
Rectangle[length=5.6,width=7.8]
length is: 5.6
width is: 7.8
area is: 43.68
perimeter is: 26.80
19 class.

What kind of data is the colors of the cars around the gym in the scenario

Below is a test driver to test the

Rectangle[length=1.2,width=3.4]
Rectangle[length=1.0,width=1.0]
Rectangle[length=5.6,width=7.8]
length is: 5.6
width is: 7.8
area is: 43.68
perimeter is: 26.80
19 class:

The expected output is:

InvoiceItem[id=A101,desc=Pen Red,qty=888,unitPrice=0.08]
InvoiceItem[id=A101,desc=Pen Red,qty=999,unitPrice=0.99]
id is: A101
desc is: Pen Red
qty is: 999
unitPrice is: 0.99
The total is: 989.01

Ex: The Account Class

A class called

Rectangle[length=1.2,width=3.4]
Rectangle[length=1.0,width=1.0]
Rectangle[length=5.6,width=7.8]
length is: 5.6
width is: 7.8
area is: 43.68
perimeter is: 26.80
22, which models a bank account of a customer, is designed as shown in the following class diagram. The methods
Rectangle[length=1.2,width=3.4]
Rectangle[length=1.0,width=1.0]
Rectangle[length=5.6,width=7.8]
length is: 5.6
width is: 7.8
area is: 43.68
perimeter is: 26.80
23 and
Rectangle[length=1.2,width=3.4]
Rectangle[length=1.0,width=1.0]
Rectangle[length=5.6,width=7.8]
length is: 5.6
width is: 7.8
area is: 43.68
perimeter is: 26.80
24 add or subtract the given
Rectangle[length=1.2,width=3.4]
Rectangle[length=1.0,width=1.0]
Rectangle[length=5.6,width=7.8]
length is: 5.6
width is: 7.8
area is: 43.68
perimeter is: 26.80
25 to the
Rectangle[length=1.2,width=3.4]
Rectangle[length=1.0,width=1.0]
Rectangle[length=5.6,width=7.8]
length is: 5.6
width is: 7.8
area is: 43.68
perimeter is: 26.80
26. The method
Rectangle[length=1.2,width=3.4]
Rectangle[length=1.0,width=1.0]
Rectangle[length=5.6,width=7.8]
length is: 5.6
width is: 7.8
area is: 43.68
perimeter is: 26.80
27 transfers the given
Rectangle[length=1.2,width=3.4]
Rectangle[length=1.0,width=1.0]
Rectangle[length=5.6,width=7.8]
length is: 5.6
width is: 7.8
area is: 43.68
perimeter is: 26.80
25 from this
Rectangle[length=1.2,width=3.4]
Rectangle[length=1.0,width=1.0]
Rectangle[length=5.6,width=7.8]
length is: 5.6
width is: 7.8
area is: 43.68
perimeter is: 26.80
22 to the given
Rectangle[length=1.2,width=3.4]
Rectangle[length=1.0,width=1.0]
Rectangle[length=5.6,width=7.8]
length is: 5.6
width is: 7.8
area is: 43.68
perimeter is: 26.80
30. Write the
Rectangle[length=1.2,width=3.4]
Rectangle[length=1.0,width=1.0]
Rectangle[length=5.6,width=7.8]
length is: 5.6
width is: 7.8
area is: 43.68
perimeter is: 26.80
22 class.

What kind of data is the colors of the cars around the gym in the scenario

Below is a test driver to test the

Rectangle[length=1.2,width=3.4]
Rectangle[length=1.0,width=1.0]
Rectangle[length=5.6,width=7.8]
length is: 5.6
width is: 7.8
area is: 43.68
perimeter is: 26.80
22 class:

The expected output is:

Account[id=A101,name=Tan Ah Teck,balance=88]
Account[id=A102,name=Kumar,balance=0]
ID: A101 
Name: Tan Ah Teck
Balance: 88 
Account[id=A101,name=Tan Ah Teck,balance=188]
Account[id=A101,name=Tan Ah Teck,balance=138]
Amount exceeded balance
Account[id=A101,name=Tan Ah Teck,balance=138]
Account[id=A101,name=Tan Ah Teck,balance=38]
Account[id=A102,name=Kumar,balance=100]

Ex: The Date Class

A class called

Rectangle[length=1.2,width=3.4]
Rectangle[length=1.0,width=1.0]
Rectangle[length=5.6,width=7.8]
length is: 5.6
width is: 7.8
area is: 43.68
perimeter is: 26.80
33, which models a calendar date, is designed as shown in the following class diagram. Write the
Rectangle[length=1.2,width=3.4]
Rectangle[length=1.0,width=1.0]
Rectangle[length=5.6,width=7.8]
length is: 5.6
width is: 7.8
area is: 43.68
perimeter is: 26.80
33 class.

What kind of data is the colors of the cars around the gym in the scenario

Below is a test driver to test the

Rectangle[length=1.2,width=3.4]
Rectangle[length=1.0,width=1.0]
Rectangle[length=5.6,width=7.8]
length is: 5.6
width is: 7.8
area is: 43.68
perimeter is: 26.80
33 class:

The expected output is:

01/02/2014
09/12/2099
Month: 12
Day: 9
Year: 2099
03/04/2016

Ex: The Time Class

A class called

Rectangle[length=1.2,width=3.4]
Rectangle[length=1.0,width=1.0]
Rectangle[length=5.6,width=7.8]
length is: 5.6
width is: 7.8
area is: 43.68
perimeter is: 26.80
36, which models a time instance, is designed as shown in the following class diagram. The methods
Rectangle[length=1.2,width=3.4]
Rectangle[length=1.0,width=1.0]
Rectangle[length=5.6,width=7.8]
length is: 5.6
width is: 7.8
area is: 43.68
perimeter is: 26.80
37 and
Rectangle[length=1.2,width=3.4]
Rectangle[length=1.0,width=1.0]
Rectangle[length=5.6,width=7.8]
length is: 5.6
width is: 7.8
area is: 43.68
perimeter is: 26.80
38 shall advance or rewind this instance by one second, and return this instance, so as to support chaining operation such as
Rectangle[length=1.2,width=3.4]
Rectangle[length=1.0,width=1.0]
Rectangle[length=5.6,width=7.8]
length is: 5.6
width is: 7.8
area is: 43.68
perimeter is: 26.80
39. Write the
Rectangle[length=1.2,width=3.4]
Rectangle[length=1.0,width=1.0]
Rectangle[length=5.6,width=7.8]
length is: 5.6
width is: 7.8
area is: 43.68
perimeter is: 26.80
36 class.

What kind of data is the colors of the cars around the gym in the scenario

Below is a test driver for testing the

Rectangle[length=1.2,width=3.4]
Rectangle[length=1.0,width=1.0]
Rectangle[length=5.6,width=7.8]
length is: 5.6
width is: 7.8
area is: 43.68
perimeter is: 26.80
36 class:

The expected output is:

01:02:03
04:05:06
Hour: 4
Minute: 5
Second: 6
23:59:58
23:59:59
00:00:01
00:00:00
23:59:58

Ex: The Ball Class

A class called

Rectangle[length=1.2,width=3.4]
Rectangle[length=1.0,width=1.0]
Rectangle[length=5.6,width=7.8]
length is: 5.6
width is: 7.8
area is: 43.68
perimeter is: 26.80
42, which models a bouncing ball, is designed as shown in the following class diagram. It contains its radius, x and y position. Each move-step advances the x and y by delta-x and delta-y, respectively. delta-x and delta-y could be positive or negative. The
Rectangle[length=1.2,width=3.4]
Rectangle[length=1.0,width=1.0]
Rectangle[length=5.6,width=7.8]
length is: 5.6
width is: 7.8
area is: 43.68
perimeter is: 26.80
43 and
Rectangle[length=1.2,width=3.4]
Rectangle[length=1.0,width=1.0]
Rectangle[length=5.6,width=7.8]
length is: 5.6
width is: 7.8
area is: 43.68
perimeter is: 26.80
44 methods could be used to bounce the ball off the walls. Write the
Rectangle[length=1.2,width=3.4]
Rectangle[length=1.0,width=1.0]
Rectangle[length=5.6,width=7.8]
length is: 5.6
width is: 7.8
area is: 43.68
perimeter is: 26.80
42 class. Study the test driver on how the ball bounces.

What kind of data is the colors of the cars around the gym in the scenario

Below is a test driver:

The expected output is:

Ball[(1.1,2.2),speed=(3.3,4.4)]
Ball[(80.0,35.0),speed=(4.0,6.0)]
x is: 80.0
y is: 35.0
radius is: 5
xDelta is: 4.0
yDelta is: 6.0
Ball[(84.0,41.0),speed=(4.0,6.0)]
Ball[(88.0,47.0),speed=(4.0,6.0)]
Ball[(92.0,41.0),speed=(4.0,-6.0)]
Ball[(96.0,35.0),speed=(4.0,-6.0)]
Ball[(92.0,29.0),speed=(-4.0,-6.0)]
Ball[(88.0,23.0),speed=(-4.0,-6.0)]
Ball[(84.0,17.0),speed=(-4.0,-6.0)]
Ball[(80.0,11.0),speed=(-4.0,-6.0)]
Ball[(76.0,5.0),speed=(-4.0,-6.0)]
Ball[(72.0,-1.0),speed=(-4.0,-6.0)]
Ball[(68.0,5.0),speed=(-4.0,6.0)]
Ball[(64.0,11.0),speed=(-4.0,6.0)]
Ball[(60.0,17.0),speed=(-4.0,6.0)]
Ball[(56.0,23.0),speed=(-4.0,6.0)]
Ball[(52.0,29.0),speed=(-4.0,6.0)]

Try: Modify the constructor to take in speed and direction (in polar coordinates) instead of delta-x and delta-y (in cartesian coordinates), which is more convenient for the users.

public Ball(float x, float y, int radius, int speed, int directionInDegree)

Exercises on Composition

This first exercise shall lead you through all the concepts involved in OOP Composition.

What kind of data is the colors of the cars around the gym in the scenario

A class called

Rectangle[length=1.2,width=3.4]
Rectangle[length=1.0,width=1.0]
Rectangle[length=5.6,width=7.8]
length is: 5.6
width is: 7.8
area is: 43.68
perimeter is: 26.80
46 (as shown in the class diagram) is designed to model a book's author. It contains:

  • Three
    Account[id=A101,name=Tan Ah Teck,balance=88]
    Account[id=A102,name=Kumar,balance=0]
    ID: A101 
    Name: Tan Ah Teck
    Balance: 88 
    Account[id=A101,name=Tan Ah Teck,balance=188]
    Account[id=A101,name=Tan Ah Teck,balance=138]
    Amount exceeded balance
    Account[id=A101,name=Tan Ah Teck,balance=138]
    Account[id=A101,name=Tan Ah Teck,balance=38]
    Account[id=A102,name=Kumar,balance=100]
    0 instance variables:
    Rectangle[length=1.2,width=3.4]
    Rectangle[length=1.0,width=1.0]
    Rectangle[length=5.6,width=7.8]
    length is: 5.6
    width is: 7.8
    area is: 43.68
    perimeter is: 26.80
    48 (
    Account[id=A101,name=Tan Ah Teck,balance=88]
    Account[id=A102,name=Kumar,balance=0]
    ID: A101 
    Name: Tan Ah Teck
    Balance: 88 
    Account[id=A101,name=Tan Ah Teck,balance=188]
    Account[id=A101,name=Tan Ah Teck,balance=138]
    Amount exceeded balance
    Account[id=A101,name=Tan Ah Teck,balance=138]
    Account[id=A101,name=Tan Ah Teck,balance=38]
    Account[id=A102,name=Kumar,balance=100]
    4),
    Rectangle[length=1.2,width=3.4]
    Rectangle[length=1.0,width=1.0]
    Rectangle[length=5.6,width=7.8]
    length is: 5.6
    width is: 7.8
    area is: 43.68
    perimeter is: 26.80
    50 (
    Account[id=A101,name=Tan Ah Teck,balance=88]
    Account[id=A102,name=Kumar,balance=0]
    ID: A101 
    Name: Tan Ah Teck
    Balance: 88 
    Account[id=A101,name=Tan Ah Teck,balance=188]
    Account[id=A101,name=Tan Ah Teck,balance=138]
    Amount exceeded balance
    Account[id=A101,name=Tan Ah Teck,balance=138]
    Account[id=A101,name=Tan Ah Teck,balance=38]
    Account[id=A102,name=Kumar,balance=100]
    4), and
    Rectangle[length=1.2,width=3.4]
    Rectangle[length=1.0,width=1.0]
    Rectangle[length=5.6,width=7.8]
    length is: 5.6
    width is: 7.8
    area is: 43.68
    perimeter is: 26.80
    52 (
    Rectangle[length=1.2,width=3.4]
    Rectangle[length=1.0,width=1.0]
    Rectangle[length=5.6,width=7.8]
    length is: 5.6
    width is: 7.8
    area is: 43.68
    perimeter is: 26.80
    53 of either
    Rectangle[length=1.2,width=3.4]
    Rectangle[length=1.0,width=1.0]
    Rectangle[length=5.6,width=7.8]
    length is: 5.6
    width is: 7.8
    area is: 43.68
    perimeter is: 26.80
    54 or
    Rectangle[length=1.2,width=3.4]
    Rectangle[length=1.0,width=1.0]
    Rectangle[length=5.6,width=7.8]
    length is: 5.6
    width is: 7.8
    area is: 43.68
    perimeter is: 26.80
    55);
  • One constructor to initialize the
    Rectangle[length=1.2,width=3.4]
    Rectangle[length=1.0,width=1.0]
    Rectangle[length=5.6,width=7.8]
    length is: 5.6
    width is: 7.8
    area is: 43.68
    perimeter is: 26.80
    48,
    Rectangle[length=1.2,width=3.4]
    Rectangle[length=1.0,width=1.0]
    Rectangle[length=5.6,width=7.8]
    length is: 5.6
    width is: 7.8
    area is: 43.68
    perimeter is: 26.80
    50 and
    Rectangle[length=1.2,width=3.4]
    Rectangle[length=1.0,width=1.0]
    Rectangle[length=5.6,width=7.8]
    length is: 5.6
    width is: 7.8
    area is: 43.68
    perimeter is: 26.80
    52 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.)
  • Account[id=A101,name=Tan Ah Teck,balance=88]
    Account[id=A102,name=Kumar,balance=0]
    ID: A101 
    Name: Tan Ah Teck
    Balance: 88 
    Account[id=A101,name=Tan Ah Teck,balance=188]
    Account[id=A101,name=Tan Ah Teck,balance=138]
    Amount exceeded balance
    Account[id=A101,name=Tan Ah Teck,balance=138]
    Account[id=A101,name=Tan Ah Teck,balance=38]
    Account[id=A102,name=Kumar,balance=100]
    7 getters/setters:
    Rectangle[length=1.2,width=3.4]
    Rectangle[length=1.0,width=1.0]
    Rectangle[length=5.6,width=7.8]
    length is: 5.6
    width is: 7.8
    area is: 43.68
    perimeter is: 26.80
    60,
    Rectangle[length=1.2,width=3.4]
    Rectangle[length=1.0,width=1.0]
    Rectangle[length=5.6,width=7.8]
    length is: 5.6
    width is: 7.8
    area is: 43.68
    perimeter is: 26.80
    61,
    Rectangle[length=1.2,width=3.4]
    Rectangle[length=1.0,width=1.0]
    Rectangle[length=5.6,width=7.8]
    length is: 5.6
    width is: 7.8
    area is: 43.68
    perimeter is: 26.80
    62, and
    Rectangle[length=1.2,width=3.4]
    Rectangle[length=1.0,width=1.0]
    Rectangle[length=5.6,width=7.8]
    length is: 5.6
    width is: 7.8
    area is: 43.68
    perimeter is: 26.80
    63;
    (There are no setters for
    Rectangle[length=1.2,width=3.4]
    Rectangle[length=1.0,width=1.0]
    Rectangle[length=5.6,width=7.8]
    length is: 5.6
    width is: 7.8
    area is: 43.68
    perimeter is: 26.80
    48 and
    Rectangle[length=1.2,width=3.4]
    Rectangle[length=1.0,width=1.0]
    Rectangle[length=5.6,width=7.8]
    length is: 5.6
    width is: 7.8
    area is: 43.68
    perimeter is: 26.80
    52, as these attributes cannot be changed.)
  • A
    public Author (String name, String email, char gender) {......}
    5 method that returns "
    Rectangle[length=1.2,width=3.4]
    Rectangle[length=1.0,width=1.0]
    Rectangle[length=5.6,width=7.8]
    length is: 5.6
    width is: 7.8
    area is: 43.68
    perimeter is: 26.80
    67", e.g., "
    Rectangle[length=1.2,width=3.4]
    Rectangle[length=1.0,width=1.0]
    Rectangle[length=5.6,width=7.8]
    length is: 5.6
    width is: 7.8
    area is: 43.68
    perimeter is: 26.80
    68".

Write the

Rectangle[length=1.2,width=3.4]
Rectangle[length=1.0,width=1.0]
Rectangle[length=5.6,width=7.8]
length is: 5.6
width is: 7.8
area is: 43.68
perimeter is: 26.80
46 class. Also write a test driver called
Rectangle[length=1.2,width=3.4]
Rectangle[length=1.0,width=1.0]
Rectangle[length=5.6,width=7.8]
length is: 5.6
width is: 7.8
area is: 43.68
perimeter is: 26.80
70 to test all the
Account[id=A101,name=Tan Ah Teck,balance=88]
Account[id=A102,name=Kumar,balance=0]
ID: A101 
Name: Tan Ah Teck
Balance: 88 
Account[id=A101,name=Tan Ah Teck,balance=188]
Account[id=A101,name=Tan Ah Teck,balance=138]
Amount exceeded balance
Account[id=A101,name=Tan Ah Teck,balance=138]
Account[id=A101,name=Tan Ah Teck,balance=38]
Account[id=A102,name=Kumar,balance=100]
7 methods, e.g.,


What kind of data is the colors of the cars around the gym in the scenario

A class called

Rectangle[length=1.2,width=3.4]
Rectangle[length=1.0,width=1.0]
Rectangle[length=5.6,width=7.8]
length is: 5.6
width is: 7.8
area is: 43.68
perimeter is: 26.80
72 is designed (as shown in the class diagram) to model a book written by one author. It contains:

  • Four
    Account[id=A101,name=Tan Ah Teck,balance=88]
    Account[id=A102,name=Kumar,balance=0]
    ID: A101 
    Name: Tan Ah Teck
    Balance: 88 
    Account[id=A101,name=Tan Ah Teck,balance=188]
    Account[id=A101,name=Tan Ah Teck,balance=138]
    Amount exceeded balance
    Account[id=A101,name=Tan Ah Teck,balance=138]
    Account[id=A101,name=Tan Ah Teck,balance=38]
    Account[id=A102,name=Kumar,balance=100]
    0 instance variables:
    Rectangle[length=1.2,width=3.4]
    Rectangle[length=1.0,width=1.0]
    Rectangle[length=5.6,width=7.8]
    length is: 5.6
    width is: 7.8
    area is: 43.68
    perimeter is: 26.80
    48 (
    Account[id=A101,name=Tan Ah Teck,balance=88]
    Account[id=A102,name=Kumar,balance=0]
    ID: A101 
    Name: Tan Ah Teck
    Balance: 88 
    Account[id=A101,name=Tan Ah Teck,balance=188]
    Account[id=A101,name=Tan Ah Teck,balance=138]
    Amount exceeded balance
    Account[id=A101,name=Tan Ah Teck,balance=138]
    Account[id=A101,name=Tan Ah Teck,balance=38]
    Account[id=A102,name=Kumar,balance=100]
    4),
    Rectangle[length=1.2,width=3.4]
    Rectangle[length=1.0,width=1.0]
    Rectangle[length=5.6,width=7.8]
    length is: 5.6
    width is: 7.8
    area is: 43.68
    perimeter is: 26.80
    76 (of the class
    Rectangle[length=1.2,width=3.4]
    Rectangle[length=1.0,width=1.0]
    Rectangle[length=5.6,width=7.8]
    length is: 5.6
    width is: 7.8
    area is: 43.68
    perimeter is: 26.80
    46 you have just created, assume that a book has one and only one author),
    Rectangle[length=1.2,width=3.4]
    Rectangle[length=1.0,width=1.0]
    Rectangle[length=5.6,width=7.8]
    length is: 5.6
    width is: 7.8
    area is: 43.68
    perimeter is: 26.80
    78 (
    Account[id=A101,name=Tan Ah Teck,balance=88]
    Account[id=A102,name=Kumar,balance=0]
    ID: A101 
    Name: Tan Ah Teck
    Balance: 88 
    Account[id=A101,name=Tan Ah Teck,balance=188]
    Account[id=A101,name=Tan Ah Teck,balance=138]
    Amount exceeded balance
    Account[id=A101,name=Tan Ah Teck,balance=138]
    Account[id=A101,name=Tan Ah Teck,balance=38]
    Account[id=A102,name=Kumar,balance=100]
    2), and
    Rectangle[length=1.2,width=3.4]
    Rectangle[length=1.0,width=1.0]
    Rectangle[length=5.6,width=7.8]
    length is: 5.6
    width is: 7.8
    area is: 43.68
    perimeter is: 26.80
    80 (
    Rectangle[length=1.2,width=3.4]
    Rectangle[length=1.0,width=1.0]
    Rectangle[length=5.6,width=7.8]
    length is: 5.6
    width is: 7.8
    area is: 43.68
    perimeter is: 26.80
    81);
  • Two constructors:
    Rectangle[length=1.2,width=3.4]
    Rectangle[length=1.0,width=1.0]
    Rectangle[length=5.6,width=7.8]
    length is: 5.6
    width is: 7.8
    area is: 43.68
    perimeter is: 26.80
    0
  • public methods
    Rectangle[length=1.2,width=3.4]
    Rectangle[length=1.0,width=1.0]
    Rectangle[length=5.6,width=7.8]
    length is: 5.6
    width is: 7.8
    area is: 43.68
    perimeter is: 26.80
    60,
    Rectangle[length=1.2,width=3.4]
    Rectangle[length=1.0,width=1.0]
    Rectangle[length=5.6,width=7.8]
    length is: 5.6
    width is: 7.8
    area is: 43.68
    perimeter is: 26.80
    83,
    Rectangle[length=1.2,width=3.4]
    Rectangle[length=1.0,width=1.0]
    Rectangle[length=5.6,width=7.8]
    length is: 5.6
    width is: 7.8
    area is: 43.68
    perimeter is: 26.80
    84,
    Rectangle[length=1.2,width=3.4]
    Rectangle[length=1.0,width=1.0]
    Rectangle[length=5.6,width=7.8]
    length is: 5.6
    width is: 7.8
    area is: 43.68
    perimeter is: 26.80
    85,
    Rectangle[length=1.2,width=3.4]
    Rectangle[length=1.0,width=1.0]
    Rectangle[length=5.6,width=7.8]
    length is: 5.6
    width is: 7.8
    area is: 43.68
    perimeter is: 26.80
    86,
    Rectangle[length=1.2,width=3.4]
    Rectangle[length=1.0,width=1.0]
    Rectangle[length=5.6,width=7.8]
    length is: 5.6
    width is: 7.8
    area is: 43.68
    perimeter is: 26.80
    87.
  • A
    public Author (String name, String email, char gender) {......}
    5 that returns "
    Rectangle[length=1.2,width=3.4]
    Rectangle[length=1.0,width=1.0]
    Rectangle[length=5.6,width=7.8]
    length is: 5.6
    width is: 7.8
    area is: 43.68
    perimeter is: 26.80
    89".  You should reuse
    Rectangle[length=1.2,width=3.4]
    Rectangle[length=1.0,width=1.0]
    Rectangle[length=5.6,width=7.8]
    length is: 5.6
    width is: 7.8
    area is: 43.68
    perimeter is: 26.80
    46’s
    public Author (String name, String email, char gender) {......}
    5.

Write the

Rectangle[length=1.2,width=3.4]
Rectangle[length=1.0,width=1.0]
Rectangle[length=5.6,width=7.8]
length is: 5.6
width is: 7.8
area is: 43.68
perimeter is: 26.80
72 class (which uses the
Rectangle[length=1.2,width=3.4]
Rectangle[length=1.0,width=1.0]
Rectangle[length=5.6,width=7.8]
length is: 5.6
width is: 7.8
area is: 43.68
perimeter is: 26.80
46 class written earlier). Also write a test driver called
Rectangle[length=1.2,width=3.4]
Rectangle[length=1.0,width=1.0]
Rectangle[length=5.6,width=7.8]
length is: 5.6
width is: 7.8
area is: 43.68
perimeter is: 26.80
94 to test all the
Account[id=A101,name=Tan Ah Teck,balance=88]
Account[id=A102,name=Kumar,balance=0]
ID: A101 
Name: Tan Ah Teck
Balance: 88 
Account[id=A101,name=Tan Ah Teck,balance=188]
Account[id=A101,name=Tan Ah Teck,balance=138]
Amount exceeded balance
Account[id=A101,name=Tan Ah Teck,balance=138]
Account[id=A101,name=Tan Ah Teck,balance=38]
Account[id=A102,name=Kumar,balance=100]
7 methods in the class
Rectangle[length=1.2,width=3.4]
Rectangle[length=1.0,width=1.0]
Rectangle[length=5.6,width=7.8]
length is: 5.6
width is: 7.8
area is: 43.68
perimeter is: 26.80
72. Take Note that you have to construct an instance of
Rectangle[length=1.2,width=3.4]
Rectangle[length=1.0,width=1.0]
Rectangle[length=5.6,width=7.8]
length is: 5.6
width is: 7.8
area is: 43.68
perimeter is: 26.80
46 before you can construct an instance of
Rectangle[length=1.2,width=3.4]
Rectangle[length=1.0,width=1.0]
Rectangle[length=5.6,width=7.8]
length is: 5.6
width is: 7.8
area is: 43.68
perimeter is: 26.80
72. E.g.,

Take note that both

Rectangle[length=1.2,width=3.4]
Rectangle[length=1.0,width=1.0]
Rectangle[length=5.6,width=7.8]
length is: 5.6
width is: 7.8
area is: 43.68
perimeter is: 26.80
72 and
Rectangle[length=1.2,width=3.4]
Rectangle[length=1.0,width=1.0]
Rectangle[length=5.6,width=7.8]
length is: 5.6
width is: 7.8
area is: 43.68
perimeter is: 26.80
46 classes have a variable called
Rectangle[length=1.2,width=3.4]
Rectangle[length=1.0,width=1.0]
Rectangle[length=5.6,width=7.8]
length is: 5.6
width is: 7.8
area is: 43.68
perimeter is: 26.80
48. However, it can be differentiated via the referencing instance. For a
Rectangle[length=1.2,width=3.4]
Rectangle[length=1.0,width=1.0]
Rectangle[length=5.6,width=7.8]
length is: 5.6
width is: 7.8
area is: 43.68
perimeter is: 26.80
72 instance says
Employee[id=8,name=Peter Tan,salary=2500]
Employee[id=8,name=Peter Tan,salary=999]
id is: 8
firstname is: Peter
lastname is: Tan
salary is: 999
name is: Peter Tan
annual salary is: 11988
1098
Employee[id=8,name=Peter Tan,salary=1098]
03,
Employee[id=8,name=Peter Tan,salary=2500]
Employee[id=8,name=Peter Tan,salary=999]
id is: 8
firstname is: Peter
lastname is: Tan
salary is: 999
name is: Peter Tan
annual salary is: 11988
1098
Employee[id=8,name=Peter Tan,salary=1098]
04 refers to the
Rectangle[length=1.2,width=3.4]
Rectangle[length=1.0,width=1.0]
Rectangle[length=5.6,width=7.8]
length is: 5.6
width is: 7.8
area is: 43.68
perimeter is: 26.80
48 of the book; whereas for an
Rectangle[length=1.2,width=3.4]
Rectangle[length=1.0,width=1.0]
Rectangle[length=5.6,width=7.8]
length is: 5.6
width is: 7.8
area is: 43.68
perimeter is: 26.80
46's instance say
Employee[id=8,name=Peter Tan,salary=2500]
Employee[id=8,name=Peter Tan,salary=999]
id is: 8
firstname is: Peter
lastname is: Tan
salary is: 999
name is: Peter Tan
annual salary is: 11988
1098
Employee[id=8,name=Peter Tan,salary=1098]
07,
Employee[id=8,name=Peter Tan,salary=2500]
Employee[id=8,name=Peter Tan,salary=999]
id is: 8
firstname is: Peter
lastname is: Tan
salary is: 999
name is: Peter Tan
annual salary is: 11988
1098
Employee[id=8,name=Peter Tan,salary=1098]
08 refers to the
Rectangle[length=1.2,width=3.4]
Rectangle[length=1.0,width=1.0]
Rectangle[length=5.6,width=7.8]
length is: 5.6
width is: 7.8
area is: 43.68
perimeter is: 26.80
48 of the author. There is no need (and not recommended) to call the variables
Employee[id=8,name=Peter Tan,salary=2500]
Employee[id=8,name=Peter Tan,salary=999]
id is: 8
firstname is: Peter
lastname is: Tan
salary is: 999
name is: Peter Tan
annual salary is: 11988
1098
Employee[id=8,name=Peter Tan,salary=1098]
10 and
Employee[id=8,name=Peter Tan,salary=2500]
Employee[id=8,name=Peter Tan,salary=999]
id is: 8
firstname is: Peter
lastname is: Tan
salary is: 999
name is: Peter Tan
annual salary is: 11988
1098
Employee[id=8,name=Peter Tan,salary=1098]
11.

TRY:

  1. Printing the
    Rectangle[length=1.2,width=3.4]
    Rectangle[length=1.0,width=1.0]
    Rectangle[length=5.6,width=7.8]
    length is: 5.6
    width is: 7.8
    area is: 43.68
    perimeter is: 26.80
    48 and
    Rectangle[length=1.2,width=3.4]
    Rectangle[length=1.0,width=1.0]
    Rectangle[length=5.6,width=7.8]
    length is: 5.6
    width is: 7.8
    area is: 43.68
    perimeter is: 26.80
    50 of the author from a
    Rectangle[length=1.2,width=3.4]
    Rectangle[length=1.0,width=1.0]
    Rectangle[length=5.6,width=7.8]
    length is: 5.6
    width is: 7.8
    area is: 43.68
    perimeter is: 26.80
    72 instance. (Hint:
    Employee[id=8,name=Peter Tan,salary=2500]
    Employee[id=8,name=Peter Tan,salary=999]
    id is: 8
    firstname is: Peter
    lastname is: Tan
    salary is: 999
    name is: Peter Tan
    annual salary is: 11988
    1098
    Employee[id=8,name=Peter Tan,salary=1098]
    15,
    Employee[id=8,name=Peter Tan,salary=2500]
    Employee[id=8,name=Peter Tan,salary=999]
    id is: 8
    firstname is: Peter
    lastname is: Tan
    salary is: 999
    name is: Peter Tan
    annual salary is: 11988
    1098
    Employee[id=8,name=Peter Tan,salary=1098]
    16).
  2. Introduce new methods called
    Employee[id=8,name=Peter Tan,salary=2500]
    Employee[id=8,name=Peter Tan,salary=999]
    id is: 8
    firstname is: Peter
    lastname is: Tan
    salary is: 999
    name is: Peter Tan
    annual salary is: 11988
    1098
    Employee[id=8,name=Peter Tan,salary=1098]
    17,
    Employee[id=8,name=Peter Tan,salary=2500]
    Employee[id=8,name=Peter Tan,salary=999]
    id is: 8
    firstname is: Peter
    lastname is: Tan
    salary is: 999
    name is: Peter Tan
    annual salary is: 11988
    1098
    Employee[id=8,name=Peter Tan,salary=1098]
    18,
    Employee[id=8,name=Peter Tan,salary=2500]
    Employee[id=8,name=Peter Tan,salary=999]
    id is: 8
    firstname is: Peter
    lastname is: Tan
    salary is: 999
    name is: Peter Tan
    annual salary is: 11988
    1098
    Employee[id=8,name=Peter Tan,salary=1098]
    19 in the
    Rectangle[length=1.2,width=3.4]
    Rectangle[length=1.0,width=1.0]
    Rectangle[length=5.6,width=7.8]
    length is: 5.6
    width is: 7.8
    area is: 43.68
    perimeter is: 26.80
    72 class to return the
    Rectangle[length=1.2,width=3.4]
    Rectangle[length=1.0,width=1.0]
    Rectangle[length=5.6,width=7.8]
    length is: 5.6
    width is: 7.8
    area is: 43.68
    perimeter is: 26.80
    48,
    Rectangle[length=1.2,width=3.4]
    Rectangle[length=1.0,width=1.0]
    Rectangle[length=5.6,width=7.8]
    length is: 5.6
    width is: 7.8
    area is: 43.68
    perimeter is: 26.80
    50 and
    Rectangle[length=1.2,width=3.4]
    Rectangle[length=1.0,width=1.0]
    Rectangle[length=5.6,width=7.8]
    length is: 5.6
    width is: 7.8
    area is: 43.68
    perimeter is: 26.80
    52 of the author of the book. For example,

(Advanced) The Author and Book Classes Again - An Array of Objects as an Instance Variable

What kind of data is the colors of the cars around the gym in the scenario

In the earlier exercise, a book is written by one and only one author. In reality, a book can be written by one or more author. Modify the

Rectangle[length=1.2,width=3.4]
Rectangle[length=1.0,width=1.0]
Rectangle[length=5.6,width=7.8]
length is: 5.6
width is: 7.8
area is: 43.68
perimeter is: 26.80
72 class to support one or more authors by changing the instance variable
Employee[id=8,name=Peter Tan,salary=2500]
Employee[id=8,name=Peter Tan,salary=999]
id is: 8
firstname is: Peter
lastname is: Tan
salary is: 999
name is: Peter Tan
annual salary is: 11988
1098
Employee[id=8,name=Peter Tan,salary=1098]
25 to an
Rectangle[length=1.2,width=3.4]
Rectangle[length=1.0,width=1.0]
Rectangle[length=5.6,width=7.8]
length is: 5.6
width is: 7.8
area is: 43.68
perimeter is: 26.80
46 array.

Notes:

  • The constructors take an array of
    Rectangle[length=1.2,width=3.4]
    Rectangle[length=1.0,width=1.0]
    Rectangle[length=5.6,width=7.8]
    length is: 5.6
    width is: 7.8
    area is: 43.68
    perimeter is: 26.80
    46 (i.e.,
    Employee[id=8,name=Peter Tan,salary=2500]
    Employee[id=8,name=Peter Tan,salary=999]
    id is: 8
    firstname is: Peter
    lastname is: Tan
    salary is: 999
    name is: Peter Tan
    annual salary is: 11988
    1098
    Employee[id=8,name=Peter Tan,salary=1098]
    28), instead of an
    Rectangle[length=1.2,width=3.4]
    Rectangle[length=1.0,width=1.0]
    Rectangle[length=5.6,width=7.8]
    length is: 5.6
    width is: 7.8
    area is: 43.68
    perimeter is: 26.80
    46 instance. In this design, once a
    Rectangle[length=1.2,width=3.4]
    Rectangle[length=1.0,width=1.0]
    Rectangle[length=5.6,width=7.8]
    length is: 5.6
    width is: 7.8
    area is: 43.68
    perimeter is: 26.80
    72 instance is constructor, you cannot add or remove author.
  • The
    public Author (String name, String email, char gender) {......}
    5 method shall return "
    Employee[id=8,name=Peter Tan,salary=2500]
    Employee[id=8,name=Peter Tan,salary=999]
    id is: 8
    firstname is: Peter
    lastname is: Tan
    salary is: 999
    name is: Peter Tan
    annual salary is: 11988
    1098
    Employee[id=8,name=Peter Tan,salary=1098]
    32".

You are required to:

  1. Write the code for the
    Rectangle[length=1.2,width=3.4]
    Rectangle[length=1.0,width=1.0]
    Rectangle[length=5.6,width=7.8]
    length is: 5.6
    width is: 7.8
    area is: 43.68
    perimeter is: 26.80
    72 class. You shall re-use the
    Rectangle[length=1.2,width=3.4]
    Rectangle[length=1.0,width=1.0]
    Rectangle[length=5.6,width=7.8]
    length is: 5.6
    width is: 7.8
    area is: 43.68
    perimeter is: 26.80
    46 class written earlier.
  2. Write a test driver (called
    Rectangle[length=1.2,width=3.4]
    Rectangle[length=1.0,width=1.0]
    Rectangle[length=5.6,width=7.8]
    length is: 5.6
    width is: 7.8
    area is: 43.68
    perimeter is: 26.80
    94) to test the
    Rectangle[length=1.2,width=3.4]
    Rectangle[length=1.0,width=1.0]
    Rectangle[length=5.6,width=7.8]
    length is: 5.6
    width is: 7.8
    area is: 43.68
    perimeter is: 26.80
    72 class.

Hints:

Ex: The Author and Book Classes - Your Turn

A class called

Rectangle[length=1.2,width=3.4]
Rectangle[length=1.0,width=1.0]
Rectangle[length=5.6,width=7.8]
length is: 5.6
width is: 7.8
area is: 43.68
perimeter is: 26.80
46, which models an author of a book, is designed as shown in the class diagram. A class called
Rectangle[length=1.2,width=3.4]
Rectangle[length=1.0,width=1.0]
Rectangle[length=5.6,width=7.8]
length is: 5.6
width is: 7.8
area is: 43.68
perimeter is: 26.80
72, which models a book written by ONE author and composes an instance of
Rectangle[length=1.2,width=3.4]
Rectangle[length=1.0,width=1.0]
Rectangle[length=5.6,width=7.8]
length is: 5.6
width is: 7.8
area is: 43.68
perimeter is: 26.80
46 as its instance variable, is also shown. Write the
Rectangle[length=1.2,width=3.4]
Rectangle[length=1.0,width=1.0]
Rectangle[length=5.6,width=7.8]
length is: 5.6
width is: 7.8
area is: 43.68
perimeter is: 26.80
46 and
Rectangle[length=1.2,width=3.4]
Rectangle[length=1.0,width=1.0]
Rectangle[length=5.6,width=7.8]
length is: 5.6
width is: 7.8
area is: 43.68
perimeter is: 26.80
72 classes.

What kind of data is the colors of the cars around the gym in the scenario
What kind of data is the colors of the cars around the gym in the scenario

Below is a test driver:

The expected output is:

Rectangle[length=1.2,width=3.4]
Rectangle[length=1.0,width=1.0]
Rectangle[length=5.6,width=7.8]
length is: 5.6
width is: 7.8
area is: 43.68
perimeter is: 26.80
1

Ex: The Customer and Invoice classes

A class called

Employee[id=8,name=Peter Tan,salary=2500]
Employee[id=8,name=Peter Tan,salary=999]
id is: 8
firstname is: Peter
lastname is: Tan
salary is: 999
name is: Peter Tan
annual salary is: 11988
1098
Employee[id=8,name=Peter Tan,salary=1098]
42, which models a customer in a transaction, is designed as shown in the class diagram. A class called
Employee[id=8,name=Peter Tan,salary=2500]
Employee[id=8,name=Peter Tan,salary=999]
id is: 8
firstname is: Peter
lastname is: Tan
salary is: 999
name is: Peter Tan
annual salary is: 11988
1098
Employee[id=8,name=Peter Tan,salary=1098]
43, which models an invoice for a particular customer and composes an instance of
Employee[id=8,name=Peter Tan,salary=2500]
Employee[id=8,name=Peter Tan,salary=999]
id is: 8
firstname is: Peter
lastname is: Tan
salary is: 999
name is: Peter Tan
annual salary is: 11988
1098
Employee[id=8,name=Peter Tan,salary=1098]
42 as its instance variable, is also shown. Write the
Employee[id=8,name=Peter Tan,salary=2500]
Employee[id=8,name=Peter Tan,salary=999]
id is: 8
firstname is: Peter
lastname is: Tan
salary is: 999
name is: Peter Tan
annual salary is: 11988
1098
Employee[id=8,name=Peter Tan,salary=1098]
42 and
Employee[id=8,name=Peter Tan,salary=2500]
Employee[id=8,name=Peter Tan,salary=999]
id is: 8
firstname is: Peter
lastname is: Tan
salary is: 999
name is: Peter Tan
annual salary is: 11988
1098
Employee[id=8,name=Peter Tan,salary=1098]
43 classes.

What kind of data is the colors of the cars around the gym in the scenario
What kind of data is the colors of the cars around the gym in the scenario

Below is a test driver:

The expected output is:

Rectangle[length=1.2,width=3.4]
Rectangle[length=1.0,width=1.0]
Rectangle[length=5.6,width=7.8]
length is: 5.6
width is: 7.8
area is: 43.68
perimeter is: 26.80
2

Ex: The Customer and Account classes

What kind of data is the colors of the cars around the gym in the scenario

The

Employee[id=8,name=Peter Tan,salary=2500]
Employee[id=8,name=Peter Tan,salary=999]
id is: 8
firstname is: Peter
lastname is: Tan
salary is: 999
name is: Peter Tan
annual salary is: 11988
1098
Employee[id=8,name=Peter Tan,salary=1098]
42 class models a customer is design as shown in the class diagram. Write the codes for the
Employee[id=8,name=Peter Tan,salary=2500]
Employee[id=8,name=Peter Tan,salary=999]
id is: 8
firstname is: Peter
lastname is: Tan
salary is: 999
name is: Peter Tan
annual salary is: 11988
1098
Employee[id=8,name=Peter Tan,salary=1098]
42 class and a test driver to test all the
Account[id=A101,name=Tan Ah Teck,balance=88]
Account[id=A102,name=Kumar,balance=0]
ID: A101 
Name: Tan Ah Teck
Balance: 88 
Account[id=A101,name=Tan Ah Teck,balance=188]
Account[id=A101,name=Tan Ah Teck,balance=138]
Amount exceeded balance
Account[id=A101,name=Tan Ah Teck,balance=138]
Account[id=A101,name=Tan Ah Teck,balance=38]
Account[id=A102,name=Kumar,balance=100]
7 methods.

What kind of data is the colors of the cars around the gym in the scenario

The

Rectangle[length=1.2,width=3.4]
Rectangle[length=1.0,width=1.0]
Rectangle[length=5.6,width=7.8]
length is: 5.6
width is: 7.8
area is: 43.68
perimeter is: 26.80
22 class models a bank account, design as shown in the class diagram, composes a
Employee[id=8,name=Peter Tan,salary=2500]
Employee[id=8,name=Peter Tan,salary=999]
id is: 8
firstname is: Peter
lastname is: Tan
salary is: 999
name is: Peter Tan
annual salary is: 11988
1098
Employee[id=8,name=Peter Tan,salary=1098]
42 instance (written earlier) as its member. Write the codes for the
Rectangle[length=1.2,width=3.4]
Rectangle[length=1.0,width=1.0]
Rectangle[length=5.6,width=7.8]
length is: 5.6
width is: 7.8
area is: 43.68
perimeter is: 26.80
22 class and a test driver to test all the
Account[id=A101,name=Tan Ah Teck,balance=88]
Account[id=A102,name=Kumar,balance=0]
ID: A101 
Name: Tan Ah Teck
Balance: 88 
Account[id=A101,name=Tan Ah Teck,balance=188]
Account[id=A101,name=Tan Ah Teck,balance=138]
Amount exceeded balance
Account[id=A101,name=Tan Ah Teck,balance=138]
Account[id=A101,name=Tan Ah Teck,balance=38]
Account[id=A102,name=Kumar,balance=100]
7 methods.

Ex: The MyPoint Class

A class called

Employee[id=8,name=Peter Tan,salary=2500]
Employee[id=8,name=Peter Tan,salary=999]
id is: 8
firstname is: Peter
lastname is: Tan
salary is: 999
name is: Peter Tan
annual salary is: 11988
1098
Employee[id=8,name=Peter Tan,salary=1098]
54, which models a 2D point with x and y coordinates, is designed as shown in the class diagram.

What kind of data is the colors of the cars around the gym in the scenario

It contains:

  • Two instance variables
    Employee[id=8,name=Peter Tan,salary=2500]
    Employee[id=8,name=Peter Tan,salary=999]
    id is: 8
    firstname is: Peter
    lastname is: Tan
    salary is: 999
    name is: Peter Tan
    annual salary is: 11988
    1098
    Employee[id=8,name=Peter Tan,salary=1098]
    55 (
    Rectangle[length=1.2,width=3.4]
    Rectangle[length=1.0,width=1.0]
    Rectangle[length=5.6,width=7.8]
    length is: 5.6
    width is: 7.8
    area is: 43.68
    perimeter is: 26.80
    81) and
    Employee[id=8,name=Peter Tan,salary=2500]
    Employee[id=8,name=Peter Tan,salary=999]
    id is: 8
    firstname is: Peter
    lastname is: Tan
    salary is: 999
    name is: Peter Tan
    annual salary is: 11988
    1098
    Employee[id=8,name=Peter Tan,salary=1098]
    57 (
    Rectangle[length=1.2,width=3.4]
    Rectangle[length=1.0,width=1.0]
    Rectangle[length=5.6,width=7.8]
    length is: 5.6
    width is: 7.8
    area is: 43.68
    perimeter is: 26.80
    81).
  • A default (or "no-argument" or "no-arg") constructor that construct a point at the default location of
    Employee[id=8,name=Peter Tan,salary=2500]
    Employee[id=8,name=Peter Tan,salary=999]
    id is: 8
    firstname is: Peter
    lastname is: Tan
    salary is: 999
    name is: Peter Tan
    annual salary is: 11988
    1098
    Employee[id=8,name=Peter Tan,salary=1098]
    59.
  • A overloaded constructor that constructs a point with the given
    Employee[id=8,name=Peter Tan,salary=2500]
    Employee[id=8,name=Peter Tan,salary=999]
    id is: 8
    firstname is: Peter
    lastname is: Tan
    salary is: 999
    name is: Peter Tan
    annual salary is: 11988
    1098
    Employee[id=8,name=Peter Tan,salary=1098]
    55 and
    Employee[id=8,name=Peter Tan,salary=2500]
    Employee[id=8,name=Peter Tan,salary=999]
    id is: 8
    firstname is: Peter
    lastname is: Tan
    salary is: 999
    name is: Peter Tan
    annual salary is: 11988
    1098
    Employee[id=8,name=Peter Tan,salary=1098]
    57 coordinates.
  • Getter and setter for the instance variables
    Employee[id=8,name=Peter Tan,salary=2500]
    Employee[id=8,name=Peter Tan,salary=999]
    id is: 8
    firstname is: Peter
    lastname is: Tan
    salary is: 999
    name is: Peter Tan
    annual salary is: 11988
    1098
    Employee[id=8,name=Peter Tan,salary=1098]
    55 and
    Employee[id=8,name=Peter Tan,salary=2500]
    Employee[id=8,name=Peter Tan,salary=999]
    id is: 8
    firstname is: Peter
    lastname is: Tan
    salary is: 999
    name is: Peter Tan
    annual salary is: 11988
    1098
    Employee[id=8,name=Peter Tan,salary=1098]
    57.
  • A method
    Employee[id=8,name=Peter Tan,salary=2500]
    Employee[id=8,name=Peter Tan,salary=999]
    id is: 8
    firstname is: Peter
    lastname is: Tan
    salary is: 999
    name is: Peter Tan
    annual salary is: 11988
    1098
    Employee[id=8,name=Peter Tan,salary=1098]
    64 to set both
    Employee[id=8,name=Peter Tan,salary=2500]
    Employee[id=8,name=Peter Tan,salary=999]
    id is: 8
    firstname is: Peter
    lastname is: Tan
    salary is: 999
    name is: Peter Tan
    annual salary is: 11988
    1098
    Employee[id=8,name=Peter Tan,salary=1098]
    55 and
    Employee[id=8,name=Peter Tan,salary=2500]
    Employee[id=8,name=Peter Tan,salary=999]
    id is: 8
    firstname is: Peter
    lastname is: Tan
    salary is: 999
    name is: Peter Tan
    annual salary is: 11988
    1098
    Employee[id=8,name=Peter Tan,salary=1098]
    57.
  • A method
    Employee[id=8,name=Peter Tan,salary=2500]
    Employee[id=8,name=Peter Tan,salary=999]
    id is: 8
    firstname is: Peter
    lastname is: Tan
    salary is: 999
    name is: Peter Tan
    annual salary is: 11988
    1098
    Employee[id=8,name=Peter Tan,salary=1098]
    67 which returns the x and y in a 2-element
    Rectangle[length=1.2,width=3.4]
    Rectangle[length=1.0,width=1.0]
    Rectangle[length=5.6,width=7.8]
    length is: 5.6
    width is: 7.8
    area is: 43.68
    perimeter is: 26.80
    81 array.
  • A
    public Author (String name, String email, char gender) {......}
    5 method that returns a string description of the instance in the format "
    Employee[id=8,name=Peter Tan,salary=2500]
    Employee[id=8,name=Peter Tan,salary=999]
    id is: 8
    firstname is: Peter
    lastname is: Tan
    salary is: 999
    name is: Peter Tan
    annual salary is: 11988
    1098
    Employee[id=8,name=Peter Tan,salary=1098]
    70".
  • A method called
    Employee[id=8,name=Peter Tan,salary=2500]
    Employee[id=8,name=Peter Tan,salary=999]
    id is: 8
    firstname is: Peter
    lastname is: Tan
    salary is: 999
    name is: Peter Tan
    annual salary is: 11988
    1098
    Employee[id=8,name=Peter Tan,salary=1098]
    71 that returns the distance from this point to another point at the given
    Employee[id=8,name=Peter Tan,salary=2500]
    Employee[id=8,name=Peter Tan,salary=999]
    id is: 8
    firstname is: Peter
    lastname is: Tan
    salary is: 999
    name is: Peter Tan
    annual salary is: 11988
    1098
    Employee[id=8,name=Peter Tan,salary=1098]
    72 coordinates, e.g.,
    Rectangle[length=1.2,width=3.4]
    Rectangle[length=1.0,width=1.0]
    Rectangle[length=5.6,width=7.8]
    length is: 5.6
    width is: 7.8
    area is: 43.68
    perimeter is: 26.80
    3
  • An overloaded
    Employee[id=8,name=Peter Tan,salary=2500]
    Employee[id=8,name=Peter Tan,salary=999]
    id is: 8
    firstname is: Peter
    lastname is: Tan
    salary is: 999
    name is: Peter Tan
    annual salary is: 11988
    1098
    Employee[id=8,name=Peter Tan,salary=1098]
    73 that returns the distance from this point to the given
    Employee[id=8,name=Peter Tan,salary=2500]
    Employee[id=8,name=Peter Tan,salary=999]
    id is: 8
    firstname is: Peter
    lastname is: Tan
    salary is: 999
    name is: Peter Tan
    annual salary is: 11988
    1098
    Employee[id=8,name=Peter Tan,salary=1098]
    54 instance (called
    Employee[id=8,name=Peter Tan,salary=2500]
    Employee[id=8,name=Peter Tan,salary=999]
    id is: 8
    firstname is: Peter
    lastname is: Tan
    salary is: 999
    name is: Peter Tan
    annual salary is: 11988
    1098
    Employee[id=8,name=Peter Tan,salary=1098]
    75), e.g.,
    Rectangle[length=1.2,width=3.4]
    Rectangle[length=1.0,width=1.0]
    Rectangle[length=5.6,width=7.8]
    length is: 5.6
    width is: 7.8
    area is: 43.68
    perimeter is: 26.80
    4
  • Another overloaded
    Employee[id=8,name=Peter Tan,salary=2500]
    Employee[id=8,name=Peter Tan,salary=999]
    id is: 8
    firstname is: Peter
    lastname is: Tan
    salary is: 999
    name is: Peter Tan
    annual salary is: 11988
    1098
    Employee[id=8,name=Peter Tan,salary=1098]
    76 method that returns the distance from
    public Author (String name, String email, char gender) {......}
    1 point to the origin
    Employee[id=8,name=Peter Tan,salary=2500]
    Employee[id=8,name=Peter Tan,salary=999]
    id is: 8
    firstname is: Peter
    lastname is: Tan
    salary is: 999
    name is: Peter Tan
    annual salary is: 11988
    1098
    Employee[id=8,name=Peter Tan,salary=1098]
    78, e.g.,
    Rectangle[length=1.2,width=3.4]
    Rectangle[length=1.0,width=1.0]
    Rectangle[length=5.6,width=7.8]
    length is: 5.6
    width is: 7.8
    area is: 43.68
    perimeter is: 26.80
    5

You are required to:

  1. Write the code for the class
    Employee[id=8,name=Peter Tan,salary=2500]
    Employee[id=8,name=Peter Tan,salary=999]
    id is: 8
    firstname is: Peter
    lastname is: Tan
    salary is: 999
    name is: Peter Tan
    annual salary is: 11988
    1098
    Employee[id=8,name=Peter Tan,salary=1098]
    54. Also write a test program (called
    Employee[id=8,name=Peter Tan,salary=2500]
    Employee[id=8,name=Peter Tan,salary=999]
    id is: 8
    firstname is: Peter
    lastname is: Tan
    salary is: 999
    name is: Peter Tan
    annual salary is: 11988
    1098
    Employee[id=8,name=Peter Tan,salary=1098]
    80) to test all the methods defined in the class.
    Hints:
  2. Write a program that allocates
    Employee[id=8,name=Peter Tan,salary=2500]
    Employee[id=8,name=Peter Tan,salary=999]
    id is: 8
    firstname is: Peter
    lastname is: Tan
    salary is: 999
    name is: Peter Tan
    annual salary is: 11988
    1098
    Employee[id=8,name=Peter Tan,salary=1098]
    81 points in an array of
    Employee[id=8,name=Peter Tan,salary=2500]
    Employee[id=8,name=Peter Tan,salary=999]
    id is: 8
    firstname is: Peter
    lastname is: Tan
    salary is: 999
    name is: Peter Tan
    annual salary is: 11988
    1098
    Employee[id=8,name=Peter Tan,salary=1098]
    54, and initializes to
    Employee[id=8,name=Peter Tan,salary=2500]
    Employee[id=8,name=Peter Tan,salary=999]
    id is: 8
    firstname is: Peter
    lastname is: Tan
    salary is: 999
    name is: Peter Tan
    annual salary is: 11988
    1098
    Employee[id=8,name=Peter Tan,salary=1098]
    83,
    Employee[id=8,name=Peter Tan,salary=2500]
    Employee[id=8,name=Peter Tan,salary=999]
    id is: 8
    firstname is: Peter
    lastname is: Tan
    salary is: 999
    name is: Peter Tan
    annual salary is: 11988
    1098
    Employee[id=8,name=Peter Tan,salary=1098]
    84, ...
    Employee[id=8,name=Peter Tan,salary=2500]
    Employee[id=8,name=Peter Tan,salary=999]
    id is: 8
    firstname is: Peter
    lastname is: Tan
    salary is: 999
    name is: Peter Tan
    annual salary is: 11988
    1098
    Employee[id=8,name=Peter Tan,salary=1098]
    85.
    Hints: You need to allocate the array, as well as each of the 10
    Employee[id=8,name=Peter Tan,salary=2500]
    Employee[id=8,name=Peter Tan,salary=999]
    id is: 8
    firstname is: Peter
    lastname is: Tan
    salary is: 999
    name is: Peter Tan
    annual salary is: 11988
    1098
    Employee[id=8,name=Peter Tan,salary=1098]
    54 instances.  In other words, you need to issue 11
    Employee[id=8,name=Peter Tan,salary=2500]
    Employee[id=8,name=Peter Tan,salary=999]
    id is: 8
    firstname is: Peter
    lastname is: Tan
    salary is: 999
    name is: Peter Tan
    annual salary is: 11988
    1098
    Employee[id=8,name=Peter Tan,salary=1098]
    87, 1 for the array and 10 for the
    Employee[id=8,name=Peter Tan,salary=2500]
    Employee[id=8,name=Peter Tan,salary=999]
    id is: 8
    firstname is: Peter
    lastname is: Tan
    salary is: 999
    name is: Peter Tan
    annual salary is: 11988
    1098
    Employee[id=8,name=Peter Tan,salary=1098]
    54 instances.

Notes: Point is such a common entity that JDK certainly provided for in all flavors.

Ex: The MyLine and MyPoint Classes

A class called

Employee[id=8,name=Peter Tan,salary=2500]
Employee[id=8,name=Peter Tan,salary=999]
id is: 8
firstname is: Peter
lastname is: Tan
salary is: 999
name is: Peter Tan
annual salary is: 11988
1098
Employee[id=8,name=Peter Tan,salary=1098]
89, which models a line with a begin point at (x1, y1) and an end point at (x2, y2), is designed as shown in the class diagram. The
Employee[id=8,name=Peter Tan,salary=2500]
Employee[id=8,name=Peter Tan,salary=999]
id is: 8
firstname is: Peter
lastname is: Tan
salary is: 999
name is: Peter Tan
annual salary is: 11988
1098
Employee[id=8,name=Peter Tan,salary=1098]
89 class uses two
Employee[id=8,name=Peter Tan,salary=2500]
Employee[id=8,name=Peter Tan,salary=999]
id is: 8
firstname is: Peter
lastname is: Tan
salary is: 999
name is: Peter Tan
annual salary is: 11988
1098
Employee[id=8,name=Peter Tan,salary=1098]
54 instances (written in the earlier exercise) as its begin and end points. Write the
Employee[id=8,name=Peter Tan,salary=2500]
Employee[id=8,name=Peter Tan,salary=999]
id is: 8
firstname is: Peter
lastname is: Tan
salary is: 999
name is: Peter Tan
annual salary is: 11988
1098
Employee[id=8,name=Peter Tan,salary=1098]
89 class. Also write a test driver to test all the public methods in the
Employee[id=8,name=Peter Tan,salary=2500]
Employee[id=8,name=Peter Tan,salary=999]
id is: 8
firstname is: Peter
lastname is: Tan
salary is: 999
name is: Peter Tan
annual salary is: 11988
1098
Employee[id=8,name=Peter Tan,salary=1098]
89 class.

What kind of data is the colors of the cars around the gym in the scenario

Ex: The MyCircle and MyPoint Classes

A class called

Employee[id=8,name=Peter Tan,salary=2500]
Employee[id=8,name=Peter Tan,salary=999]
id is: 8
firstname is: Peter
lastname is: Tan
salary is: 999
name is: Peter Tan
annual salary is: 11988
1098
Employee[id=8,name=Peter Tan,salary=1098]
94, which models a circle with a center and a radius, is designed as shown in the class diagram. The
Employee[id=8,name=Peter Tan,salary=2500]
Employee[id=8,name=Peter Tan,salary=999]
id is: 8
firstname is: Peter
lastname is: Tan
salary is: 999
name is: Peter Tan
annual salary is: 11988
1098
Employee[id=8,name=Peter Tan,salary=1098]
94 class uses a
Employee[id=8,name=Peter Tan,salary=2500]
Employee[id=8,name=Peter Tan,salary=999]
id is: 8
firstname is: Peter
lastname is: Tan
salary is: 999
name is: Peter Tan
annual salary is: 11988
1098
Employee[id=8,name=Peter Tan,salary=1098]
54 instance (written in the earlier exercise) as its center.

What kind of data is the colors of the cars around the gym in the scenario

The class contains:

  • Two
    Account[id=A101,name=Tan Ah Teck,balance=88]
    Account[id=A102,name=Kumar,balance=0]
    ID: A101 
    Name: Tan Ah Teck
    Balance: 88 
    Account[id=A101,name=Tan Ah Teck,balance=188]
    Account[id=A101,name=Tan Ah Teck,balance=138]
    Amount exceeded balance
    Account[id=A101,name=Tan Ah Teck,balance=138]
    Account[id=A101,name=Tan Ah Teck,balance=38]
    Account[id=A102,name=Kumar,balance=100]
    0 instance variables:
    Employee[id=8,name=Peter Tan,salary=2500]
    Employee[id=8,name=Peter Tan,salary=999]
    id is: 8
    firstname is: Peter
    lastname is: Tan
    salary is: 999
    name is: Peter Tan
    annual salary is: 11988
    1098
    Employee[id=8,name=Peter Tan,salary=1098]
    98 (an instance of
    Employee[id=8,name=Peter Tan,salary=2500]
    Employee[id=8,name=Peter Tan,salary=999]
    id is: 8
    firstname is: Peter
    lastname is: Tan
    salary is: 999
    name is: Peter Tan
    annual salary is: 11988
    1098
    Employee[id=8,name=Peter Tan,salary=1098]
    54) and
    Account[id=A101,name=Tan Ah Teck,balance=88]
    Account[id=A102,name=Kumar,balance=0]
    ID: A101 
    Name: Tan Ah Teck
    Balance: 88 
    Account[id=A101,name=Tan Ah Teck,balance=188]
    Account[id=A101,name=Tan Ah Teck,balance=138]
    Amount exceeded balance
    Account[id=A101,name=Tan Ah Teck,balance=138]
    Account[id=A101,name=Tan Ah Teck,balance=38]
    Account[id=A102,name=Kumar,balance=100]
    1 (
    Rectangle[length=1.2,width=3.4]
    Rectangle[length=1.0,width=1.0]
    Rectangle[length=5.6,width=7.8]
    length is: 5.6
    width is: 7.8
    area is: 43.68
    perimeter is: 26.80
    81).
  • A constructor that constructs a circle with the given center's (
    Employee[id=8,name=Peter Tan,salary=2500]
    Employee[id=8,name=Peter Tan,salary=999]
    id is: 8
    firstname is: Peter
    lastname is: Tan
    salary is: 999
    name is: Peter Tan
    annual salary is: 11988
    1098
    Employee[id=8,name=Peter Tan,salary=1098]
    55,
    Employee[id=8,name=Peter Tan,salary=2500]
    Employee[id=8,name=Peter Tan,salary=999]
    id is: 8
    firstname is: Peter
    lastname is: Tan
    salary is: 999
    name is: Peter Tan
    annual salary is: 11988
    1098
    Employee[id=8,name=Peter Tan,salary=1098]
    57) and
    Account[id=A101,name=Tan Ah Teck,balance=88]
    Account[id=A102,name=Kumar,balance=0]
    ID: A101 
    Name: Tan Ah Teck
    Balance: 88 
    Account[id=A101,name=Tan Ah Teck,balance=188]
    Account[id=A101,name=Tan Ah Teck,balance=138]
    Amount exceeded balance
    Account[id=A101,name=Tan Ah Teck,balance=138]
    Account[id=A101,name=Tan Ah Teck,balance=38]
    Account[id=A102,name=Kumar,balance=100]
    1.
  • An overloaded constructor that constructs a
    Employee[id=8,name=Peter Tan,salary=2500]
    Employee[id=8,name=Peter Tan,salary=999]
    id is: 8
    firstname is: Peter
    lastname is: Tan
    salary is: 999
    name is: Peter Tan
    annual salary is: 11988
    1098
    Employee[id=8,name=Peter Tan,salary=1098]
    94 given a
    Employee[id=8,name=Peter Tan,salary=2500]
    Employee[id=8,name=Peter Tan,salary=999]
    id is: 8
    firstname is: Peter
    lastname is: Tan
    salary is: 999
    name is: Peter Tan
    annual salary is: 11988
    1098
    Employee[id=8,name=Peter Tan,salary=1098]
    54 instance as
    Employee[id=8,name=Peter Tan,salary=2500]
    Employee[id=8,name=Peter Tan,salary=999]
    id is: 8
    firstname is: Peter
    lastname is: Tan
    salary is: 999
    name is: Peter Tan
    annual salary is: 11988
    1098
    Employee[id=8,name=Peter Tan,salary=1098]
    98, and
    Account[id=A101,name=Tan Ah Teck,balance=88]
    Account[id=A102,name=Kumar,balance=0]
    ID: A101 
    Name: Tan Ah Teck
    Balance: 88 
    Account[id=A101,name=Tan Ah Teck,balance=188]
    Account[id=A101,name=Tan Ah Teck,balance=138]
    Amount exceeded balance
    Account[id=A101,name=Tan Ah Teck,balance=138]
    Account[id=A101,name=Tan Ah Teck,balance=38]
    Account[id=A102,name=Kumar,balance=100]
    1.
  • A default constructor that construct a circle with center at
    Employee[id=8,name=Peter Tan,salary=2500]
    Employee[id=8,name=Peter Tan,salary=999]
    id is: 8
    firstname is: Peter
    lastname is: Tan
    salary is: 999
    name is: Peter Tan
    annual salary is: 11988
    1098
    Employee[id=8,name=Peter Tan,salary=1098]
    78 and radius of
    InvoiceItem[id=A101,desc=Pen Red,qty=888,unitPrice=0.08]
    InvoiceItem[id=A101,desc=Pen Red,qty=999,unitPrice=0.99]
    id is: A101
    desc is: Pen Red
    qty is: 999
    unitPrice is: 0.99
    The total is: 989.01
    
    10.
  • Various getters and setters.
  • A
    public Author (String name, String email, char gender) {......}
    5 method that returns a string description of this instance in the format "
    InvoiceItem[id=A101,desc=Pen Red,qty=888,unitPrice=0.08]
    InvoiceItem[id=A101,desc=Pen Red,qty=999,unitPrice=0.99]
    id is: A101
    desc is: Pen Red
    qty is: 999
    unitPrice is: 0.99
    The total is: 989.01
    
    12". You shall reuse the
    public Author (String name, String email, char gender) {......}
    5 of
    Employee[id=8,name=Peter Tan,salary=2500]
    Employee[id=8,name=Peter Tan,salary=999]
    id is: 8
    firstname is: Peter
    lastname is: Tan
    salary is: 999
    name is: Peter Tan
    annual salary is: 11988
    1098
    Employee[id=8,name=Peter Tan,salary=1098]
    54.
  • Account[id=A101,name=Tan Ah Teck,balance=88]
    Account[id=A102,name=Kumar,balance=0]
    ID: A101 
    Name: Tan Ah Teck
    Balance: 88 
    Account[id=A101,name=Tan Ah Teck,balance=188]
    Account[id=A101,name=Tan Ah Teck,balance=138]
    Amount exceeded balance
    Account[id=A101,name=Tan Ah Teck,balance=138]
    Account[id=A101,name=Tan Ah Teck,balance=38]
    Account[id=A102,name=Kumar,balance=100]
    9 and
    InvoiceItem[id=A101,desc=Pen Red,qty=888,unitPrice=0.08]
    InvoiceItem[id=A101,desc=Pen Red,qty=999,unitPrice=0.99]
    id is: A101
    desc is: Pen Red
    qty is: 999
    unitPrice is: 0.99
    The total is: 989.01
    
    16 methods that return the area and circumference of
    public Author (String name, String email, char gender) {......}
    1 circle in
    Account[id=A101,name=Tan Ah Teck,balance=88]
    Account[id=A102,name=Kumar,balance=0]
    ID: A101 
    Name: Tan Ah Teck
    Balance: 88 
    Account[id=A101,name=Tan Ah Teck,balance=188]
    Account[id=A101,name=Tan Ah Teck,balance=138]
    Amount exceeded balance
    Account[id=A101,name=Tan Ah Teck,balance=138]
    Account[id=A101,name=Tan Ah Teck,balance=38]
    Account[id=A102,name=Kumar,balance=100]
    2.
  • A
    InvoiceItem[id=A101,desc=Pen Red,qty=888,unitPrice=0.08]
    InvoiceItem[id=A101,desc=Pen Red,qty=999,unitPrice=0.99]
    id is: A101
    desc is: Pen Red
    qty is: 999
    unitPrice is: 0.99
    The total is: 989.01
    
    19 method that returns the distance of the centers from
    public Author (String name, String email, char gender) {......}
    1 instance and the given
    Employee[id=8,name=Peter Tan,salary=2500]
    Employee[id=8,name=Peter Tan,salary=999]
    id is: 8
    firstname is: Peter
    lastname is: Tan
    salary is: 999
    name is: Peter Tan
    annual salary is: 11988
    1098
    Employee[id=8,name=Peter Tan,salary=1098]
    94 instance.  You should use
    Employee[id=8,name=Peter Tan,salary=2500]
    Employee[id=8,name=Peter Tan,salary=999]
    id is: 8
    firstname is: Peter
    lastname is: Tan
    salary is: 999
    name is: Peter Tan
    annual salary is: 11988
    1098
    Employee[id=8,name=Peter Tan,salary=1098]
    54’s
    Employee[id=8,name=Peter Tan,salary=2500]
    Employee[id=8,name=Peter Tan,salary=999]
    id is: 8
    firstname is: Peter
    lastname is: Tan
    salary is: 999
    name is: Peter Tan
    annual salary is: 11988
    1098
    Employee[id=8,name=Peter Tan,salary=1098]
    76 method to compute this distance.

Write the

Employee[id=8,name=Peter Tan,salary=2500]
Employee[id=8,name=Peter Tan,salary=999]
id is: 8
firstname is: Peter
lastname is: Tan
salary is: 999
name is: Peter Tan
annual salary is: 11988
1098
Employee[id=8,name=Peter Tan,salary=1098]
94 class. Also write a test driver (called
InvoiceItem[id=A101,desc=Pen Red,qty=888,unitPrice=0.08]
InvoiceItem[id=A101,desc=Pen Red,qty=999,unitPrice=0.99]
id is: A101
desc is: Pen Red
qty is: 999
unitPrice is: 0.99
The total is: 989.01
25) to test all the public methods defined in the class.

Hints:

Ex: The MyTriangle and MyPoint Classes

A class called

InvoiceItem[id=A101,desc=Pen Red,qty=888,unitPrice=0.08]
InvoiceItem[id=A101,desc=Pen Red,qty=999,unitPrice=0.99]
id is: A101
desc is: Pen Red
qty is: 999
unitPrice is: 0.99
The total is: 989.01
26, which models a triangle with 3 vertices, is designed as shown in the class diagram. The
InvoiceItem[id=A101,desc=Pen Red,qty=888,unitPrice=0.08]
InvoiceItem[id=A101,desc=Pen Red,qty=999,unitPrice=0.99]
id is: A101
desc is: Pen Red
qty is: 999
unitPrice is: 0.99
The total is: 989.01
26 class uses three
Employee[id=8,name=Peter Tan,salary=2500]
Employee[id=8,name=Peter Tan,salary=999]
id is: 8
firstname is: Peter
lastname is: Tan
salary is: 999
name is: Peter Tan
annual salary is: 11988
1098
Employee[id=8,name=Peter Tan,salary=1098]
54 instances (created in the earlier exercise) as the three vertices.

What kind of data is the colors of the cars around the gym in the scenario

It contains:

  • Three
    Account[id=A101,name=Tan Ah Teck,balance=88]
    Account[id=A102,name=Kumar,balance=0]
    ID: A101 
    Name: Tan Ah Teck
    Balance: 88 
    Account[id=A101,name=Tan Ah Teck,balance=188]
    Account[id=A101,name=Tan Ah Teck,balance=138]
    Amount exceeded balance
    Account[id=A101,name=Tan Ah Teck,balance=138]
    Account[id=A101,name=Tan Ah Teck,balance=38]
    Account[id=A102,name=Kumar,balance=100]
    0 instance variables
    InvoiceItem[id=A101,desc=Pen Red,qty=888,unitPrice=0.08]
    InvoiceItem[id=A101,desc=Pen Red,qty=999,unitPrice=0.99]
    id is: A101
    desc is: Pen Red
    qty is: 999
    unitPrice is: 0.99
    The total is: 989.01
    
    30,
    InvoiceItem[id=A101,desc=Pen Red,qty=888,unitPrice=0.08]
    InvoiceItem[id=A101,desc=Pen Red,qty=999,unitPrice=0.99]
    id is: A101
    desc is: Pen Red
    qty is: 999
    unitPrice is: 0.99
    The total is: 989.01
    
    31,
    InvoiceItem[id=A101,desc=Pen Red,qty=888,unitPrice=0.08]
    InvoiceItem[id=A101,desc=Pen Red,qty=999,unitPrice=0.99]
    id is: A101
    desc is: Pen Red
    qty is: 999
    unitPrice is: 0.99
    The total is: 989.01
    
    32 (instances of
    Employee[id=8,name=Peter Tan,salary=2500]
    Employee[id=8,name=Peter Tan,salary=999]
    id is: 8
    firstname is: Peter
    lastname is: Tan
    salary is: 999
    name is: Peter Tan
    annual salary is: 11988
    1098
    Employee[id=8,name=Peter Tan,salary=1098]
    54), for the three vertices.
  • A constructor that constructs a
    InvoiceItem[id=A101,desc=Pen Red,qty=888,unitPrice=0.08]
    InvoiceItem[id=A101,desc=Pen Red,qty=999,unitPrice=0.99]
    id is: A101
    desc is: Pen Red
    qty is: 999
    unitPrice is: 0.99
    The total is: 989.01
    
    26 with three set of coordinates,
    InvoiceItem[id=A101,desc=Pen Red,qty=888,unitPrice=0.08]
    InvoiceItem[id=A101,desc=Pen Red,qty=999,unitPrice=0.99]
    id is: A101
    desc is: Pen Red
    qty is: 999
    unitPrice is: 0.99
    The total is: 989.01
    
    35,
    InvoiceItem[id=A101,desc=Pen Red,qty=888,unitPrice=0.08]
    InvoiceItem[id=A101,desc=Pen Red,qty=999,unitPrice=0.99]
    id is: A101
    desc is: Pen Red
    qty is: 999
    unitPrice is: 0.99
    The total is: 989.01
    
    36,
    InvoiceItem[id=A101,desc=Pen Red,qty=888,unitPrice=0.08]
    InvoiceItem[id=A101,desc=Pen Red,qty=999,unitPrice=0.99]
    id is: A101
    desc is: Pen Red
    qty is: 999
    unitPrice is: 0.99
    The total is: 989.01
    
    37.
  • An overloaded constructor that constructs a
    InvoiceItem[id=A101,desc=Pen Red,qty=888,unitPrice=0.08]
    InvoiceItem[id=A101,desc=Pen Red,qty=999,unitPrice=0.99]
    id is: A101
    desc is: Pen Red
    qty is: 999
    unitPrice is: 0.99
    The total is: 989.01
    
    26 given three instances of
    Employee[id=8,name=Peter Tan,salary=2500]
    Employee[id=8,name=Peter Tan,salary=999]
    id is: 8
    firstname is: Peter
    lastname is: Tan
    salary is: 999
    name is: Peter Tan
    annual salary is: 11988
    1098
    Employee[id=8,name=Peter Tan,salary=1098]
    54.
  • A
    public Author (String name, String email, char gender) {......}
    5 method that returns a string description of the instance in the format "
    InvoiceItem[id=A101,desc=Pen Red,qty=888,unitPrice=0.08]
    InvoiceItem[id=A101,desc=Pen Red,qty=999,unitPrice=0.99]
    id is: A101
    desc is: Pen Red
    qty is: 999
    unitPrice is: 0.99
    The total is: 989.01
    
    41".
  • A
    InvoiceItem[id=A101,desc=Pen Red,qty=888,unitPrice=0.08]
    InvoiceItem[id=A101,desc=Pen Red,qty=999,unitPrice=0.99]
    id is: A101
    desc is: Pen Red
    qty is: 999
    unitPrice is: 0.99
    The total is: 989.01
    
    42 method that returns the length of the perimeter in double. You should use the
    Employee[id=8,name=Peter Tan,salary=2500]
    Employee[id=8,name=Peter Tan,salary=999]
    id is: 8
    firstname is: Peter
    lastname is: Tan
    salary is: 999
    name is: Peter Tan
    annual salary is: 11988
    1098
    Employee[id=8,name=Peter Tan,salary=1098]
    76 method of
    Employee[id=8,name=Peter Tan,salary=2500]
    Employee[id=8,name=Peter Tan,salary=999]
    id is: 8
    firstname is: Peter
    lastname is: Tan
    salary is: 999
    name is: Peter Tan
    annual salary is: 11988
    1098
    Employee[id=8,name=Peter Tan,salary=1098]
    54 to compute the perimeter.
  • A method
    InvoiceItem[id=A101,desc=Pen Red,qty=888,unitPrice=0.08]
    InvoiceItem[id=A101,desc=Pen Red,qty=999,unitPrice=0.99]
    id is: A101
    desc is: Pen Red
    qty is: 999
    unitPrice is: 0.99
    The total is: 989.01
    
    45, which prints "
    InvoiceItem[id=A101,desc=Pen Red,qty=888,unitPrice=0.08]
    InvoiceItem[id=A101,desc=Pen Red,qty=999,unitPrice=0.99]
    id is: A101
    desc is: Pen Red
    qty is: 999
    unitPrice is: 0.99
    The total is: 989.01
    
    46" if all the three sides are equal, "
    InvoiceItem[id=A101,desc=Pen Red,qty=888,unitPrice=0.08]
    InvoiceItem[id=A101,desc=Pen Red,qty=999,unitPrice=0.99]
    id is: A101
    desc is: Pen Red
    qty is: 999
    unitPrice is: 0.99
    The total is: 989.01
    
    47" if any two of the three sides are equal, or "
    InvoiceItem[id=A101,desc=Pen Red,qty=888,unitPrice=0.08]
    InvoiceItem[id=A101,desc=Pen Red,qty=999,unitPrice=0.99]
    id is: A101
    desc is: Pen Red
    qty is: 999
    unitPrice is: 0.99
    The total is: 989.01
    
    48" if the three sides are different.

Write the

InvoiceItem[id=A101,desc=Pen Red,qty=888,unitPrice=0.08]
InvoiceItem[id=A101,desc=Pen Red,qty=999,unitPrice=0.99]
id is: A101
desc is: Pen Red
qty is: 999
unitPrice is: 0.99
The total is: 989.01
26 class. Also write a test driver (called
InvoiceItem[id=A101,desc=Pen Red,qty=888,unitPrice=0.08]
InvoiceItem[id=A101,desc=Pen Red,qty=999,unitPrice=0.99]
id is: A101
desc is: Pen Red
qty is: 999
unitPrice is: 0.99
The total is: 989.01
50) to test all the
Account[id=A101,name=Tan Ah Teck,balance=88]
Account[id=A102,name=Kumar,balance=0]
ID: A101 
Name: Tan Ah Teck
Balance: 88 
Account[id=A101,name=Tan Ah Teck,balance=188]
Account[id=A101,name=Tan Ah Teck,balance=138]
Amount exceeded balance
Account[id=A101,name=Tan Ah Teck,balance=138]
Account[id=A101,name=Tan Ah Teck,balance=38]
Account[id=A102,name=Kumar,balance=100]
7 methods defined in the class.

Ex: The MyRectangle and MyPoint Classes

Design a

InvoiceItem[id=A101,desc=Pen Red,qty=888,unitPrice=0.08]
InvoiceItem[id=A101,desc=Pen Red,qty=999,unitPrice=0.99]
id is: A101
desc is: Pen Red
qty is: 999
unitPrice is: 0.99
The total is: 989.01
52 class which is composed of two
Employee[id=8,name=Peter Tan,salary=2500]
Employee[id=8,name=Peter Tan,salary=999]
id is: 8
firstname is: Peter
lastname is: Tan
salary is: 999
name is: Peter Tan
annual salary is: 11988
1098
Employee[id=8,name=Peter Tan,salary=1098]
54 instances as its top-left and bottom-right corners. Draw the class diagrams, write the codes, and write the test drivers.

More Exercises on Classes

Ex: The MyComplex class

A class called

InvoiceItem[id=A101,desc=Pen Red,qty=888,unitPrice=0.08]
InvoiceItem[id=A101,desc=Pen Red,qty=999,unitPrice=0.99]
id is: A101
desc is: Pen Red
qty is: 999
unitPrice is: 0.99
The total is: 989.01
54, which models a complex number with real and imaginary parts, is designed as shown in the class diagram.

What kind of data is the colors of the cars around the gym in the scenario

It contains:

  • Two instance variable named
    InvoiceItem[id=A101,desc=Pen Red,qty=888,unitPrice=0.08]
    InvoiceItem[id=A101,desc=Pen Red,qty=999,unitPrice=0.99]
    id is: A101
    desc is: Pen Red
    qty is: 999
    unitPrice is: 0.99
    The total is: 989.01
    
    55 (
    Account[id=A101,name=Tan Ah Teck,balance=88]
    Account[id=A102,name=Kumar,balance=0]
    ID: A101 
    Name: Tan Ah Teck
    Balance: 88 
    Account[id=A101,name=Tan Ah Teck,balance=188]
    Account[id=A101,name=Tan Ah Teck,balance=138]
    Amount exceeded balance
    Account[id=A101,name=Tan Ah Teck,balance=138]
    Account[id=A101,name=Tan Ah Teck,balance=38]
    Account[id=A102,name=Kumar,balance=100]
    2) and
    InvoiceItem[id=A101,desc=Pen Red,qty=888,unitPrice=0.08]
    InvoiceItem[id=A101,desc=Pen Red,qty=999,unitPrice=0.99]
    id is: A101
    desc is: Pen Red
    qty is: 999
    unitPrice is: 0.99
    The total is: 989.01
    
    57 (
    Account[id=A101,name=Tan Ah Teck,balance=88]
    Account[id=A102,name=Kumar,balance=0]
    ID: A101 
    Name: Tan Ah Teck
    Balance: 88 
    Account[id=A101,name=Tan Ah Teck,balance=188]
    Account[id=A101,name=Tan Ah Teck,balance=138]
    Amount exceeded balance
    Account[id=A101,name=Tan Ah Teck,balance=138]
    Account[id=A101,name=Tan Ah Teck,balance=38]
    Account[id=A102,name=Kumar,balance=100]
    2) which stores the real and imaginary parts of the complex number, respectively.
  • A constructor that creates a
    InvoiceItem[id=A101,desc=Pen Red,qty=888,unitPrice=0.08]
    InvoiceItem[id=A101,desc=Pen Red,qty=999,unitPrice=0.99]
    id is: A101
    desc is: Pen Red
    qty is: 999
    unitPrice is: 0.99
    The total is: 989.01
    
    54 instance with the given real and imaginary values.
  • A default constructor that create a MyComplex at
    InvoiceItem[id=A101,desc=Pen Red,qty=888,unitPrice=0.08]
    InvoiceItem[id=A101,desc=Pen Red,qty=999,unitPrice=0.99]
    id is: A101
    desc is: Pen Red
    qty is: 999
    unitPrice is: 0.99
    The total is: 989.01
    
    60.
  • Getters and setters for instance variables
    InvoiceItem[id=A101,desc=Pen Red,qty=888,unitPrice=0.08]
    InvoiceItem[id=A101,desc=Pen Red,qty=999,unitPrice=0.99]
    id is: A101
    desc is: Pen Red
    qty is: 999
    unitPrice is: 0.99
    The total is: 989.01
    
    55 and
    InvoiceItem[id=A101,desc=Pen Red,qty=888,unitPrice=0.08]
    InvoiceItem[id=A101,desc=Pen Red,qty=999,unitPrice=0.99]
    id is: A101
    desc is: Pen Red
    qty is: 999
    unitPrice is: 0.99
    The total is: 989.01
    
    57.
  • A method
    InvoiceItem[id=A101,desc=Pen Red,qty=888,unitPrice=0.08]
    InvoiceItem[id=A101,desc=Pen Red,qty=999,unitPrice=0.99]
    id is: A101
    desc is: Pen Red
    qty is: 999
    unitPrice is: 0.99
    The total is: 989.01
    
    63 to set the value of the complex number.
  • A
    public Author (String name, String email, char gender) {......}
    5 that returns "
    InvoiceItem[id=A101,desc=Pen Red,qty=888,unitPrice=0.08]
    InvoiceItem[id=A101,desc=Pen Red,qty=999,unitPrice=0.99]
    id is: A101
    desc is: Pen Red
    qty is: 999
    unitPrice is: 0.99
    The total is: 989.01
    
    65" where
    Employee[id=8,name=Peter Tan,salary=2500]
    Employee[id=8,name=Peter Tan,salary=999]
    id is: 8
    firstname is: Peter
    lastname is: Tan
    salary is: 999
    name is: Peter Tan
    annual salary is: 11988
    1098
    Employee[id=8,name=Peter Tan,salary=1098]
    55 and
    Employee[id=8,name=Peter Tan,salary=2500]
    Employee[id=8,name=Peter Tan,salary=999]
    id is: 8
    firstname is: Peter
    lastname is: Tan
    salary is: 999
    name is: Peter Tan
    annual salary is: 11988
    1098
    Employee[id=8,name=Peter Tan,salary=1098]
    57 are the real and imaginary parts, respectively.
  • Methods
    InvoiceItem[id=A101,desc=Pen Red,qty=888,unitPrice=0.08]
    InvoiceItem[id=A101,desc=Pen Red,qty=999,unitPrice=0.99]
    id is: A101
    desc is: Pen Red
    qty is: 999
    unitPrice is: 0.99
    The total is: 989.01
    
    68 and
    InvoiceItem[id=A101,desc=Pen Red,qty=888,unitPrice=0.08]
    InvoiceItem[id=A101,desc=Pen Red,qty=999,unitPrice=0.99]
    id is: A101
    desc is: Pen Red
    qty is: 999
    unitPrice is: 0.99
    The total is: 989.01
    
    69 that returns
    InvoiceItem[id=A101,desc=Pen Red,qty=888,unitPrice=0.08]
    InvoiceItem[id=A101,desc=Pen Red,qty=999,unitPrice=0.99]
    id is: A101
    desc is: Pen Red
    qty is: 999
    unitPrice is: 0.99
    The total is: 989.01
    
    70 if this complex number is real or imaginary, respectively.
    Hints:
  • A method
    InvoiceItem[id=A101,desc=Pen Red,qty=888,unitPrice=0.08]
    InvoiceItem[id=A101,desc=Pen Red,qty=999,unitPrice=0.99]
    id is: A101
    desc is: Pen Red
    qty is: 999
    unitPrice is: 0.99
    The total is: 989.01
    
    71 that returns
    InvoiceItem[id=A101,desc=Pen Red,qty=888,unitPrice=0.08]
    InvoiceItem[id=A101,desc=Pen Red,qty=999,unitPrice=0.99]
    id is: A101
    desc is: Pen Red
    qty is: 999
    unitPrice is: 0.99
    The total is: 989.01
    
    70 if
    public Author (String name, String email, char gender) {......}
    1 complex number is equal to the given complex number (real, imag).
    Hints:
    Rectangle[length=1.2,width=3.4]
    Rectangle[length=1.0,width=1.0]
    Rectangle[length=5.6,width=7.8]
    length is: 5.6
    width is: 7.8
    area is: 43.68
    perimeter is: 26.80
    6
  • An overloaded
    InvoiceItem[id=A101,desc=Pen Red,qty=888,unitPrice=0.08]
    InvoiceItem[id=A101,desc=Pen Red,qty=999,unitPrice=0.99]
    id is: A101
    desc is: Pen Red
    qty is: 999
    unitPrice is: 0.99
    The total is: 989.01
    
    74 that returns
    InvoiceItem[id=A101,desc=Pen Red,qty=888,unitPrice=0.08]
    InvoiceItem[id=A101,desc=Pen Red,qty=999,unitPrice=0.99]
    id is: A101
    desc is: Pen Red
    qty is: 999
    unitPrice is: 0.99
    The total is: 989.01
    
    70 if this complex number is equal to the given
    InvoiceItem[id=A101,desc=Pen Red,qty=888,unitPrice=0.08]
    InvoiceItem[id=A101,desc=Pen Red,qty=999,unitPrice=0.99]
    id is: A101
    desc is: Pen Red
    qty is: 999
    unitPrice is: 0.99
    The total is: 989.01
    
    54 instance
    Employee[id=8,name=Peter Tan,salary=2500]
    Employee[id=8,name=Peter Tan,salary=999]
    id is: 8
    firstname is: Peter
    lastname is: Tan
    salary is: 999
    name is: Peter Tan
    annual salary is: 11988
    1098
    Employee[id=8,name=Peter Tan,salary=1098]
    75.
    Hints:
    Rectangle[length=1.2,width=3.4]
    Rectangle[length=1.0,width=1.0]
    Rectangle[length=5.6,width=7.8]
    length is: 5.6
    width is: 7.8
    area is: 43.68
    perimeter is: 26.80
    7
  • A method
    InvoiceItem[id=A101,desc=Pen Red,qty=888,unitPrice=0.08]
    InvoiceItem[id=A101,desc=Pen Red,qty=999,unitPrice=0.99]
    id is: A101
    desc is: Pen Red
    qty is: 999
    unitPrice is: 0.99
    The total is: 989.01
    
    78 that returns the magnitude of this complex number.
    Rectangle[length=1.2,width=3.4]
    Rectangle[length=1.0,width=1.0]
    Rectangle[length=5.6,width=7.8]
    length is: 5.6
    width is: 7.8
    area is: 43.68
    perimeter is: 26.80
    8
  • Methods
    InvoiceItem[id=A101,desc=Pen Red,qty=888,unitPrice=0.08]
    InvoiceItem[id=A101,desc=Pen Red,qty=999,unitPrice=0.99]
    id is: A101
    desc is: Pen Red
    qty is: 999
    unitPrice is: 0.99
    The total is: 989.01
    
    79 that adds and subtract the given
    InvoiceItem[id=A101,desc=Pen Red,qty=888,unitPrice=0.08]
    InvoiceItem[id=A101,desc=Pen Red,qty=999,unitPrice=0.99]
    id is: A101
    desc is: Pen Red
    qty is: 999
    unitPrice is: 0.99
    The total is: 989.01
    
    54 instance (called
    InvoiceItem[id=A101,desc=Pen Red,qty=888,unitPrice=0.08]
    InvoiceItem[id=A101,desc=Pen Red,qty=999,unitPrice=0.99]
    id is: A101
    desc is: Pen Red
    qty is: 999
    unitPrice is: 0.99
    The total is: 989.01
    
    81) into
    public Author (String name, String email, char gender) {......}
    1 instance and returns
    public Author (String name, String email, char gender) {......}
    1 instance.
    Rectangle[length=1.2,width=3.4]
    Rectangle[length=1.0,width=1.0]
    Rectangle[length=5.6,width=7.8]
    length is: 5.6
    width is: 7.8
    area is: 43.68
    perimeter is: 26.80
    9Hints:
  • Methods
    InvoiceItem[id=A101,desc=Pen Red,qty=888,unitPrice=0.08]
    InvoiceItem[id=A101,desc=Pen Red,qty=999,unitPrice=0.99]
    id is: A101
    desc is: Pen Red
    qty is: 999
    unitPrice is: 0.99
    The total is: 989.01
    
    84 that adds
    public Author (String name, String email, char gender) {......}
    1 instance with the given
    InvoiceItem[id=A101,desc=Pen Red,qty=888,unitPrice=0.08]
    InvoiceItem[id=A101,desc=Pen Red,qty=999,unitPrice=0.99]
    id is: A101
    desc is: Pen Red
    qty is: 999
    unitPrice is: 0.99
    The total is: 989.01
    
    54 instance called
    InvoiceItem[id=A101,desc=Pen Red,qty=888,unitPrice=0.08]
    InvoiceItem[id=A101,desc=Pen Red,qty=999,unitPrice=0.99]
    id is: A101
    desc is: Pen Red
    qty is: 999
    unitPrice is: 0.99
    The total is: 989.01
    
    81, and returns a new
    InvoiceItem[id=A101,desc=Pen Red,qty=888,unitPrice=0.08]
    InvoiceItem[id=A101,desc=Pen Red,qty=999,unitPrice=0.99]
    id is: A101
    desc is: Pen Red
    qty is: 999
    unitPrice is: 0.99
    The total is: 989.01
    
    54 instance containing the result.
    Hint:

You are required to:

  1. Write the
    InvoiceItem[id=A101,desc=Pen Red,qty=888,unitPrice=0.08]
    InvoiceItem[id=A101,desc=Pen Red,qty=999,unitPrice=0.99]
    id is: A101
    desc is: Pen Red
    qty is: 999
    unitPrice is: 0.99
    The total is: 989.01
    
    54 class.
  2. Write a test driver to test all the
    Account[id=A101,name=Tan Ah Teck,balance=88]
    Account[id=A102,name=Kumar,balance=0]
    ID: A101 
    Name: Tan Ah Teck
    Balance: 88 
    Account[id=A101,name=Tan Ah Teck,balance=188]
    Account[id=A101,name=Tan Ah Teck,balance=138]
    Amount exceeded balance
    Account[id=A101,name=Tan Ah Teck,balance=138]
    Account[id=A101,name=Tan Ah Teck,balance=38]
    Account[id=A102,name=Kumar,balance=100]
    7 methods defined in the class.
  3. Write an application called
    InvoiceItem[id=A101,desc=Pen Red,qty=888,unitPrice=0.08]
    InvoiceItem[id=A101,desc=Pen Red,qty=999,unitPrice=0.99]
    id is: A101
    desc is: Pen Red
    qty is: 999
    unitPrice is: 0.99
    The total is: 989.01
    
    91 that uses the
    InvoiceItem[id=A101,desc=Pen Red,qty=888,unitPrice=0.08]
    InvoiceItem[id=A101,desc=Pen Red,qty=999,unitPrice=0.99]
    id is: A101
    desc is: Pen Red
    qty is: 999
    unitPrice is: 0.99
    The total is: 989.01
    
    54 class. The application shall prompt the user for two complex numbers, print their values, check for real, imaginary and equality, and carry out all the arithmetic operations.
    Employee[id=8,name=Peter Tan,salary=2500]
    Employee[id=8,name=Peter Tan,salary=999]
    id is: 8
    firstname is: Peter
    lastname is: Tan
    salary is: 999
    name is: Peter Tan
    annual salary is: 11988
    1098
    Employee[id=8,name=Peter Tan,salary=1098]
    0

Try: A (more) complete design of

InvoiceItem[id=A101,desc=Pen Red,qty=888,unitPrice=0.08]
InvoiceItem[id=A101,desc=Pen Red,qty=999,unitPrice=0.99]
id is: A101
desc is: Pen Red
qty is: 999
unitPrice is: 0.99
The total is: 989.01
54 class is shown below:

What kind of data is the colors of the cars around the gym in the scenario
  • Methods
    InvoiceItem[id=A101,desc=Pen Red,qty=888,unitPrice=0.08]
    InvoiceItem[id=A101,desc=Pen Red,qty=999,unitPrice=0.99]
    id is: A101
    desc is: Pen Red
    qty is: 999
    unitPrice is: 0.99
    The total is: 989.01
    
    94 that returns the argument of this complex number in radians (
    Account[id=A101,name=Tan Ah Teck,balance=88]
    Account[id=A102,name=Kumar,balance=0]
    ID: A101 
    Name: Tan Ah Teck
    Balance: 88 
    Account[id=A101,name=Tan Ah Teck,balance=188]
    Account[id=A101,name=Tan Ah Teck,balance=138]
    Amount exceeded balance
    Account[id=A101,name=Tan Ah Teck,balance=138]
    Account[id=A101,name=Tan Ah Teck,balance=38]
    Account[id=A102,name=Kumar,balance=100]
    2).
    Employee[id=8,name=Peter Tan,salary=2500]
    Employee[id=8,name=Peter Tan,salary=999]
    id is: 8
    firstname is: Peter
    lastname is: Tan
    salary is: 999
    name is: Peter Tan
    annual salary is: 11988
    1098
    Employee[id=8,name=Peter Tan,salary=1098]
    1Note: The
    InvoiceItem[id=A101,desc=Pen Red,qty=888,unitPrice=0.08]
    InvoiceItem[id=A101,desc=Pen Red,qty=999,unitPrice=0.99]
    id is: A101
    desc is: Pen Red
    qty is: 999
    unitPrice is: 0.99
    The total is: 989.01
    
    96 library has two arc-tangent methods,
    InvoiceItem[id=A101,desc=Pen Red,qty=888,unitPrice=0.08]
    InvoiceItem[id=A101,desc=Pen Red,qty=999,unitPrice=0.99]
    id is: A101
    desc is: Pen Red
    qty is: 999
    unitPrice is: 0.99
    The total is: 989.01
    
    97 and
    InvoiceItem[id=A101,desc=Pen Red,qty=888,unitPrice=0.08]
    InvoiceItem[id=A101,desc=Pen Red,qty=999,unitPrice=0.99]
    id is: A101
    desc is: Pen Red
    qty is: 999
    unitPrice is: 0.99
    The total is: 989.01
    
    98. We commonly use the
    InvoiceItem[id=A101,desc=Pen Red,qty=888,unitPrice=0.08]
    InvoiceItem[id=A101,desc=Pen Red,qty=999,unitPrice=0.99]
    id is: A101
    desc is: Pen Red
    qty is: 999
    unitPrice is: 0.99
    The total is: 989.01
    
    99 instead of
    Account[id=A101,name=Tan Ah Teck,balance=88]
    Account[id=A102,name=Kumar,balance=0]
    ID: A101 
    Name: Tan Ah Teck
    Balance: 88 
    Account[id=A101,name=Tan Ah Teck,balance=188]
    Account[id=A101,name=Tan Ah Teck,balance=138]
    Amount exceeded balance
    Account[id=A101,name=Tan Ah Teck,balance=138]
    Account[id=A101,name=Tan Ah Teck,balance=38]
    Account[id=A102,name=Kumar,balance=100]
    00 to avoid division by zero. Read the documentation of
    InvoiceItem[id=A101,desc=Pen Red,qty=888,unitPrice=0.08]
    InvoiceItem[id=A101,desc=Pen Red,qty=999,unitPrice=0.99]
    id is: A101
    desc is: Pen Red
    qty is: 999
    unitPrice is: 0.99
    The total is: 989.01
    
    96 class in package
    Account[id=A101,name=Tan Ah Teck,balance=88]
    Account[id=A102,name=Kumar,balance=0]
    ID: A101 
    Name: Tan Ah Teck
    Balance: 88 
    Account[id=A101,name=Tan Ah Teck,balance=188]
    Account[id=A101,name=Tan Ah Teck,balance=138]
    Amount exceeded balance
    Account[id=A101,name=Tan Ah Teck,balance=138]
    Account[id=A101,name=Tan Ah Teck,balance=38]
    Account[id=A102,name=Kumar,balance=100]
    02.
  • The method
    Account[id=A101,name=Tan Ah Teck,balance=88]
    Account[id=A102,name=Kumar,balance=0]
    ID: A101 
    Name: Tan Ah Teck
    Balance: 88 
    Account[id=A101,name=Tan Ah Teck,balance=188]
    Account[id=A101,name=Tan Ah Teck,balance=138]
    Amount exceeded balance
    Account[id=A101,name=Tan Ah Teck,balance=138]
    Account[id=A101,name=Tan Ah Teck,balance=38]
    Account[id=A102,name=Kumar,balance=100]
    03 is renamed
    Account[id=A101,name=Tan Ah Teck,balance=88]
    Account[id=A102,name=Kumar,balance=0]
    ID: A101 
    Name: Tan Ah Teck
    Balance: 88 
    Account[id=A101,name=Tan Ah Teck,balance=188]
    Account[id=A101,name=Tan Ah Teck,balance=138]
    Amount exceeded balance
    Account[id=A101,name=Tan Ah Teck,balance=138]
    Account[id=A101,name=Tan Ah Teck,balance=38]
    Account[id=A102,name=Kumar,balance=100]
    04. Also added
    Account[id=A101,name=Tan Ah Teck,balance=88]
    Account[id=A102,name=Kumar,balance=0]
    ID: A101 
    Name: Tan Ah Teck
    Balance: 88 
    Account[id=A101,name=Tan Ah Teck,balance=188]
    Account[id=A101,name=Tan Ah Teck,balance=138]
    Amount exceeded balance
    Account[id=A101,name=Tan Ah Teck,balance=138]
    Account[id=A101,name=Tan Ah Teck,balance=38]
    Account[id=A102,name=Kumar,balance=100]
    05 and
    Account[id=A101,name=Tan Ah Teck,balance=88]
    Account[id=A102,name=Kumar,balance=0]
    ID: A101 
    Name: Tan Ah Teck
    Balance: 88 
    Account[id=A101,name=Tan Ah Teck,balance=188]
    Account[id=A101,name=Tan Ah Teck,balance=138]
    Amount exceeded balance
    Account[id=A101,name=Tan Ah Teck,balance=138]
    Account[id=A101,name=Tan Ah Teck,balance=38]
    Account[id=A102,name=Kumar,balance=100]
    06.
  • Methods
    Account[id=A101,name=Tan Ah Teck,balance=88]
    Account[id=A102,name=Kumar,balance=0]
    ID: A101 
    Name: Tan Ah Teck
    Balance: 88 
    Account[id=A101,name=Tan Ah Teck,balance=188]
    Account[id=A101,name=Tan Ah Teck,balance=138]
    Amount exceeded balance
    Account[id=A101,name=Tan Ah Teck,balance=138]
    Account[id=A101,name=Tan Ah Teck,balance=38]
    Account[id=A102,name=Kumar,balance=100]
    07 and
    Account[id=A101,name=Tan Ah Teck,balance=88]
    Account[id=A102,name=Kumar,balance=0]
    ID: A101 
    Name: Tan Ah Teck
    Balance: 88 
    Account[id=A101,name=Tan Ah Teck,balance=188]
    Account[id=A101,name=Tan Ah Teck,balance=138]
    Amount exceeded balance
    Account[id=A101,name=Tan Ah Teck,balance=138]
    Account[id=A101,name=Tan Ah Teck,balance=38]
    Account[id=A102,name=Kumar,balance=100]
    08 that multiplies and divides
    public Author (String name, String email, char gender) {......}
    1 instance with the given
    InvoiceItem[id=A101,desc=Pen Red,qty=888,unitPrice=0.08]
    InvoiceItem[id=A101,desc=Pen Red,qty=999,unitPrice=0.99]
    id is: A101
    desc is: Pen Red
    qty is: 999
    unitPrice is: 0.99
    The total is: 989.01
    
    54 instance
    InvoiceItem[id=A101,desc=Pen Red,qty=888,unitPrice=0.08]
    InvoiceItem[id=A101,desc=Pen Red,qty=999,unitPrice=0.99]
    id is: A101
    desc is: Pen Red
    qty is: 999
    unitPrice is: 0.99
    The total is: 989.01
    
    81, and keeps the result in
    public Author (String name, String email, char gender) {......}
    1 instance, and returns this instance.
    Employee[id=8,name=Peter Tan,salary=2500]
    Employee[id=8,name=Peter Tan,salary=999]
    id is: 8
    firstname is: Peter
    lastname is: Tan
    salary is: 999
    name is: Peter Tan
    annual salary is: 11988
    1098
    Employee[id=8,name=Peter Tan,salary=1098]
    2
  • A method
    Account[id=A101,name=Tan Ah Teck,balance=88]
    Account[id=A102,name=Kumar,balance=0]
    ID: A101 
    Name: Tan Ah Teck
    Balance: 88 
    Account[id=A101,name=Tan Ah Teck,balance=188]
    Account[id=A101,name=Tan Ah Teck,balance=138]
    Amount exceeded balance
    Account[id=A101,name=Tan Ah Teck,balance=138]
    Account[id=A101,name=Tan Ah Teck,balance=38]
    Account[id=A102,name=Kumar,balance=100]
    13 that operates on
    public Author (String name, String email, char gender) {......}
    1 instance and returns
    public Author (String name, String email, char gender) {......}
    1 instance containing the complex conjugate.
    Employee[id=8,name=Peter Tan,salary=2500]
    Employee[id=8,name=Peter Tan,salary=999]
    id is: 8
    firstname is: Peter
    lastname is: Tan
    salary is: 999
    name is: Peter Tan
    annual salary is: 11988
    1098
    Employee[id=8,name=Peter Tan,salary=1098]
    3

Take note that there are a few flaws in the design of this class, which was introduced solely for teaching purpose:

  • Comparing
    Account[id=A101,name=Tan Ah Teck,balance=88]
    Account[id=A102,name=Kumar,balance=0]
    ID: A101 
    Name: Tan Ah Teck
    Balance: 88 
    Account[id=A101,name=Tan Ah Teck,balance=188]
    Account[id=A101,name=Tan Ah Teck,balance=138]
    Amount exceeded balance
    Account[id=A101,name=Tan Ah Teck,balance=138]
    Account[id=A101,name=Tan Ah Teck,balance=38]
    Account[id=A102,name=Kumar,balance=100]
    2s in
    Account[id=A101,name=Tan Ah Teck,balance=88]
    Account[id=A102,name=Kumar,balance=0]
    ID: A101 
    Name: Tan Ah Teck
    Balance: 88 
    Account[id=A101,name=Tan Ah Teck,balance=188]
    Account[id=A101,name=Tan Ah Teck,balance=138]
    Amount exceeded balance
    Account[id=A101,name=Tan Ah Teck,balance=138]
    Account[id=A101,name=Tan Ah Teck,balance=38]
    Account[id=A102,name=Kumar,balance=100]
    17 using "
    Account[id=A101,name=Tan Ah Teck,balance=88]
    Account[id=A102,name=Kumar,balance=0]
    ID: A101 
    Name: Tan Ah Teck
    Balance: 88 
    Account[id=A101,name=Tan Ah Teck,balance=188]
    Account[id=A101,name=Tan Ah Teck,balance=138]
    Amount exceeded balance
    Account[id=A101,name=Tan Ah Teck,balance=138]
    Account[id=A101,name=Tan Ah Teck,balance=38]
    Account[id=A102,name=Kumar,balance=100]
    18" may produce unexpected outcome. For example,
    Account[id=A101,name=Tan Ah Teck,balance=88]
    Account[id=A102,name=Kumar,balance=0]
    ID: A101 
    Name: Tan Ah Teck
    Balance: 88 
    Account[id=A101,name=Tan Ah Teck,balance=188]
    Account[id=A101,name=Tan Ah Teck,balance=138]
    Amount exceeded balance
    Account[id=A101,name=Tan Ah Teck,balance=138]
    Account[id=A101,name=Tan Ah Teck,balance=38]
    Account[id=A102,name=Kumar,balance=100]
    19 returns
    Account[id=A101,name=Tan Ah Teck,balance=88]
    Account[id=A102,name=Kumar,balance=0]
    ID: A101 
    Name: Tan Ah Teck
    Balance: 88 
    Account[id=A101,name=Tan Ah Teck,balance=188]
    Account[id=A101,name=Tan Ah Teck,balance=138]
    Amount exceeded balance
    Account[id=A101,name=Tan Ah Teck,balance=138]
    Account[id=A101,name=Tan Ah Teck,balance=38]
    Account[id=A102,name=Kumar,balance=100]
    20. It is common to define a small threshold called
    Account[id=A101,name=Tan Ah Teck,balance=88]
    Account[id=A102,name=Kumar,balance=0]
    ID: A101 
    Name: Tan Ah Teck
    Balance: 88 
    Account[id=A101,name=Tan Ah Teck,balance=188]
    Account[id=A101,name=Tan Ah Teck,balance=138]
    Amount exceeded balance
    Account[id=A101,name=Tan Ah Teck,balance=138]
    Account[id=A101,name=Tan Ah Teck,balance=38]
    Account[id=A102,name=Kumar,balance=100]
    21 (set to about
    Account[id=A101,name=Tan Ah Teck,balance=88]
    Account[id=A102,name=Kumar,balance=0]
    ID: A101 
    Name: Tan Ah Teck
    Balance: 88 
    Account[id=A101,name=Tan Ah Teck,balance=188]
    Account[id=A101,name=Tan Ah Teck,balance=138]
    Amount exceeded balance
    Account[id=A101,name=Tan Ah Teck,balance=138]
    Account[id=A101,name=Tan Ah Teck,balance=38]
    Account[id=A102,name=Kumar,balance=100]
    22) for comparing floating point numbers.
  • The method
    Account[id=A101,name=Tan Ah Teck,balance=88]
    Account[id=A102,name=Kumar,balance=0]
    ID: A101 
    Name: Tan Ah Teck
    Balance: 88 
    Account[id=A101,name=Tan Ah Teck,balance=188]
    Account[id=A101,name=Tan Ah Teck,balance=138]
    Amount exceeded balance
    Account[id=A101,name=Tan Ah Teck,balance=138]
    Account[id=A101,name=Tan Ah Teck,balance=38]
    Account[id=A102,name=Kumar,balance=100]
    23,
    Account[id=A101,name=Tan Ah Teck,balance=88]
    Account[id=A102,name=Kumar,balance=0]
    ID: A101 
    Name: Tan Ah Teck
    Balance: 88 
    Account[id=A101,name=Tan Ah Teck,balance=188]
    Account[id=A101,name=Tan Ah Teck,balance=138]
    Amount exceeded balance
    Account[id=A101,name=Tan Ah Teck,balance=138]
    Account[id=A101,name=Tan Ah Teck,balance=38]
    Account[id=A102,name=Kumar,balance=100]
    06 produce new instances, whereas
    Account[id=A101,name=Tan Ah Teck,balance=88]
    Account[id=A102,name=Kumar,balance=0]
    ID: A101 
    Name: Tan Ah Teck
    Balance: 88 
    Account[id=A101,name=Tan Ah Teck,balance=188]
    Account[id=A101,name=Tan Ah Teck,balance=138]
    Amount exceeded balance
    Account[id=A101,name=Tan Ah Teck,balance=138]
    Account[id=A101,name=Tan Ah Teck,balance=38]
    Account[id=A102,name=Kumar,balance=100]
    04,
    Account[id=A101,name=Tan Ah Teck,balance=88]
    Account[id=A102,name=Kumar,balance=0]
    ID: A101 
    Name: Tan Ah Teck
    Balance: 88 
    Account[id=A101,name=Tan Ah Teck,balance=188]
    Account[id=A101,name=Tan Ah Teck,balance=138]
    Amount exceeded balance
    Account[id=A101,name=Tan Ah Teck,balance=138]
    Account[id=A101,name=Tan Ah Teck,balance=38]
    Account[id=A102,name=Kumar,balance=100]
    05,
    Account[id=A101,name=Tan Ah Teck,balance=88]
    Account[id=A102,name=Kumar,balance=0]
    ID: A101 
    Name: Tan Ah Teck
    Balance: 88 
    Account[id=A101,name=Tan Ah Teck,balance=188]
    Account[id=A101,name=Tan Ah Teck,balance=138]
    Amount exceeded balance
    Account[id=A101,name=Tan Ah Teck,balance=138]
    Account[id=A101,name=Tan Ah Teck,balance=38]
    Account[id=A102,name=Kumar,balance=100]
    27,
    Account[id=A101,name=Tan Ah Teck,balance=88]
    Account[id=A102,name=Kumar,balance=0]
    ID: A101 
    Name: Tan Ah Teck
    Balance: 88 
    Account[id=A101,name=Tan Ah Teck,balance=188]
    Account[id=A101,name=Tan Ah Teck,balance=138]
    Amount exceeded balance
    Account[id=A101,name=Tan Ah Teck,balance=138]
    Account[id=A101,name=Tan Ah Teck,balance=38]
    Account[id=A102,name=Kumar,balance=100]
    28 and
    Account[id=A101,name=Tan Ah Teck,balance=88]
    Account[id=A102,name=Kumar,balance=0]
    ID: A101 
    Name: Tan Ah Teck
    Balance: 88 
    Account[id=A101,name=Tan Ah Teck,balance=188]
    Account[id=A101,name=Tan Ah Teck,balance=138]
    Amount exceeded balance
    Account[id=A101,name=Tan Ah Teck,balance=138]
    Account[id=A101,name=Tan Ah Teck,balance=38]
    Account[id=A102,name=Kumar,balance=100]
    13 modify
    public Author (String name, String email, char gender) {......}
    1 instance. There is inconsistency in the design (introduced for teaching purpose).

Also take note that methods such as

Account[id=A101,name=Tan Ah Teck,balance=88]
Account[id=A102,name=Kumar,balance=0]
ID: A101 
Name: Tan Ah Teck
Balance: 88 
Account[id=A101,name=Tan Ah Teck,balance=188]
Account[id=A101,name=Tan Ah Teck,balance=138]
Amount exceeded balance
Account[id=A101,name=Tan Ah Teck,balance=138]
Account[id=A101,name=Tan Ah Teck,balance=38]
Account[id=A102,name=Kumar,balance=100]
04 returns an instance of
InvoiceItem[id=A101,desc=Pen Red,qty=888,unitPrice=0.08]
InvoiceItem[id=A101,desc=Pen Red,qty=999,unitPrice=0.99]
id is: A101
desc is: Pen Red
qty is: 999
unitPrice is: 0.99
The total is: 989.01
54. Hence, you can place the result inside a
Account[id=A101,name=Tan Ah Teck,balance=88]
Account[id=A102,name=Kumar,balance=0]
ID: A101 
Name: Tan Ah Teck
Balance: 88 
Account[id=A101,name=Tan Ah Teck,balance=188]
Account[id=A101,name=Tan Ah Teck,balance=138]
Amount exceeded balance
Account[id=A101,name=Tan Ah Teck,balance=138]
Account[id=A101,name=Tan Ah Teck,balance=38]
Account[id=A102,name=Kumar,balance=100]
33 (which implicitly invoke the
public Author (String name, String email, char gender) {......}
5). You can also chain the operations, e.g.,
Account[id=A101,name=Tan Ah Teck,balance=88]
Account[id=A102,name=Kumar,balance=0]
ID: A101 
Name: Tan Ah Teck
Balance: 88 
Account[id=A101,name=Tan Ah Teck,balance=188]
Account[id=A101,name=Tan Ah Teck,balance=138]
Amount exceeded balance
Account[id=A101,name=Tan Ah Teck,balance=138]
Account[id=A101,name=Tan Ah Teck,balance=38]
Account[id=A102,name=Kumar,balance=100]
35 (same as
Account[id=A101,name=Tan Ah Teck,balance=88]
Account[id=A102,name=Kumar,balance=0]
ID: A101 
Name: Tan Ah Teck
Balance: 88 
Account[id=A101,name=Tan Ah Teck,balance=188]
Account[id=A101,name=Tan Ah Teck,balance=138]
Amount exceeded balance
Account[id=A101,name=Tan Ah Teck,balance=138]
Account[id=A101,name=Tan Ah Teck,balance=38]
Account[id=A102,name=Kumar,balance=100]
36, or
Account[id=A101,name=Tan Ah Teck,balance=88]
Account[id=A102,name=Kumar,balance=0]
ID: A101 
Name: Tan Ah Teck
Balance: 88 
Account[id=A101,name=Tan Ah Teck,balance=188]
Account[id=A101,name=Tan Ah Teck,balance=138]
Amount exceeded balance
Account[id=A101,name=Tan Ah Teck,balance=138]
Account[id=A101,name=Tan Ah Teck,balance=38]
Account[id=A102,name=Kumar,balance=100]
37.

Ex: The MyPolynomial Class

What kind of data is the colors of the cars around the gym in the scenario

A class called

Account[id=A101,name=Tan Ah Teck,balance=88]
Account[id=A102,name=Kumar,balance=0]
ID: A101 
Name: Tan Ah Teck
Balance: 88 
Account[id=A101,name=Tan Ah Teck,balance=188]
Account[id=A101,name=Tan Ah Teck,balance=138]
Amount exceeded balance
Account[id=A101,name=Tan Ah Teck,balance=138]
Account[id=A101,name=Tan Ah Teck,balance=38]
Account[id=A102,name=Kumar,balance=100]
38, which models polynomials of degree-
Account[id=A101,name=Tan Ah Teck,balance=88]
Account[id=A102,name=Kumar,balance=0]
ID: A101 
Name: Tan Ah Teck
Balance: 88 
Account[id=A101,name=Tan Ah Teck,balance=188]
Account[id=A101,name=Tan Ah Teck,balance=138]
Amount exceeded balance
Account[id=A101,name=Tan Ah Teck,balance=138]
Account[id=A101,name=Tan Ah Teck,balance=38]
Account[id=A102,name=Kumar,balance=100]
39 (see equation), is designed as shown in the class diagram.

What kind of data is the colors of the cars around the gym in the scenario

It contains:

  • An instance variable named
    Account[id=A101,name=Tan Ah Teck,balance=88]
    Account[id=A102,name=Kumar,balance=0]
    ID: A101 
    Name: Tan Ah Teck
    Balance: 88 
    Account[id=A101,name=Tan Ah Teck,balance=188]
    Account[id=A101,name=Tan Ah Teck,balance=138]
    Amount exceeded balance
    Account[id=A101,name=Tan Ah Teck,balance=138]
    Account[id=A101,name=Tan Ah Teck,balance=38]
    Account[id=A102,name=Kumar,balance=100]
    40, which stores the coefficients of the n-degree polynomial in a
    Account[id=A101,name=Tan Ah Teck,balance=88]
    Account[id=A102,name=Kumar,balance=0]
    ID: A101 
    Name: Tan Ah Teck
    Balance: 88 
    Account[id=A101,name=Tan Ah Teck,balance=188]
    Account[id=A101,name=Tan Ah Teck,balance=138]
    Amount exceeded balance
    Account[id=A101,name=Tan Ah Teck,balance=138]
    Account[id=A101,name=Tan Ah Teck,balance=38]
    Account[id=A102,name=Kumar,balance=100]
    2 array of size
    Account[id=A101,name=Tan Ah Teck,balance=88]
    Account[id=A102,name=Kumar,balance=0]
    ID: A101 
    Name: Tan Ah Teck
    Balance: 88 
    Account[id=A101,name=Tan Ah Teck,balance=188]
    Account[id=A101,name=Tan Ah Teck,balance=138]
    Amount exceeded balance
    Account[id=A101,name=Tan Ah Teck,balance=138]
    Account[id=A101,name=Tan Ah Teck,balance=38]
    Account[id=A102,name=Kumar,balance=100]
    42, where c0 is kept at index 0.
  • A constructor
    Account[id=A101,name=Tan Ah Teck,balance=88]
    Account[id=A102,name=Kumar,balance=0]
    ID: A101 
    Name: Tan Ah Teck
    Balance: 88 
    Account[id=A101,name=Tan Ah Teck,balance=188]
    Account[id=A101,name=Tan Ah Teck,balance=138]
    Amount exceeded balance
    Account[id=A101,name=Tan Ah Teck,balance=138]
    Account[id=A101,name=Tan Ah Teck,balance=38]
    Account[id=A102,name=Kumar,balance=100]
    43 that takes a variable number of doubles to initialize the coeffs array, where the first argument corresponds to c0.
    The three dots is known as varargs (variable number of arguments), which is a new feature introduced in JDK 1.5. It accepts an array or a sequence of comma-separated arguments. The compiler automatically packs the comma-separated arguments in an array. The three dots can only be used for the last argument of the method.
    Hints:
  • A method
    Account[id=A101,name=Tan Ah Teck,balance=88]
    Account[id=A102,name=Kumar,balance=0]
    ID: A101 
    Name: Tan Ah Teck
    Balance: 88 
    Account[id=A101,name=Tan Ah Teck,balance=188]
    Account[id=A101,name=Tan Ah Teck,balance=138]
    Amount exceeded balance
    Account[id=A101,name=Tan Ah Teck,balance=138]
    Account[id=A101,name=Tan Ah Teck,balance=38]
    Account[id=A102,name=Kumar,balance=100]
    44 that returns the degree of this polynomial.
  • A method
    public Author (String name, String email, char gender) {......}
    5 that returns "cnx^n+cn-1x^(n-1)+...+c1x+c0".
  • A method
    Account[id=A101,name=Tan Ah Teck,balance=88]
    Account[id=A102,name=Kumar,balance=0]
    ID: A101 
    Name: Tan Ah Teck
    Balance: 88 
    Account[id=A101,name=Tan Ah Teck,balance=188]
    Account[id=A101,name=Tan Ah Teck,balance=138]
    Amount exceeded balance
    Account[id=A101,name=Tan Ah Teck,balance=138]
    Account[id=A101,name=Tan Ah Teck,balance=38]
    Account[id=A102,name=Kumar,balance=100]
    46 that evaluate the polynomial for the given
    Employee[id=8,name=Peter Tan,salary=2500]
    Employee[id=8,name=Peter Tan,salary=999]
    id is: 8
    firstname is: Peter
    lastname is: Tan
    salary is: 999
    name is: Peter Tan
    annual salary is: 11988
    1098
    Employee[id=8,name=Peter Tan,salary=1098]
    55, by substituting the given
    Employee[id=8,name=Peter Tan,salary=2500]
    Employee[id=8,name=Peter Tan,salary=999]
    id is: 8
    firstname is: Peter
    lastname is: Tan
    salary is: 999
    name is: Peter Tan
    annual salary is: 11988
    1098
    Employee[id=8,name=Peter Tan,salary=1098]
    55 into the polynomial expression.
  • Methods
    Account[id=A101,name=Tan Ah Teck,balance=88]
    Account[id=A102,name=Kumar,balance=0]
    ID: A101 
    Name: Tan Ah Teck
    Balance: 88 
    Account[id=A101,name=Tan Ah Teck,balance=188]
    Account[id=A101,name=Tan Ah Teck,balance=138]
    Amount exceeded balance
    Account[id=A101,name=Tan Ah Teck,balance=138]
    Account[id=A101,name=Tan Ah Teck,balance=38]
    Account[id=A102,name=Kumar,balance=100]
    04 and
    Account[id=A101,name=Tan Ah Teck,balance=88]
    Account[id=A102,name=Kumar,balance=0]
    ID: A101 
    Name: Tan Ah Teck
    Balance: 88 
    Account[id=A101,name=Tan Ah Teck,balance=188]
    Account[id=A101,name=Tan Ah Teck,balance=138]
    Amount exceeded balance
    Account[id=A101,name=Tan Ah Teck,balance=138]
    Account[id=A101,name=Tan Ah Teck,balance=38]
    Account[id=A102,name=Kumar,balance=100]
    27 that adds and multiplies this polynomial with the given
    Account[id=A101,name=Tan Ah Teck,balance=88]
    Account[id=A102,name=Kumar,balance=0]
    ID: A101 
    Name: Tan Ah Teck
    Balance: 88 
    Account[id=A101,name=Tan Ah Teck,balance=188]
    Account[id=A101,name=Tan Ah Teck,balance=138]
    Amount exceeded balance
    Account[id=A101,name=Tan Ah Teck,balance=138]
    Account[id=A101,name=Tan Ah Teck,balance=38]
    Account[id=A102,name=Kumar,balance=100]
    38 instance
    Employee[id=8,name=Peter Tan,salary=2500]
    Employee[id=8,name=Peter Tan,salary=999]
    id is: 8
    firstname is: Peter
    lastname is: Tan
    salary is: 999
    name is: Peter Tan
    annual salary is: 11988
    1098
    Employee[id=8,name=Peter Tan,salary=1098]
    75, and returns
    public Author (String name, String email, char gender) {......}
    1 instance that contains the result.

Write the

Account[id=A101,name=Tan Ah Teck,balance=88]
Account[id=A102,name=Kumar,balance=0]
ID: A101 
Name: Tan Ah Teck
Balance: 88 
Account[id=A101,name=Tan Ah Teck,balance=188]
Account[id=A101,name=Tan Ah Teck,balance=138]
Amount exceeded balance
Account[id=A101,name=Tan Ah Teck,balance=138]
Account[id=A101,name=Tan Ah Teck,balance=38]
Account[id=A102,name=Kumar,balance=100]
38 class. Also write a test driver (called
Account[id=A101,name=Tan Ah Teck,balance=88]
Account[id=A102,name=Kumar,balance=0]
ID: A101 
Name: Tan Ah Teck
Balance: 88 
Account[id=A101,name=Tan Ah Teck,balance=188]
Account[id=A101,name=Tan Ah Teck,balance=138]
Amount exceeded balance
Account[id=A101,name=Tan Ah Teck,balance=138]
Account[id=A101,name=Tan Ah Teck,balance=38]
Account[id=A102,name=Kumar,balance=100]
55) to test all the
Account[id=A101,name=Tan Ah Teck,balance=88]
Account[id=A102,name=Kumar,balance=0]
ID: A101 
Name: Tan Ah Teck
Balance: 88 
Account[id=A101,name=Tan Ah Teck,balance=188]
Account[id=A101,name=Tan Ah Teck,balance=138]
Amount exceeded balance
Account[id=A101,name=Tan Ah Teck,balance=138]
Account[id=A101,name=Tan Ah Teck,balance=38]
Account[id=A102,name=Kumar,balance=100]
7 methods defined in the class.

Question: Do you need to keep the degree of the polynomial as an instance variable in the

Account[id=A101,name=Tan Ah Teck,balance=88]
Account[id=A102,name=Kumar,balance=0]
ID: A101 
Name: Tan Ah Teck
Balance: 88 
Account[id=A101,name=Tan Ah Teck,balance=188]
Account[id=A101,name=Tan Ah Teck,balance=138]
Amount exceeded balance
Account[id=A101,name=Tan Ah Teck,balance=138]
Account[id=A101,name=Tan Ah Teck,balance=38]
Account[id=A102,name=Kumar,balance=100]
38 class in Java? How about C/C++? Why?

Ex: Using JDK's BigInteger Class

Recall that primitive integer type

Account[id=A101,name=Tan Ah Teck,balance=88]
Account[id=A102,name=Kumar,balance=0]
ID: A101 
Name: Tan Ah Teck
Balance: 88 
Account[id=A101,name=Tan Ah Teck,balance=188]
Account[id=A101,name=Tan Ah Teck,balance=138]
Amount exceeded balance
Account[id=A101,name=Tan Ah Teck,balance=138]
Account[id=A101,name=Tan Ah Teck,balance=38]
Account[id=A102,name=Kumar,balance=100]
58,
Account[id=A101,name=Tan Ah Teck,balance=88]
Account[id=A102,name=Kumar,balance=0]
ID: A101 
Name: Tan Ah Teck
Balance: 88 
Account[id=A101,name=Tan Ah Teck,balance=188]
Account[id=A101,name=Tan Ah Teck,balance=138]
Amount exceeded balance
Account[id=A101,name=Tan Ah Teck,balance=138]
Account[id=A101,name=Tan Ah Teck,balance=38]
Account[id=A102,name=Kumar,balance=100]
59,
Rectangle[length=1.2,width=3.4]
Rectangle[length=1.0,width=1.0]
Rectangle[length=5.6,width=7.8]
length is: 5.6
width is: 7.8
area is: 43.68
perimeter is: 26.80
81 and
Account[id=A101,name=Tan Ah Teck,balance=88]
Account[id=A102,name=Kumar,balance=0]
ID: A101 
Name: Tan Ah Teck
Balance: 88 
Account[id=A101,name=Tan Ah Teck,balance=188]
Account[id=A101,name=Tan Ah Teck,balance=138]
Amount exceeded balance
Account[id=A101,name=Tan Ah Teck,balance=138]
Account[id=A101,name=Tan Ah Teck,balance=38]
Account[id=A102,name=Kumar,balance=100]
61 represent 8-, 16-, 32-, and 64-bit signed integers, respectively. You cannot use them for integers bigger than 64 bits. Java API provides a class called
Account[id=A101,name=Tan Ah Teck,balance=88]
Account[id=A102,name=Kumar,balance=0]
ID: A101 
Name: Tan Ah Teck
Balance: 88 
Account[id=A101,name=Tan Ah Teck,balance=188]
Account[id=A101,name=Tan Ah Teck,balance=138]
Amount exceeded balance
Account[id=A101,name=Tan Ah Teck,balance=138]
Account[id=A101,name=Tan Ah Teck,balance=38]
Account[id=A102,name=Kumar,balance=100]
62 in a package called
Account[id=A101,name=Tan Ah Teck,balance=88]
Account[id=A102,name=Kumar,balance=0]
ID: A101 
Name: Tan Ah Teck
Balance: 88 
Account[id=A101,name=Tan Ah Teck,balance=188]
Account[id=A101,name=Tan Ah Teck,balance=138]
Amount exceeded balance
Account[id=A101,name=Tan Ah Teck,balance=138]
Account[id=A101,name=Tan Ah Teck,balance=38]
Account[id=A102,name=Kumar,balance=100]
63. Study the API of the
Account[id=A101,name=Tan Ah Teck,balance=88]
Account[id=A102,name=Kumar,balance=0]
ID: A101 
Name: Tan Ah Teck
Balance: 88 
Account[id=A101,name=Tan Ah Teck,balance=188]
Account[id=A101,name=Tan Ah Teck,balance=138]
Amount exceeded balance
Account[id=A101,name=Tan Ah Teck,balance=138]
Account[id=A101,name=Tan Ah Teck,balance=38]
Account[id=A102,name=Kumar,balance=100]
62 class (Java API ⇒ From "Packages", choose "java.math" " From "classes", choose "BigInteger" " Study the constructors (choose "CONSTR") on how to construct a
Account[id=A101,name=Tan Ah Teck,balance=88]
Account[id=A102,name=Kumar,balance=0]
ID: A101 
Name: Tan Ah Teck
Balance: 88 
Account[id=A101,name=Tan Ah Teck,balance=188]
Account[id=A101,name=Tan Ah Teck,balance=138]
Amount exceeded balance
Account[id=A101,name=Tan Ah Teck,balance=138]
Account[id=A101,name=Tan Ah Teck,balance=38]
Account[id=A102,name=Kumar,balance=100]
62 instance, and the public methods available (choose "METHOD"). Look for methods for adding and multiplying two
Account[id=A101,name=Tan Ah Teck,balance=88]
Account[id=A102,name=Kumar,balance=0]
ID: A101 
Name: Tan Ah Teck
Balance: 88 
Account[id=A101,name=Tan Ah Teck,balance=188]
Account[id=A101,name=Tan Ah Teck,balance=138]
Amount exceeded balance
Account[id=A101,name=Tan Ah Teck,balance=138]
Account[id=A101,name=Tan Ah Teck,balance=38]
Account[id=A102,name=Kumar,balance=100]
66.

Write a program called

Account[id=A101,name=Tan Ah Teck,balance=88]
Account[id=A102,name=Kumar,balance=0]
ID: A101 
Name: Tan Ah Teck
Balance: 88 
Account[id=A101,name=Tan Ah Teck,balance=188]
Account[id=A101,name=Tan Ah Teck,balance=138]
Amount exceeded balance
Account[id=A101,name=Tan Ah Teck,balance=138]
Account[id=A101,name=Tan Ah Teck,balance=38]
Account[id=A102,name=Kumar,balance=100]
67 that:

  1. adds "11111111111111111111111111111111111111111111111111111111111111" to "22222222222222222222222222222222222222222222222222" and prints the result.
  2. multiplies the above two number and prints the result.

Hints:

Employee[id=8,name=Peter Tan,salary=2500]
Employee[id=8,name=Peter Tan,salary=999]
id is: 8
firstname is: Peter
lastname is: Tan
salary is: 999
name is: Peter Tan
annual salary is: 11988
1098
Employee[id=8,name=Peter Tan,salary=1098]
4

Ex: The MyTime Class

What kind of data is the colors of the cars around the gym in the scenario

A class called

Account[id=A101,name=Tan Ah Teck,balance=88]
Account[id=A102,name=Kumar,balance=0]
ID: A101 
Name: Tan Ah Teck
Balance: 88 
Account[id=A101,name=Tan Ah Teck,balance=188]
Account[id=A101,name=Tan Ah Teck,balance=138]
Amount exceeded balance
Account[id=A101,name=Tan Ah Teck,balance=138]
Account[id=A101,name=Tan Ah Teck,balance=38]
Account[id=A102,name=Kumar,balance=100]
68, which models a time instance, is designed as shown in the class diagram.

It contains the following

Account[id=A101,name=Tan Ah Teck,balance=88]
Account[id=A102,name=Kumar,balance=0]
ID: A101 
Name: Tan Ah Teck
Balance: 88 
Account[id=A101,name=Tan Ah Teck,balance=188]
Account[id=A101,name=Tan Ah Teck,balance=138]
Amount exceeded balance
Account[id=A101,name=Tan Ah Teck,balance=138]
Account[id=A101,name=Tan Ah Teck,balance=38]
Account[id=A102,name=Kumar,balance=100]
0 instance variables:

  • Account[id=A101,name=Tan Ah Teck,balance=88]
    Account[id=A102,name=Kumar,balance=0]
    ID: A101 
    Name: Tan Ah Teck
    Balance: 88 
    Account[id=A101,name=Tan Ah Teck,balance=188]
    Account[id=A101,name=Tan Ah Teck,balance=138]
    Amount exceeded balance
    Account[id=A101,name=Tan Ah Teck,balance=138]
    Account[id=A101,name=Tan Ah Teck,balance=38]
    Account[id=A102,name=Kumar,balance=100]
    70: between 0 to 23.
  • Account[id=A101,name=Tan Ah Teck,balance=88]
    Account[id=A102,name=Kumar,balance=0]
    ID: A101 
    Name: Tan Ah Teck
    Balance: 88 
    Account[id=A101,name=Tan Ah Teck,balance=188]
    Account[id=A101,name=Tan Ah Teck,balance=138]
    Amount exceeded balance
    Account[id=A101,name=Tan Ah Teck,balance=138]
    Account[id=A101,name=Tan Ah Teck,balance=38]
    Account[id=A102,name=Kumar,balance=100]
    71: between 0 to 59.
  • Account[id=A101,name=Tan Ah Teck,balance=88]
    Account[id=A102,name=Kumar,balance=0]
    ID: A101 
    Name: Tan Ah Teck
    Balance: 88 
    Account[id=A101,name=Tan Ah Teck,balance=188]
    Account[id=A101,name=Tan Ah Teck,balance=138]
    Amount exceeded balance
    Account[id=A101,name=Tan Ah Teck,balance=138]
    Account[id=A101,name=Tan Ah Teck,balance=38]
    Account[id=A102,name=Kumar,balance=100]
    72: between 0 to 59.

You are required to perform input validation.

It contains the following

Account[id=A101,name=Tan Ah Teck,balance=88]
Account[id=A102,name=Kumar,balance=0]
ID: A101 
Name: Tan Ah Teck
Balance: 88 
Account[id=A101,name=Tan Ah Teck,balance=188]
Account[id=A101,name=Tan Ah Teck,balance=138]
Amount exceeded balance
Account[id=A101,name=Tan Ah Teck,balance=138]
Account[id=A101,name=Tan Ah Teck,balance=38]
Account[id=A102,name=Kumar,balance=100]
7 methods:

  • Account[id=A101,name=Tan Ah Teck,balance=88]
    Account[id=A102,name=Kumar,balance=0]
    ID: A101 
    Name: Tan Ah Teck
    Balance: 88 
    Account[id=A101,name=Tan Ah Teck,balance=188]
    Account[id=A101,name=Tan Ah Teck,balance=138]
    Amount exceeded balance
    Account[id=A101,name=Tan Ah Teck,balance=138]
    Account[id=A101,name=Tan Ah Teck,balance=38]
    Account[id=A102,name=Kumar,balance=100]
    74: It shall check if the given
    Account[id=A101,name=Tan Ah Teck,balance=88]
    Account[id=A102,name=Kumar,balance=0]
    ID: A101 
    Name: Tan Ah Teck
    Balance: 88 
    Account[id=A101,name=Tan Ah Teck,balance=188]
    Account[id=A101,name=Tan Ah Teck,balance=138]
    Amount exceeded balance
    Account[id=A101,name=Tan Ah Teck,balance=138]
    Account[id=A101,name=Tan Ah Teck,balance=38]
    Account[id=A102,name=Kumar,balance=100]
    70,
    Account[id=A101,name=Tan Ah Teck,balance=88]
    Account[id=A102,name=Kumar,balance=0]
    ID: A101 
    Name: Tan Ah Teck
    Balance: 88 
    Account[id=A101,name=Tan Ah Teck,balance=188]
    Account[id=A101,name=Tan Ah Teck,balance=138]
    Amount exceeded balance
    Account[id=A101,name=Tan Ah Teck,balance=138]
    Account[id=A101,name=Tan Ah Teck,balance=38]
    Account[id=A102,name=Kumar,balance=100]
    71 and
    Account[id=A101,name=Tan Ah Teck,balance=88]
    Account[id=A102,name=Kumar,balance=0]
    ID: A101 
    Name: Tan Ah Teck
    Balance: 88 
    Account[id=A101,name=Tan Ah Teck,balance=188]
    Account[id=A101,name=Tan Ah Teck,balance=138]
    Amount exceeded balance
    Account[id=A101,name=Tan Ah Teck,balance=138]
    Account[id=A101,name=Tan Ah Teck,balance=38]
    Account[id=A102,name=Kumar,balance=100]
    77 are valid before setting the instance variables.
    (Advanced: Otherwise, it shall throw an
    Account[id=A101,name=Tan Ah Teck,balance=88]
    Account[id=A102,name=Kumar,balance=0]
    ID: A101 
    Name: Tan Ah Teck
    Balance: 88 
    Account[id=A101,name=Tan Ah Teck,balance=188]
    Account[id=A101,name=Tan Ah Teck,balance=138]
    Amount exceeded balance
    Account[id=A101,name=Tan Ah Teck,balance=138]
    Account[id=A101,name=Tan Ah Teck,balance=38]
    Account[id=A102,name=Kumar,balance=100]
    78 with the message "Invalid hour, minute, or second!".)
  • Setters
    Account[id=A101,name=Tan Ah Teck,balance=88]
    Account[id=A102,name=Kumar,balance=0]
    ID: A101 
    Name: Tan Ah Teck
    Balance: 88 
    Account[id=A101,name=Tan Ah Teck,balance=188]
    Account[id=A101,name=Tan Ah Teck,balance=138]
    Amount exceeded balance
    Account[id=A101,name=Tan Ah Teck,balance=138]
    Account[id=A101,name=Tan Ah Teck,balance=38]
    Account[id=A102,name=Kumar,balance=100]
    79,
    Account[id=A101,name=Tan Ah Teck,balance=88]
    Account[id=A102,name=Kumar,balance=0]
    ID: A101 
    Name: Tan Ah Teck
    Balance: 88 
    Account[id=A101,name=Tan Ah Teck,balance=188]
    Account[id=A101,name=Tan Ah Teck,balance=138]
    Amount exceeded balance
    Account[id=A101,name=Tan Ah Teck,balance=138]
    Account[id=A101,name=Tan Ah Teck,balance=38]
    Account[id=A102,name=Kumar,balance=100]
    80,
    Account[id=A101,name=Tan Ah Teck,balance=88]
    Account[id=A102,name=Kumar,balance=0]
    ID: A101 
    Name: Tan Ah Teck
    Balance: 88 
    Account[id=A101,name=Tan Ah Teck,balance=188]
    Account[id=A101,name=Tan Ah Teck,balance=138]
    Amount exceeded balance
    Account[id=A101,name=Tan Ah Teck,balance=138]
    Account[id=A101,name=Tan Ah Teck,balance=38]
    Account[id=A102,name=Kumar,balance=100]
    81: It shall check if the parameters are valid, similar to the above.
  • Getters
    Account[id=A101,name=Tan Ah Teck,balance=88]
    Account[id=A102,name=Kumar,balance=0]
    ID: A101 
    Name: Tan Ah Teck
    Balance: 88 
    Account[id=A101,name=Tan Ah Teck,balance=188]
    Account[id=A101,name=Tan Ah Teck,balance=138]
    Amount exceeded balance
    Account[id=A101,name=Tan Ah Teck,balance=138]
    Account[id=A101,name=Tan Ah Teck,balance=38]
    Account[id=A102,name=Kumar,balance=100]
    82,
    Account[id=A101,name=Tan Ah Teck,balance=88]
    Account[id=A102,name=Kumar,balance=0]
    ID: A101 
    Name: Tan Ah Teck
    Balance: 88 
    Account[id=A101,name=Tan Ah Teck,balance=188]
    Account[id=A101,name=Tan Ah Teck,balance=138]
    Amount exceeded balance
    Account[id=A101,name=Tan Ah Teck,balance=138]
    Account[id=A101,name=Tan Ah Teck,balance=38]
    Account[id=A102,name=Kumar,balance=100]
    83,
    Account[id=A101,name=Tan Ah Teck,balance=88]
    Account[id=A102,name=Kumar,balance=0]
    ID: A101 
    Name: Tan Ah Teck
    Balance: 88 
    Account[id=A101,name=Tan Ah Teck,balance=188]
    Account[id=A101,name=Tan Ah Teck,balance=138]
    Amount exceeded balance
    Account[id=A101,name=Tan Ah Teck,balance=138]
    Account[id=A101,name=Tan Ah Teck,balance=38]
    Account[id=A102,name=Kumar,balance=100]
    84.
  • public Author (String name, String email, char gender) {......}
    5: returns "
    Account[id=A101,name=Tan Ah Teck,balance=88]
    Account[id=A102,name=Kumar,balance=0]
    ID: A101 
    Name: Tan Ah Teck
    Balance: 88 
    Account[id=A101,name=Tan Ah Teck,balance=188]
    Account[id=A101,name=Tan Ah Teck,balance=138]
    Amount exceeded balance
    Account[id=A101,name=Tan Ah Teck,balance=138]
    Account[id=A101,name=Tan Ah Teck,balance=38]
    Account[id=A102,name=Kumar,balance=100]
    86".
  • Rectangle[length=1.2,width=3.4]
    Rectangle[length=1.0,width=1.0]
    Rectangle[length=5.6,width=7.8]
    length is: 5.6
    width is: 7.8
    area is: 43.68
    perimeter is: 26.80
    37: Update this instance to the next second and return this instance. Take note that the
    Rectangle[length=1.2,width=3.4]
    Rectangle[length=1.0,width=1.0]
    Rectangle[length=5.6,width=7.8]
    length is: 5.6
    width is: 7.8
    area is: 43.68
    perimeter is: 26.80
    37 of
    Account[id=A101,name=Tan Ah Teck,balance=88]
    Account[id=A102,name=Kumar,balance=0]
    ID: A101 
    Name: Tan Ah Teck
    Balance: 88 
    Account[id=A101,name=Tan Ah Teck,balance=188]
    Account[id=A101,name=Tan Ah Teck,balance=138]
    Amount exceeded balance
    Account[id=A101,name=Tan Ah Teck,balance=138]
    Account[id=A101,name=Tan Ah Teck,balance=38]
    Account[id=A102,name=Kumar,balance=100]
    89 is
    Account[id=A101,name=Tan Ah Teck,balance=88]
    Account[id=A102,name=Kumar,balance=0]
    ID: A101 
    Name: Tan Ah Teck
    Balance: 88 
    Account[id=A101,name=Tan Ah Teck,balance=188]
    Account[id=A101,name=Tan Ah Teck,balance=138]
    Amount exceeded balance
    Account[id=A101,name=Tan Ah Teck,balance=138]
    Account[id=A101,name=Tan Ah Teck,balance=38]
    Account[id=A102,name=Kumar,balance=100]
    90.
  • Account[id=A101,name=Tan Ah Teck,balance=88]
    Account[id=A102,name=Kumar,balance=0]
    ID: A101 
    Name: Tan Ah Teck
    Balance: 88 
    Account[id=A101,name=Tan Ah Teck,balance=188]
    Account[id=A101,name=Tan Ah Teck,balance=138]
    Amount exceeded balance
    Account[id=A101,name=Tan Ah Teck,balance=138]
    Account[id=A101,name=Tan Ah Teck,balance=38]
    Account[id=A102,name=Kumar,balance=100]
    91,
    Account[id=A101,name=Tan Ah Teck,balance=88]
    Account[id=A102,name=Kumar,balance=0]
    ID: A101 
    Name: Tan Ah Teck
    Balance: 88 
    Account[id=A101,name=Tan Ah Teck,balance=188]
    Account[id=A101,name=Tan Ah Teck,balance=138]
    Amount exceeded balance
    Account[id=A101,name=Tan Ah Teck,balance=138]
    Account[id=A101,name=Tan Ah Teck,balance=38]
    Account[id=A102,name=Kumar,balance=100]
    92,
    Rectangle[length=1.2,width=3.4]
    Rectangle[length=1.0,width=1.0]
    Rectangle[length=5.6,width=7.8]
    length is: 5.6
    width is: 7.8
    area is: 43.68
    perimeter is: 26.80
    38,
    Account[id=A101,name=Tan Ah Teck,balance=88]
    Account[id=A102,name=Kumar,balance=0]
    ID: A101 
    Name: Tan Ah Teck
    Balance: 88 
    Account[id=A101,name=Tan Ah Teck,balance=188]
    Account[id=A101,name=Tan Ah Teck,balance=138]
    Amount exceeded balance
    Account[id=A101,name=Tan Ah Teck,balance=138]
    Account[id=A101,name=Tan Ah Teck,balance=38]
    Account[id=A102,name=Kumar,balance=100]
    94,
    Account[id=A101,name=Tan Ah Teck,balance=88]
    Account[id=A102,name=Kumar,balance=0]
    ID: A101 
    Name: Tan Ah Teck
    Balance: 88 
    Account[id=A101,name=Tan Ah Teck,balance=188]
    Account[id=A101,name=Tan Ah Teck,balance=138]
    Amount exceeded balance
    Account[id=A101,name=Tan Ah Teck,balance=138]
    Account[id=A101,name=Tan Ah Teck,balance=38]
    Account[id=A102,name=Kumar,balance=100]
    95: similar to the above.

Write the code for the

Account[id=A101,name=Tan Ah Teck,balance=88]
Account[id=A102,name=Kumar,balance=0]
ID: A101 
Name: Tan Ah Teck
Balance: 88 
Account[id=A101,name=Tan Ah Teck,balance=188]
Account[id=A101,name=Tan Ah Teck,balance=138]
Amount exceeded balance
Account[id=A101,name=Tan Ah Teck,balance=138]
Account[id=A101,name=Tan Ah Teck,balance=38]
Account[id=A102,name=Kumar,balance=100]
68 class. Also write a test driver (called
Account[id=A101,name=Tan Ah Teck,balance=88]
Account[id=A102,name=Kumar,balance=0]
ID: A101 
Name: Tan Ah Teck
Balance: 88 
Account[id=A101,name=Tan Ah Teck,balance=188]
Account[id=A101,name=Tan Ah Teck,balance=138]
Amount exceeded balance
Account[id=A101,name=Tan Ah Teck,balance=138]
Account[id=A101,name=Tan Ah Teck,balance=38]
Account[id=A102,name=Kumar,balance=100]
97) to test all the
Account[id=A101,name=Tan Ah Teck,balance=88]
Account[id=A102,name=Kumar,balance=0]
ID: A101 
Name: Tan Ah Teck
Balance: 88 
Account[id=A101,name=Tan Ah Teck,balance=188]
Account[id=A101,name=Tan Ah Teck,balance=138]
Amount exceeded balance
Account[id=A101,name=Tan Ah Teck,balance=138]
Account[id=A101,name=Tan Ah Teck,balance=38]
Account[id=A102,name=Kumar,balance=100]
7 methods defined in the
Account[id=A101,name=Tan Ah Teck,balance=88]
Account[id=A102,name=Kumar,balance=0]
ID: A101 
Name: Tan Ah Teck
Balance: 88 
Account[id=A101,name=Tan Ah Teck,balance=188]
Account[id=A101,name=Tan Ah Teck,balance=138]
Amount exceeded balance
Account[id=A101,name=Tan Ah Teck,balance=138]
Account[id=A101,name=Tan Ah Teck,balance=38]
Account[id=A102,name=Kumar,balance=100]
68 class.

Ex: The MyDate Class

What kind of data is the colors of the cars around the gym in the scenario

A class called

01/02/2014
09/12/2099
Month: 12
Day: 9
Year: 2099
03/04/2016
00, which models a date instance, is defined as shown in the class diagram.

The

01/02/2014
09/12/2099
Month: 12
Day: 9
Year: 2099
03/04/2016
00 class contains the following
Account[id=A101,name=Tan Ah Teck,balance=88]
Account[id=A102,name=Kumar,balance=0]
ID: A101 
Name: Tan Ah Teck
Balance: 88 
Account[id=A101,name=Tan Ah Teck,balance=188]
Account[id=A101,name=Tan Ah Teck,balance=138]
Amount exceeded balance
Account[id=A101,name=Tan Ah Teck,balance=138]
Account[id=A101,name=Tan Ah Teck,balance=38]
Account[id=A102,name=Kumar,balance=100]
0 instance variables:

  • 01/02/2014
    09/12/2099
    Month: 12
    Day: 9
    Year: 2099
    03/04/2016
    03 (
    Rectangle[length=1.2,width=3.4]
    Rectangle[length=1.0,width=1.0]
    Rectangle[length=5.6,width=7.8]
    length is: 5.6
    width is: 7.8
    area is: 43.68
    perimeter is: 26.80
    81): Between
    InvoiceItem[id=A101,desc=Pen Red,qty=888,unitPrice=0.08]
    InvoiceItem[id=A101,desc=Pen Red,qty=999,unitPrice=0.99]
    id is: A101
    desc is: Pen Red
    qty is: 999
    unitPrice is: 0.99
    The total is: 989.01
    
    10 to
    01/02/2014
    09/12/2099
    Month: 12
    Day: 9
    Year: 2099
    03/04/2016
    06.
  • 01/02/2014
    09/12/2099
    Month: 12
    Day: 9
    Year: 2099
    03/04/2016
    07 (
    Rectangle[length=1.2,width=3.4]
    Rectangle[length=1.0,width=1.0]
    Rectangle[length=5.6,width=7.8]
    length is: 5.6
    width is: 7.8
    area is: 43.68
    perimeter is: 26.80
    81): Between
    InvoiceItem[id=A101,desc=Pen Red,qty=888,unitPrice=0.08]
    InvoiceItem[id=A101,desc=Pen Red,qty=999,unitPrice=0.99]
    id is: A101
    desc is: Pen Red
    qty is: 999
    unitPrice is: 0.99
    The total is: 989.01
    
    10 (Jan) to
    01/02/2014
    09/12/2099
    Month: 12
    Day: 9
    Year: 2099
    03/04/2016
    10 (Dec).
  • 01/02/2014
    09/12/2099
    Month: 12
    Day: 9
    Year: 2099
    03/04/2016
    11 (
    Rectangle[length=1.2,width=3.4]
    Rectangle[length=1.0,width=1.0]
    Rectangle[length=5.6,width=7.8]
    length is: 5.6
    width is: 7.8
    area is: 43.68
    perimeter is: 26.80
    81): Between
    InvoiceItem[id=A101,desc=Pen Red,qty=888,unitPrice=0.08]
    InvoiceItem[id=A101,desc=Pen Red,qty=999,unitPrice=0.99]
    id is: A101
    desc is: Pen Red
    qty is: 999
    unitPrice is: 0.99
    The total is: 989.01
    
    10 to
    01/02/2014
    09/12/2099
    Month: 12
    Day: 9
    Year: 2099
    03/04/2016
    14, where the last day depends on the month and whether it is a leap year for Feb (
    01/02/2014
    09/12/2099
    Month: 12
    Day: 9
    Year: 2099
    03/04/2016
    15).

It also contains the following

Account[id=A101,name=Tan Ah Teck,balance=88]
Account[id=A102,name=Kumar,balance=0]
ID: A101 
Name: Tan Ah Teck
Balance: 88 
Account[id=A101,name=Tan Ah Teck,balance=188]
Account[id=A101,name=Tan Ah Teck,balance=138]
Amount exceeded balance
Account[id=A101,name=Tan Ah Teck,balance=138]
Account[id=A101,name=Tan Ah Teck,balance=38]
Account[id=A102,name=Kumar,balance=100]
7
01/02/2014
09/12/2099
Month: 12
Day: 9
Year: 2099
03/04/2016
17 variables (drawn with underlined in the class diagram):

  • 01/02/2014
    09/12/2099
    Month: 12
    Day: 9
    Year: 2099
    03/04/2016
    18 (
    01/02/2014
    09/12/2099
    Month: 12
    Day: 9
    Year: 2099
    03/04/2016
    19),
    01/02/2014
    09/12/2099
    Month: 12
    Day: 9
    Year: 2099
    03/04/2016
    20 (
    01/02/2014
    09/12/2099
    Month: 12
    Day: 9
    Year: 2099
    03/04/2016
    19), and DAY_IN_
    01/02/2014
    09/12/2099
    Month: 12
    Day: 9
    Year: 2099
    03/04/2016
    18 (
    01/02/2014
    09/12/2099
    Month: 12
    Day: 9
    Year: 2099
    03/04/2016
    23):
    01/02/2014
    09/12/2099
    Month: 12
    Day: 9
    Year: 2099
    03/04/2016
    24 variables, initialized as shown, which are used in the methods.

The

01/02/2014
09/12/2099
Month: 12
Day: 9
Year: 2099
03/04/2016
00 class has the following
Account[id=A101,name=Tan Ah Teck,balance=88]
Account[id=A102,name=Kumar,balance=0]
ID: A101 
Name: Tan Ah Teck
Balance: 88 
Account[id=A101,name=Tan Ah Teck,balance=188]
Account[id=A101,name=Tan Ah Teck,balance=138]
Amount exceeded balance
Account[id=A101,name=Tan Ah Teck,balance=138]
Account[id=A101,name=Tan Ah Teck,balance=38]
Account[id=A102,name=Kumar,balance=100]
7
01/02/2014
09/12/2099
Month: 12
Day: 9
Year: 2099
03/04/2016
24 methods (drawn with underlined in the class diagram):

  • 01/02/2014
    09/12/2099
    Month: 12
    Day: 9
    Year: 2099
    03/04/2016
    28: returns
    InvoiceItem[id=A101,desc=Pen Red,qty=888,unitPrice=0.08]
    InvoiceItem[id=A101,desc=Pen Red,qty=999,unitPrice=0.99]
    id is: A101
    desc is: Pen Red
    qty is: 999
    unitPrice is: 0.99
    The total is: 989.01
    
    70 if the given
    01/02/2014
    09/12/2099
    Month: 12
    Day: 9
    Year: 2099
    03/04/2016
    03 is a leap year. A year is a leap year if it is divisible by 4 but not by 100, or it is divisible by 400.
  • 01/02/2014
    09/12/2099
    Month: 12
    Day: 9
    Year: 2099
    03/04/2016
    31: returns
    InvoiceItem[id=A101,desc=Pen Red,qty=888,unitPrice=0.08]
    InvoiceItem[id=A101,desc=Pen Red,qty=999,unitPrice=0.99]
    id is: A101
    desc is: Pen Red
    qty is: 999
    unitPrice is: 0.99
    The total is: 989.01
    
    70 if the given
    01/02/2014
    09/12/2099
    Month: 12
    Day: 9
    Year: 2099
    03/04/2016
    03,
    01/02/2014
    09/12/2099
    Month: 12
    Day: 9
    Year: 2099
    03/04/2016
    07, and
    01/02/2014
    09/12/2099
    Month: 12
    Day: 9
    Year: 2099
    03/04/2016
    11 constitute a valid date. Assume that
    01/02/2014
    09/12/2099
    Month: 12
    Day: 9
    Year: 2099
    03/04/2016
    03 is between
    InvoiceItem[id=A101,desc=Pen Red,qty=888,unitPrice=0.08]
    InvoiceItem[id=A101,desc=Pen Red,qty=999,unitPrice=0.99]
    id is: A101
    desc is: Pen Red
    qty is: 999
    unitPrice is: 0.99
    The total is: 989.01
    
    10 and
    01/02/2014
    09/12/2099
    Month: 12
    Day: 9
    Year: 2099
    03/04/2016
    06,
    01/02/2014
    09/12/2099
    Month: 12
    Day: 9
    Year: 2099
    03/04/2016
    07 is between
    InvoiceItem[id=A101,desc=Pen Red,qty=888,unitPrice=0.08]
    InvoiceItem[id=A101,desc=Pen Red,qty=999,unitPrice=0.99]
    id is: A101
    desc is: Pen Red
    qty is: 999
    unitPrice is: 0.99
    The total is: 989.01
    
    10 (Jan) to
    01/02/2014
    09/12/2099
    Month: 12
    Day: 9
    Year: 2099
    03/04/2016
    10 (Dec) and
    01/02/2014
    09/12/2099
    Month: 12
    Day: 9
    Year: 2099
    03/04/2016
    11 shall be between
    InvoiceItem[id=A101,desc=Pen Red,qty=888,unitPrice=0.08]
    InvoiceItem[id=A101,desc=Pen Red,qty=999,unitPrice=0.99]
    id is: A101
    desc is: Pen Red
    qty is: 999
    unitPrice is: 0.99
    The total is: 989.01
    
    10 and
    01/02/2014
    09/12/2099
    Month: 12
    Day: 9
    Year: 2099
    03/04/2016
    14 depending on the
    01/02/2014
    09/12/2099
    Month: 12
    Day: 9
    Year: 2099
    03/04/2016
    07 and whether it is a leap year on Feb.
  • 01/02/2014
    09/12/2099
    Month: 12
    Day: 9
    Year: 2099
    03/04/2016
    46: returns the day of the week, where
    01/02/2014
    09/12/2099
    Month: 12
    Day: 9
    Year: 2099
    03/04/2016
    47 for Sun,
    InvoiceItem[id=A101,desc=Pen Red,qty=888,unitPrice=0.08]
    InvoiceItem[id=A101,desc=Pen Red,qty=999,unitPrice=0.99]
    id is: A101
    desc is: Pen Red
    qty is: 999
    unitPrice is: 0.99
    The total is: 989.01
    
    10 for Mon, ...,
    01/02/2014
    09/12/2099
    Month: 12
    Day: 9
    Year: 2099
    03/04/2016
    49 for Sat, for the given date. Assume that the date is valid. Read the earlier exercise on how to determine the day of the week (or Wiki "Determination of the day of the week").

The

01/02/2014
09/12/2099
Month: 12
Day: 9
Year: 2099
03/04/2016
00 class has one constructor, which takes 3 parameters:
01/02/2014
09/12/2099
Month: 12
Day: 9
Year: 2099
03/04/2016
03,
01/02/2014
09/12/2099
Month: 12
Day: 9
Year: 2099
03/04/2016
07 and
01/02/2014
09/12/2099
Month: 12
Day: 9
Year: 2099
03/04/2016
11. It shall invoke
01/02/2014
09/12/2099
Month: 12
Day: 9
Year: 2099
03/04/2016
54 method (to be described later) to set the instance variables.

The

01/02/2014
09/12/2099
Month: 12
Day: 9
Year: 2099
03/04/2016
00 class has the following
Account[id=A101,name=Tan Ah Teck,balance=88]
Account[id=A102,name=Kumar,balance=0]
ID: A101 
Name: Tan Ah Teck
Balance: 88 
Account[id=A101,name=Tan Ah Teck,balance=188]
Account[id=A101,name=Tan Ah Teck,balance=138]
Amount exceeded balance
Account[id=A101,name=Tan Ah Teck,balance=138]
Account[id=A101,name=Tan Ah Teck,balance=38]
Account[id=A102,name=Kumar,balance=100]
7 methods:

  • 01/02/2014
    09/12/2099
    Month: 12
    Day: 9
    Year: 2099
    03/04/2016
    57: It shall invoke the
    01/02/2014
    09/12/2099
    Month: 12
    Day: 9
    Year: 2099
    03/04/2016
    24 method
    01/02/2014
    09/12/2099
    Month: 12
    Day: 9
    Year: 2099
    03/04/2016
    59 to verify that the given
    01/02/2014
    09/12/2099
    Month: 12
    Day: 9
    Year: 2099
    03/04/2016
    03,
    01/02/2014
    09/12/2099
    Month: 12
    Day: 9
    Year: 2099
    03/04/2016
    07 and
    01/02/2014
    09/12/2099
    Month: 12
    Day: 9
    Year: 2099
    03/04/2016
    11 constitute a valid date.
    (Advanced: Otherwise, it shall throw an
    Account[id=A101,name=Tan Ah Teck,balance=88]
    Account[id=A102,name=Kumar,balance=0]
    ID: A101 
    Name: Tan Ah Teck
    Balance: 88 
    Account[id=A101,name=Tan Ah Teck,balance=188]
    Account[id=A101,name=Tan Ah Teck,balance=138]
    Amount exceeded balance
    Account[id=A101,name=Tan Ah Teck,balance=138]
    Account[id=A101,name=Tan Ah Teck,balance=38]
    Account[id=A102,name=Kumar,balance=100]
    78 with the message "Invalid year, month, or day!".)
  • 01/02/2014
    09/12/2099
    Month: 12
    Day: 9
    Year: 2099
    03/04/2016
    64: It shall verify that the given
    01/02/2014
    09/12/2099
    Month: 12
    Day: 9
    Year: 2099
    03/04/2016
    03 is between
    InvoiceItem[id=A101,desc=Pen Red,qty=888,unitPrice=0.08]
    InvoiceItem[id=A101,desc=Pen Red,qty=999,unitPrice=0.99]
    id is: A101
    desc is: Pen Red
    qty is: 999
    unitPrice is: 0.99
    The total is: 989.01
    
    10 and
    01/02/2014
    09/12/2099
    Month: 12
    Day: 9
    Year: 2099
    03/04/2016
    06.
    (Advanced: Otherwise, it shall throw an
    Account[id=A101,name=Tan Ah Teck,balance=88]
    Account[id=A102,name=Kumar,balance=0]
    ID: A101 
    Name: Tan Ah Teck
    Balance: 88 
    Account[id=A101,name=Tan Ah Teck,balance=188]
    Account[id=A101,name=Tan Ah Teck,balance=138]
    Amount exceeded balance
    Account[id=A101,name=Tan Ah Teck,balance=138]
    Account[id=A101,name=Tan Ah Teck,balance=38]
    Account[id=A102,name=Kumar,balance=100]
    78 with the message "Invalid year!".)
  • 01/02/2014
    09/12/2099
    Month: 12
    Day: 9
    Year: 2099
    03/04/2016
    69: It shall verify that the given
    01/02/2014
    09/12/2099
    Month: 12
    Day: 9
    Year: 2099
    03/04/2016
    07 is between
    InvoiceItem[id=A101,desc=Pen Red,qty=888,unitPrice=0.08]
    InvoiceItem[id=A101,desc=Pen Red,qty=999,unitPrice=0.99]
    id is: A101
    desc is: Pen Red
    qty is: 999
    unitPrice is: 0.99
    The total is: 989.01
    
    10 and
    01/02/2014
    09/12/2099
    Month: 12
    Day: 9
    Year: 2099
    03/04/2016
    10.
    (Advanced: Otherwise, it shall throw an
    Account[id=A101,name=Tan Ah Teck,balance=88]
    Account[id=A102,name=Kumar,balance=0]
    ID: A101 
    Name: Tan Ah Teck
    Balance: 88 
    Account[id=A101,name=Tan Ah Teck,balance=188]
    Account[id=A101,name=Tan Ah Teck,balance=138]
    Amount exceeded balance
    Account[id=A101,name=Tan Ah Teck,balance=138]
    Account[id=A101,name=Tan Ah Teck,balance=38]
    Account[id=A102,name=Kumar,balance=100]
    78 with the message "Invalid month!".)
  • 01/02/2014
    09/12/2099
    Month: 12
    Day: 9
    Year: 2099
    03/04/2016
    74: It shall verify that the given
    01/02/2014
    09/12/2099
    Month: 12
    Day: 9
    Year: 2099
    03/04/2016
    11 is between
    InvoiceItem[id=A101,desc=Pen Red,qty=888,unitPrice=0.08]
    InvoiceItem[id=A101,desc=Pen Red,qty=999,unitPrice=0.99]
    id is: A101
    desc is: Pen Red
    qty is: 999
    unitPrice is: 0.99
    The total is: 989.01
    
    10 and
    01/02/2014
    09/12/2099
    Month: 12
    Day: 9
    Year: 2099
    03/04/2016
    77, where
    01/02/2014
    09/12/2099
    Month: 12
    Day: 9
    Year: 2099
    03/04/2016
    77 depends on the
    01/02/2014
    09/12/2099
    Month: 12
    Day: 9
    Year: 2099
    03/04/2016
    07 and whether it is a leap year for Feb.
    (Advanced: Otherwise, it shall throw an
    Account[id=A101,name=Tan Ah Teck,balance=88]
    Account[id=A102,name=Kumar,balance=0]
    ID: A101 
    Name: Tan Ah Teck
    Balance: 88 
    Account[id=A101,name=Tan Ah Teck,balance=188]
    Account[id=A101,name=Tan Ah Teck,balance=138]
    Amount exceeded balance
    Account[id=A101,name=Tan Ah Teck,balance=138]
    Account[id=A101,name=Tan Ah Teck,balance=38]
    Account[id=A102,name=Kumar,balance=100]
    78 with the message "Invalid month!".)
  • 01/02/2014
    09/12/2099
    Month: 12
    Day: 9
    Year: 2099
    03/04/2016
    81,
    01/02/2014
    09/12/2099
    Month: 12
    Day: 9
    Year: 2099
    03/04/2016
    82,
    01/02/2014
    09/12/2099
    Month: 12
    Day: 9
    Year: 2099
    03/04/2016
    83: return the value for the
    01/02/2014
    09/12/2099
    Month: 12
    Day: 9
    Year: 2099
    03/04/2016
    03,
    01/02/2014
    09/12/2099
    Month: 12
    Day: 9
    Year: 2099
    03/04/2016
    07 and
    01/02/2014
    09/12/2099
    Month: 12
    Day: 9
    Year: 2099
    03/04/2016
    11, respectively.
  • public Author (String name, String email, char gender) {......}
    5: returns a date string in the format "
    01/02/2014
    09/12/2099
    Month: 12
    Day: 9
    Year: 2099
    03/04/2016
    88", e.g., "Tuesday 14 Feb 2012".
  • 01/02/2014
    09/12/2099
    Month: 12
    Day: 9
    Year: 2099
    03/04/2016
    89: update
    public Author (String name, String email, char gender) {......}
    1 instance to the next day and return
    public Author (String name, String email, char gender) {......}
    1 instance. Take note that
    01/02/2014
    09/12/2099
    Month: 12
    Day: 9
    Year: 2099
    03/04/2016
    89 for
    01/02/2014
    09/12/2099
    Month: 12
    Day: 9
    Year: 2099
    03/04/2016
    93 shall be
    01/02/2014
    09/12/2099
    Month: 12
    Day: 9
    Year: 2099
    03/04/2016
    94.
  • 01/02/2014
    09/12/2099
    Month: 12
    Day: 9
    Year: 2099
    03/04/2016
    95: update
    public Author (String name, String email, char gender) {......}
    1 instance to the next month and return
    public Author (String name, String email, char gender) {......}
    1 instance. Take note that
    01/02/2014
    09/12/2099
    Month: 12
    Day: 9
    Year: 2099
    03/04/2016
    95 for
    01/02/2014
    09/12/2099
    Month: 12
    Day: 9
    Year: 2099
    03/04/2016
    99 shall be
    01:02:03
    04:05:06
    Hour: 4
    Minute: 5
    Second: 6
    23:59:58
    23:59:59
    00:00:01
    00:00:00
    23:59:58
    00.
  • 01:02:03
    04:05:06
    Hour: 4
    Minute: 5
    Second: 6
    23:59:58
    23:59:59
    00:00:01
    00:00:00
    23:59:58
    01: update
    public Author (String name, String email, char gender) {......}
    1 instance to the next year and return
    public Author (String name, String email, char gender) {......}
    1 instance. Take note that
    01:02:03
    04:05:06
    Hour: 4
    Minute: 5
    Second: 6
    23:59:58
    23:59:59
    00:00:01
    00:00:00
    23:59:58
    01 for
    01:02:03
    04:05:06
    Hour: 4
    Minute: 5
    Second: 6
    23:59:58
    23:59:59
    00:00:01
    00:00:00
    23:59:58
    05 shall be
    01:02:03
    04:05:06
    Hour: 4
    Minute: 5
    Second: 6
    23:59:58
    23:59:59
    00:00:01
    00:00:00
    23:59:58
    06.
    (Advanced: throw an
    01:02:03
    04:05:06
    Hour: 4
    Minute: 5
    Second: 6
    23:59:58
    23:59:59
    00:00:01
    00:00:00
    23:59:58
    07 with the message "Year out of range!" if year > 9999.)
  • 01:02:03
    04:05:06
    Hour: 4
    Minute: 5
    Second: 6
    23:59:58
    23:59:59
    00:00:01
    00:00:00
    23:59:58
    08,
    01:02:03
    04:05:06
    Hour: 4
    Minute: 5
    Second: 6
    23:59:58
    23:59:59
    00:00:01
    00:00:00
    23:59:58
    09,
    01:02:03
    04:05:06
    Hour: 4
    Minute: 5
    Second: 6
    23:59:58
    23:59:59
    00:00:01
    00:00:00
    23:59:58
    10: similar to the above.

Write the code for the

01/02/2014
09/12/2099
Month: 12
Day: 9
Year: 2099
03/04/2016
00 class.

Use the following test statements to test the

01/02/2014
09/12/2099
Month: 12
Day: 9
Year: 2099
03/04/2016
00 class:

Write a test program that tests the

01/02/2014
09/12/2099
Month: 12
Day: 9
Year: 2099
03/04/2016
89 in a loop, by printing the dates from
01:02:03
04:05:06
Hour: 4
Minute: 5
Second: 6
23:59:58
23:59:59
00:00:01
00:00:00
23:59:58
14 to
01:02:03
04:05:06
Hour: 4
Minute: 5
Second: 6
23:59:58
23:59:59
00:00:01
00:00:00
23:59:58
15.

Ex: Bouncing Balls - Ball and Container Classes

What kind of data is the colors of the cars around the gym in the scenario

A class called

Rectangle[length=1.2,width=3.4]
Rectangle[length=1.0,width=1.0]
Rectangle[length=5.6,width=7.8]
length is: 5.6
width is: 7.8
area is: 43.68
perimeter is: 26.80
42 is designed as shown in the class diagram.

The

Rectangle[length=1.2,width=3.4]
Rectangle[length=1.0,width=1.0]
Rectangle[length=5.6,width=7.8]
length is: 5.6
width is: 7.8
area is: 43.68
perimeter is: 26.80
42 class contains the following
Account[id=A101,name=Tan Ah Teck,balance=88]
Account[id=A102,name=Kumar,balance=0]
ID: A101 
Name: Tan Ah Teck
Balance: 88 
Account[id=A101,name=Tan Ah Teck,balance=188]
Account[id=A101,name=Tan Ah Teck,balance=138]
Amount exceeded balance
Account[id=A101,name=Tan Ah Teck,balance=138]
Account[id=A101,name=Tan Ah Teck,balance=38]
Account[id=A102,name=Kumar,balance=100]
0 instance variables:

  • Employee[id=8,name=Peter Tan,salary=2500]
    Employee[id=8,name=Peter Tan,salary=999]
    id is: 8
    firstname is: Peter
    lastname is: Tan
    salary is: 999
    name is: Peter Tan
    annual salary is: 11988
    1098
    Employee[id=8,name=Peter Tan,salary=1098]
    55,
    Employee[id=8,name=Peter Tan,salary=2500]
    Employee[id=8,name=Peter Tan,salary=999]
    id is: 8
    firstname is: Peter
    lastname is: Tan
    salary is: 999
    name is: Peter Tan
    annual salary is: 11988
    1098
    Employee[id=8,name=Peter Tan,salary=1098]
    57 and
    Account[id=A101,name=Tan Ah Teck,balance=88]
    Account[id=A102,name=Kumar,balance=0]
    ID: A101 
    Name: Tan Ah Teck
    Balance: 88 
    Account[id=A101,name=Tan Ah Teck,balance=188]
    Account[id=A101,name=Tan Ah Teck,balance=138]
    Amount exceeded balance
    Account[id=A101,name=Tan Ah Teck,balance=138]
    Account[id=A101,name=Tan Ah Teck,balance=38]
    Account[id=A102,name=Kumar,balance=100]
    1, which represent the ball's center
    Employee[id=8,name=Peter Tan,salary=2500]
    Employee[id=8,name=Peter Tan,salary=999]
    id is: 8
    firstname is: Peter
    lastname is: Tan
    salary is: 999
    name is: Peter Tan
    annual salary is: 11988
    1098
    Employee[id=8,name=Peter Tan,salary=1098]
    72 co-ordinates and the radius, respectively.
  • 01:02:03
    04:05:06
    Hour: 4
    Minute: 5
    Second: 6
    23:59:58
    23:59:59
    00:00:01
    00:00:00
    23:59:58
    23 (
    01:02:03
    04:05:06
    Hour: 4
    Minute: 5
    Second: 6
    23:59:58
    23:59:59
    00:00:01
    00:00:00
    23:59:58
    24) and
    01:02:03
    04:05:06
    Hour: 4
    Minute: 5
    Second: 6
    23:59:58
    23:59:59
    00:00:01
    00:00:00
    23:59:58
    25 (
    01:02:03
    04:05:06
    Hour: 4
    Minute: 5
    Second: 6
    23:59:58
    23:59:59
    00:00:01
    00:00:00
    23:59:58
    26), which represent the displacement (movement) per step, in the
    Employee[id=8,name=Peter Tan,salary=2500]
    Employee[id=8,name=Peter Tan,salary=999]
    id is: 8
    firstname is: Peter
    lastname is: Tan
    salary is: 999
    name is: Peter Tan
    annual salary is: 11988
    1098
    Employee[id=8,name=Peter Tan,salary=1098]
    55 and
    Employee[id=8,name=Peter Tan,salary=2500]
    Employee[id=8,name=Peter Tan,salary=999]
    id is: 8
    firstname is: Peter
    lastname is: Tan
    salary is: 999
    name is: Peter Tan
    annual salary is: 11988
    1098
    Employee[id=8,name=Peter Tan,salary=1098]
    57 direction respectively.

The

Rectangle[length=1.2,width=3.4]
Rectangle[length=1.0,width=1.0]
Rectangle[length=5.6,width=7.8]
length is: 5.6
width is: 7.8
area is: 43.68
perimeter is: 26.80
42 class contains the following
Account[id=A101,name=Tan Ah Teck,balance=88]
Account[id=A102,name=Kumar,balance=0]
ID: A101 
Name: Tan Ah Teck
Balance: 88 
Account[id=A101,name=Tan Ah Teck,balance=188]
Account[id=A101,name=Tan Ah Teck,balance=138]
Amount exceeded balance
Account[id=A101,name=Tan Ah Teck,balance=138]
Account[id=A101,name=Tan Ah Teck,balance=38]
Account[id=A102,name=Kumar,balance=100]
7 methods:

  • A constructor which accepts
    Employee[id=8,name=Peter Tan,salary=2500]
    Employee[id=8,name=Peter Tan,salary=999]
    id is: 8
    firstname is: Peter
    lastname is: Tan
    salary is: 999
    name is: Peter Tan
    annual salary is: 11988
    1098
    Employee[id=8,name=Peter Tan,salary=1098]
    55,
    Employee[id=8,name=Peter Tan,salary=2500]
    Employee[id=8,name=Peter Tan,salary=999]
    id is: 8
    firstname is: Peter
    lastname is: Tan
    salary is: 999
    name is: Peter Tan
    annual salary is: 11988
    1098
    Employee[id=8,name=Peter Tan,salary=1098]
    57,
    Account[id=A101,name=Tan Ah Teck,balance=88]
    Account[id=A102,name=Kumar,balance=0]
    ID: A101 
    Name: Tan Ah Teck
    Balance: 88 
    Account[id=A101,name=Tan Ah Teck,balance=188]
    Account[id=A101,name=Tan Ah Teck,balance=138]
    Amount exceeded balance
    Account[id=A101,name=Tan Ah Teck,balance=138]
    Account[id=A101,name=Tan Ah Teck,balance=38]
    Account[id=A102,name=Kumar,balance=100]
    1,
    01:02:03
    04:05:06
    Hour: 4
    Minute: 5
    Second: 6
    23:59:58
    23:59:59
    00:00:01
    00:00:00
    23:59:58
    34, and
    01:02:03
    04:05:06
    Hour: 4
    Minute: 5
    Second: 6
    23:59:58
    23:59:59
    00:00:01
    00:00:00
    23:59:58
    35 as arguments. For user friendliness, user specifies
    01:02:03
    04:05:06
    Hour: 4
    Minute: 5
    Second: 6
    23:59:58
    23:59:59
    00:00:01
    00:00:00
    23:59:58
    34 (in pixels per step) and
    01:02:03
    04:05:06
    Hour: 4
    Minute: 5
    Second: 6
    23:59:58
    23:59:59
    00:00:01
    00:00:00
    23:59:58
    35 (in degrees in the range of
    01:02:03
    04:05:06
    Hour: 4
    Minute: 5
    Second: 6
    23:59:58
    23:59:59
    00:00:01
    00:00:00
    23:59:58
    38). For the internal operations, the
    01:02:03
    04:05:06
    Hour: 4
    Minute: 5
    Second: 6
    23:59:58
    23:59:59
    00:00:01
    00:00:00
    23:59:58
    34 and
    01:02:03
    04:05:06
    Hour: 4
    Minute: 5
    Second: 6
    23:59:58
    23:59:59
    00:00:01
    00:00:00
    23:59:58
    35 are to be converted to
    01:02:03
    04:05:06
    Hour: 4
    Minute: 5
    Second: 6
    23:59:58
    23:59:59
    00:00:01
    00:00:00
    23:59:58
    41 in the internal representation. Note that the y-axis of the Java graphics coordinate system is inverted, i.e., the origin
    Employee[id=8,name=Peter Tan,salary=2500]
    Employee[id=8,name=Peter Tan,salary=999]
    id is: 8
    firstname is: Peter
    lastname is: Tan
    salary is: 999
    name is: Peter Tan
    annual salary is: 11988
    1098
    Employee[id=8,name=Peter Tan,salary=1098]
    59 is located at the top-left corner.
    What kind of data is the colors of the cars around the gym in the scenario
    Employee[id=8,name=Peter Tan,salary=2500]
    Employee[id=8,name=Peter Tan,salary=999]
    id is: 8
    firstname is: Peter
    lastname is: Tan
    salary is: 999
    name is: Peter Tan
    annual salary is: 11988
    1098
    Employee[id=8,name=Peter Tan,salary=1098]
    5
  • Getter and setter for all the instance variables.
  • A method
    01:02:03
    04:05:06
    Hour: 4
    Minute: 5
    Second: 6
    23:59:58
    23:59:59
    00:00:01
    00:00:00
    23:59:58
    43 which move the ball by one step.
    Employee[id=8,name=Peter Tan,salary=2500]
    Employee[id=8,name=Peter Tan,salary=999]
    id is: 8
    firstname is: Peter
    lastname is: Tan
    salary is: 999
    name is: Peter Tan
    annual salary is: 11988
    1098
    Employee[id=8,name=Peter Tan,salary=1098]
    6
  • Rectangle[length=1.2,width=3.4]
    Rectangle[length=1.0,width=1.0]
    Rectangle[length=5.6,width=7.8]
    length is: 5.6
    width is: 7.8
    area is: 43.68
    perimeter is: 26.80
    43 which reflects the ball horizontally (i.e., hitting a vertical wall)
    Employee[id=8,name=Peter Tan,salary=2500]
    Employee[id=8,name=Peter Tan,salary=999]
    id is: 8
    firstname is: Peter
    lastname is: Tan
    salary is: 999
    name is: Peter Tan
    annual salary is: 11988
    1098
    Employee[id=8,name=Peter Tan,salary=1098]
    7
  • Rectangle[length=1.2,width=3.4]
    Rectangle[length=1.0,width=1.0]
    Rectangle[length=5.6,width=7.8]
    length is: 5.6
    width is: 7.8
    area is: 43.68
    perimeter is: 26.80
    44 (the ball hits a horizontal wall).
    Employee[id=8,name=Peter Tan,salary=2500]
    Employee[id=8,name=Peter Tan,salary=999]
    id is: 8
    firstname is: Peter
    lastname is: Tan
    salary is: 999
    name is: Peter Tan
    annual salary is: 11988
    1098
    Employee[id=8,name=Peter Tan,salary=1098]
    8
  • public Author (String name, String email, char gender) {......}
    5 which prints the message "
    01:02:03
    04:05:06
    Hour: 4
    Minute: 5
    Second: 6
    23:59:58
    23:59:59
    00:00:01
    00:00:00
    23:59:58
    47".

Write the

Rectangle[length=1.2,width=3.4]
Rectangle[length=1.0,width=1.0]
Rectangle[length=5.6,width=7.8]
length is: 5.6
width is: 7.8
area is: 43.68
perimeter is: 26.80
42 class. Also write a test program to test all the methods defined in the class.


What kind of data is the colors of the cars around the gym in the scenario

A class called

01:02:03
04:05:06
Hour: 4
Minute: 5
Second: 6
23:59:58
23:59:59
00:00:01
00:00:00
23:59:58
49, which represents the enclosing box for the ball, is designed as shown in the class diagram. It contains:

  • Instance variables
    01:02:03
    04:05:06
    Hour: 4
    Minute: 5
    Second: 6
    23:59:58
    23:59:59
    00:00:01
    00:00:00
    23:59:58
    50 and
    01:02:03
    04:05:06
    Hour: 4
    Minute: 5
    Second: 6
    23:59:58
    23:59:59
    00:00:01
    00:00:00
    23:59:58
    51 which denote the top-left and bottom-right corners of the rectangular box.
  • A constructor which accepts
    Employee[id=8,name=Peter Tan,salary=2500]
    Employee[id=8,name=Peter Tan,salary=999]
    id is: 8
    firstname is: Peter
    lastname is: Tan
    salary is: 999
    name is: Peter Tan
    annual salary is: 11988
    1098
    Employee[id=8,name=Peter Tan,salary=1098]
    72 of the top-left corner,
    01:02:03
    04:05:06
    Hour: 4
    Minute: 5
    Second: 6
    23:59:58
    23:59:59
    00:00:01
    00:00:00
    23:59:58
    53 and
    01:02:03
    04:05:06
    Hour: 4
    Minute: 5
    Second: 6
    23:59:58
    23:59:59
    00:00:01
    00:00:00
    23:59:58
    54 as argument, and converts them into the internal representation (i.e.,
    01:02:03
    04:05:06
    Hour: 4
    Minute: 5
    Second: 6
    23:59:58
    23:59:59
    00:00:01
    00:00:00
    23:59:58
    55).
    01:02:03
    04:05:06
    Hour: 4
    Minute: 5
    Second: 6
    23:59:58
    23:59:59
    00:00:01
    00:00:00
    23:59:58
    56 and
    01:02:03
    04:05:06
    Hour: 4
    Minute: 5
    Second: 6
    23:59:58
    23:59:59
    00:00:01
    00:00:00
    23:59:58
    54 is used in the argument for safer operation (there is no need to check the validity of
    01:02:03
    04:05:06
    Hour: 4
    Minute: 5
    Second: 6
    23:59:58
    23:59:59
    00:00:01
    00:00:00
    23:59:58
    58 etc.).
  • A
    public Author (String name, String email, char gender) {......}
    5 method that returns "
    01:02:03
    04:05:06
    Hour: 4
    Minute: 5
    Second: 6
    23:59:58
    23:59:59
    00:00:01
    00:00:00
    23:59:58
    60".
  • A
    01:02:03
    04:05:06
    Hour: 4
    Minute: 5
    Second: 6
    23:59:58
    23:59:59
    00:00:01
    00:00:00
    23:59:58
    61 method called
    01:02:03
    04:05:06
    Hour: 4
    Minute: 5
    Second: 6
    23:59:58
    23:59:59
    00:00:01
    00:00:00
    23:59:58
    62, which check if the given
    Rectangle[length=1.2,width=3.4]
    Rectangle[length=1.0,width=1.0]
    Rectangle[length=5.6,width=7.8]
    length is: 5.6
    width is: 7.8
    area is: 43.68
    perimeter is: 26.80
    42 is outside the bounds of the container box. If so, it invokes the
    Rectangle[length=1.2,width=3.4]
    Rectangle[length=1.0,width=1.0]
    Rectangle[length=5.6,width=7.8]
    length is: 5.6
    width is: 7.8
    area is: 43.68
    perimeter is: 26.80
    42's
    Rectangle[length=1.2,width=3.4]
    Rectangle[length=1.0,width=1.0]
    Rectangle[length=5.6,width=7.8]
    length is: 5.6
    width is: 7.8
    area is: 43.68
    perimeter is: 26.80
    43 and/or
    Rectangle[length=1.2,width=3.4]
    Rectangle[length=1.0,width=1.0]
    Rectangle[length=5.6,width=7.8]
    length is: 5.6
    width is: 7.8
    area is: 43.68
    perimeter is: 26.80
    44 to change the movement direction of the ball, and returns
    InvoiceItem[id=A101,desc=Pen Red,qty=888,unitPrice=0.08]
    InvoiceItem[id=A101,desc=Pen Red,qty=999,unitPrice=0.99]
    id is: A101
    desc is: Pen Red
    qty is: 999
    unitPrice is: 0.99
    The total is: 989.01
    
    70.
    Employee[id=8,name=Peter Tan,salary=2500]
    Employee[id=8,name=Peter Tan,salary=999]
    id is: 8
    firstname is: Peter
    lastname is: Tan
    salary is: 999
    name is: Peter Tan
    annual salary is: 11988
    1098
    Employee[id=8,name=Peter Tan,salary=1098]
    9

Use the following statements to test your program:

Ex: The Ball and Player Classes

What kind of data is the colors of the cars around the gym in the scenario

The

Rectangle[length=1.2,width=3.4]
Rectangle[length=1.0,width=1.0]
Rectangle[length=5.6,width=7.8]
length is: 5.6
width is: 7.8
area is: 43.68
perimeter is: 26.80
42 class, which models the ball in a soccer game, is designed as shown in the class diagram. Write the codes for the
Rectangle[length=1.2,width=3.4]
Rectangle[length=1.0,width=1.0]
Rectangle[length=5.6,width=7.8]
length is: 5.6
width is: 7.8
area is: 43.68
perimeter is: 26.80
42 class and a test driver to test all the
Account[id=A101,name=Tan Ah Teck,balance=88]
Account[id=A102,name=Kumar,balance=0]
ID: A101 
Name: Tan Ah Teck
Balance: 88 
Account[id=A101,name=Tan Ah Teck,balance=188]
Account[id=A101,name=Tan Ah Teck,balance=138]
Amount exceeded balance
Account[id=A101,name=Tan Ah Teck,balance=138]
Account[id=A101,name=Tan Ah Teck,balance=38]
Account[id=A102,name=Kumar,balance=100]
7 methods.

What kind of data is the colors of the cars around the gym in the scenario

The

01:02:03
04:05:06
Hour: 4
Minute: 5
Second: 6
23:59:58
23:59:59
00:00:01
00:00:00
23:59:58
71 class, which models the players in a soccer game, is designed as shown in the class diagram. The Player interacts with the Ball (written earlier). Write the codes for the
01:02:03
04:05:06
Hour: 4
Minute: 5
Second: 6
23:59:58
23:59:59
00:00:01
00:00:00
23:59:58
71 class and a test driver to test all the
Account[id=A101,name=Tan Ah Teck,balance=88]
Account[id=A102,name=Kumar,balance=0]
ID: A101 
Name: Tan Ah Teck
Balance: 88 
Account[id=A101,name=Tan Ah Teck,balance=188]
Account[id=A101,name=Tan Ah Teck,balance=138]
Amount exceeded balance
Account[id=A101,name=Tan Ah Teck,balance=138]
Account[id=A101,name=Tan Ah Teck,balance=38]
Account[id=A102,name=Kumar,balance=100]
7 methods. Make your assumption for the
01:02:03
04:05:06
Hour: 4
Minute: 5
Second: 6
23:59:58
23:59:59
00:00:01
00:00:00
23:59:58
74.

Can you write a very simple soccer game with 2 teams of players and a ball, inside a soccer field?

Exercises on Inheritance

An Introduction to OOP Inheritance by Example - The Circle and Cylinder Classes

This exercise shall guide you through the important concepts in inheritance.

What kind of data is the colors of the cars around the gym in the scenario

In this exercise, a subclass called

01:02:03
04:05:06
Hour: 4
Minute: 5
Second: 6
23:59:58
23:59:59
00:00:01
00:00:00
23:59:58
75 is derived from the superclass
01/02/2014
09/12/2099
Month: 12
Day: 9
Year: 2099
03/04/2016
2 as shown in the class diagram (where an an arrow pointing up from the subclass to its superclass). Study how the subclass
01:02:03
04:05:06
Hour: 4
Minute: 5
Second: 6
23:59:58
23:59:59
00:00:01
00:00:00
23:59:58
75 invokes the superclass' constructors (via
01:02:03
04:05:06
Hour: 4
Minute: 5
Second: 6
23:59:58
23:59:59
00:00:01
00:00:00
23:59:58
78 and
01:02:03
04:05:06
Hour: 4
Minute: 5
Second: 6
23:59:58
23:59:59
00:00:01
00:00:00
23:59:58
79) and inherits the variables and methods from the superclass
01/02/2014
09/12/2099
Month: 12
Day: 9
Year: 2099
03/04/2016
2.

You can reuse the

01/02/2014
09/12/2099
Month: 12
Day: 9
Year: 2099
03/04/2016
2 class that you have created in the previous exercise. Make sure that you keep "
01:02:03
04:05:06
Hour: 4
Minute: 5
Second: 6
23:59:58
23:59:59
00:00:01
00:00:00
23:59:58
82" in the same directory.

Write a test program (says

01:02:03
04:05:06
Hour: 4
Minute: 5
Second: 6
23:59:58
23:59:59
00:00:01
00:00:00
23:59:58
83) to test the
01:02:03
04:05:06
Hour: 4
Minute: 5
Second: 6
23:59:58
23:59:59
00:00:01
00:00:00
23:59:58
75 class created, as follow:

Method Overriding and "Super": The subclass

01:02:03
04:05:06
Hour: 4
Minute: 5
Second: 6
23:59:58
23:59:59
00:00:01
00:00:00
23:59:58
75 inherits
Account[id=A101,name=Tan Ah Teck,balance=88]
Account[id=A102,name=Kumar,balance=0]
ID: A101 
Name: Tan Ah Teck
Balance: 88 
Account[id=A101,name=Tan Ah Teck,balance=188]
Account[id=A101,name=Tan Ah Teck,balance=138]
Amount exceeded balance
Account[id=A101,name=Tan Ah Teck,balance=138]
Account[id=A101,name=Tan Ah Teck,balance=38]
Account[id=A102,name=Kumar,balance=100]
9 method from its superclass Circle. Try overriding the
Account[id=A101,name=Tan Ah Teck,balance=88]
Account[id=A102,name=Kumar,balance=0]
ID: A101 
Name: Tan Ah Teck
Balance: 88 
Account[id=A101,name=Tan Ah Teck,balance=188]
Account[id=A101,name=Tan Ah Teck,balance=138]
Amount exceeded balance
Account[id=A101,name=Tan Ah Teck,balance=138]
Account[id=A101,name=Tan Ah Teck,balance=38]
Account[id=A102,name=Kumar,balance=100]
9 method in the subclass
01:02:03
04:05:06
Hour: 4
Minute: 5
Second: 6
23:59:58
23:59:59
00:00:01
00:00:00
23:59:58
75 to compute the surface area (=2π×radius×height + 2×base-area) of the cylinder instead of base area. That is, if
Account[id=A101,name=Tan Ah Teck,balance=88]
Account[id=A102,name=Kumar,balance=0]
ID: A101 
Name: Tan Ah Teck
Balance: 88 
Account[id=A101,name=Tan Ah Teck,balance=188]
Account[id=A101,name=Tan Ah Teck,balance=138]
Amount exceeded balance
Account[id=A101,name=Tan Ah Teck,balance=138]
Account[id=A101,name=Tan Ah Teck,balance=38]
Account[id=A102,name=Kumar,balance=100]
9 is called by a
01/02/2014
09/12/2099
Month: 12
Day: 9
Year: 2099
03/04/2016
2 instance, it returns the area. If
Account[id=A101,name=Tan Ah Teck,balance=88]
Account[id=A102,name=Kumar,balance=0]
ID: A101 
Name: Tan Ah Teck
Balance: 88 
Account[id=A101,name=Tan Ah Teck,balance=188]
Account[id=A101,name=Tan Ah Teck,balance=138]
Amount exceeded balance
Account[id=A101,name=Tan Ah Teck,balance=138]
Account[id=A101,name=Tan Ah Teck,balance=38]
Account[id=A102,name=Kumar,balance=100]
9 is called by a
01:02:03
04:05:06
Hour: 4
Minute: 5
Second: 6
23:59:58
23:59:59
00:00:01
00:00:00
23:59:58
75 instance, it returns the surface area of the cylinder.

If you override the

Account[id=A101,name=Tan Ah Teck,balance=88]
Account[id=A102,name=Kumar,balance=0]
ID: A101 
Name: Tan Ah Teck
Balance: 88 
Account[id=A101,name=Tan Ah Teck,balance=188]
Account[id=A101,name=Tan Ah Teck,balance=138]
Amount exceeded balance
Account[id=A101,name=Tan Ah Teck,balance=138]
Account[id=A101,name=Tan Ah Teck,balance=38]
Account[id=A102,name=Kumar,balance=100]
9 in the subclass
01:02:03
04:05:06
Hour: 4
Minute: 5
Second: 6
23:59:58
23:59:59
00:00:01
00:00:00
23:59:58
75, the
01:02:03
04:05:06
Hour: 4
Minute: 5
Second: 6
23:59:58
23:59:59
00:00:01
00:00:00
23:59:58
95 no longer works. This is because the
01:02:03
04:05:06
Hour: 4
Minute: 5
Second: 6
23:59:58
23:59:59
00:00:01
00:00:00
23:59:58
95 uses the overridden
Account[id=A101,name=Tan Ah Teck,balance=88]
Account[id=A102,name=Kumar,balance=0]
ID: A101 
Name: Tan Ah Teck
Balance: 88 
Account[id=A101,name=Tan Ah Teck,balance=188]
Account[id=A101,name=Tan Ah Teck,balance=138]
Amount exceeded balance
Account[id=A101,name=Tan Ah Teck,balance=138]
Account[id=A101,name=Tan Ah Teck,balance=38]
Account[id=A102,name=Kumar,balance=100]
9 method found in the same class. (Java runtime will search the superclass only if it cannot locate the method in this class). Fix the
01:02:03
04:05:06
Hour: 4
Minute: 5
Second: 6
23:59:58
23:59:59
00:00:01
00:00:00
23:59:58
95.

Hints: After overridding the

Account[id=A101,name=Tan Ah Teck,balance=88]
Account[id=A102,name=Kumar,balance=0]
ID: A101 
Name: Tan Ah Teck
Balance: 88 
Account[id=A101,name=Tan Ah Teck,balance=188]
Account[id=A101,name=Tan Ah Teck,balance=138]
Amount exceeded balance
Account[id=A101,name=Tan Ah Teck,balance=138]
Account[id=A101,name=Tan Ah Teck,balance=38]
Account[id=A102,name=Kumar,balance=100]
9 in subclass
01:02:03
04:05:06
Hour: 4
Minute: 5
Second: 6
23:59:58
23:59:59
00:00:01
00:00:00
23:59:58
75, you can choose to invoke the
Account[id=A101,name=Tan Ah Teck,balance=88]
Account[id=A102,name=Kumar,balance=0]
ID: A101 
Name: Tan Ah Teck
Balance: 88 
Account[id=A101,name=Tan Ah Teck,balance=188]
Account[id=A101,name=Tan Ah Teck,balance=138]
Amount exceeded balance
Account[id=A101,name=Tan Ah Teck,balance=138]
Account[id=A101,name=Tan Ah Teck,balance=38]
Account[id=A102,name=Kumar,balance=100]
9 of the superclass
01/02/2014
09/12/2099
Month: 12
Day: 9
Year: 2099
03/04/2016
2 by calling
Ball[(1.1,2.2),speed=(3.3,4.4)]
Ball[(80.0,35.0),speed=(4.0,6.0)]
x is: 80.0
y is: 35.0
radius is: 5
xDelta is: 4.0
yDelta is: 6.0
Ball[(84.0,41.0),speed=(4.0,6.0)]
Ball[(88.0,47.0),speed=(4.0,6.0)]
Ball[(92.0,41.0),speed=(4.0,-6.0)]
Ball[(96.0,35.0),speed=(4.0,-6.0)]
Ball[(92.0,29.0),speed=(-4.0,-6.0)]
Ball[(88.0,23.0),speed=(-4.0,-6.0)]
Ball[(84.0,17.0),speed=(-4.0,-6.0)]
Ball[(80.0,11.0),speed=(-4.0,-6.0)]
Ball[(76.0,5.0),speed=(-4.0,-6.0)]
Ball[(72.0,-1.0),speed=(-4.0,-6.0)]
Ball[(68.0,5.0),speed=(-4.0,6.0)]
Ball[(64.0,11.0),speed=(-4.0,6.0)]
Ball[(60.0,17.0),speed=(-4.0,6.0)]
Ball[(56.0,23.0),speed=(-4.0,6.0)]
Ball[(52.0,29.0),speed=(-4.0,6.0)]
03.

TRY:

Provide a

public Author (String name, String email, char gender) {......}
5 method to the
01:02:03
04:05:06
Hour: 4
Minute: 5
Second: 6
23:59:58
23:59:59
00:00:01
00:00:00
23:59:58
75 class, which overrides the
public Author (String name, String email, char gender) {......}
5 inherited from the superclass
01/02/2014
09/12/2099
Month: 12
Day: 9
Year: 2099
03/04/2016
2, e.g.,

Try out the

public Author (String name, String email, char gender) {......}
5 method in
01:02:03
04:05:06
Hour: 4
Minute: 5
Second: 6
23:59:58
23:59:59
00:00:01
00:00:00
23:59:58
83.

Note:

Ball[(1.1,2.2),speed=(3.3,4.4)]
Ball[(80.0,35.0),speed=(4.0,6.0)]
x is: 80.0
y is: 35.0
radius is: 5
xDelta is: 4.0
yDelta is: 6.0
Ball[(84.0,41.0),speed=(4.0,6.0)]
Ball[(88.0,47.0),speed=(4.0,6.0)]
Ball[(92.0,41.0),speed=(4.0,-6.0)]
Ball[(96.0,35.0),speed=(4.0,-6.0)]
Ball[(92.0,29.0),speed=(-4.0,-6.0)]
Ball[(88.0,23.0),speed=(-4.0,-6.0)]
Ball[(84.0,17.0),speed=(-4.0,-6.0)]
Ball[(80.0,11.0),speed=(-4.0,-6.0)]
Ball[(76.0,5.0),speed=(-4.0,-6.0)]
Ball[(72.0,-1.0),speed=(-4.0,-6.0)]
Ball[(68.0,5.0),speed=(-4.0,6.0)]
Ball[(64.0,11.0),speed=(-4.0,6.0)]
Ball[(60.0,17.0),speed=(-4.0,6.0)]
Ball[(56.0,23.0),speed=(-4.0,6.0)]
Ball[(52.0,29.0),speed=(-4.0,6.0)]
10 is known as annotation (introduced in JDK 1.5), which asks compiler to check whether there is such a method in the superclass to be overridden. This helps greatly if you misspell the name of the
public Author (String name, String email, char gender) {......}
5. If
Ball[(1.1,2.2),speed=(3.3,4.4)]
Ball[(80.0,35.0),speed=(4.0,6.0)]
x is: 80.0
y is: 35.0
radius is: 5
xDelta is: 4.0
yDelta is: 6.0
Ball[(84.0,41.0),speed=(4.0,6.0)]
Ball[(88.0,47.0),speed=(4.0,6.0)]
Ball[(92.0,41.0),speed=(4.0,-6.0)]
Ball[(96.0,35.0),speed=(4.0,-6.0)]
Ball[(92.0,29.0),speed=(-4.0,-6.0)]
Ball[(88.0,23.0),speed=(-4.0,-6.0)]
Ball[(84.0,17.0),speed=(-4.0,-6.0)]
Ball[(80.0,11.0),speed=(-4.0,-6.0)]
Ball[(76.0,5.0),speed=(-4.0,-6.0)]
Ball[(72.0,-1.0),speed=(-4.0,-6.0)]
Ball[(68.0,5.0),speed=(-4.0,6.0)]
Ball[(64.0,11.0),speed=(-4.0,6.0)]
Ball[(60.0,17.0),speed=(-4.0,6.0)]
Ball[(56.0,23.0),speed=(-4.0,6.0)]
Ball[(52.0,29.0),speed=(-4.0,6.0)]
10 is not used and
public Author (String name, String email, char gender) {......}
5 is misspelled as
Ball[(1.1,2.2),speed=(3.3,4.4)]
Ball[(80.0,35.0),speed=(4.0,6.0)]
x is: 80.0
y is: 35.0
radius is: 5
xDelta is: 4.0
yDelta is: 6.0
Ball[(84.0,41.0),speed=(4.0,6.0)]
Ball[(88.0,47.0),speed=(4.0,6.0)]
Ball[(92.0,41.0),speed=(4.0,-6.0)]
Ball[(96.0,35.0),speed=(4.0,-6.0)]
Ball[(92.0,29.0),speed=(-4.0,-6.0)]
Ball[(88.0,23.0),speed=(-4.0,-6.0)]
Ball[(84.0,17.0),speed=(-4.0,-6.0)]
Ball[(80.0,11.0),speed=(-4.0,-6.0)]
Ball[(76.0,5.0),speed=(-4.0,-6.0)]
Ball[(72.0,-1.0),speed=(-4.0,-6.0)]
Ball[(68.0,5.0),speed=(-4.0,6.0)]
Ball[(64.0,11.0),speed=(-4.0,6.0)]
Ball[(60.0,17.0),speed=(-4.0,6.0)]
Ball[(56.0,23.0),speed=(-4.0,6.0)]
Ball[(52.0,29.0),speed=(-4.0,6.0)]
14, it will be treated as a new method in the subclass, instead of overriding the superclass. If
Ball[(1.1,2.2),speed=(3.3,4.4)]
Ball[(80.0,35.0),speed=(4.0,6.0)]
x is: 80.0
y is: 35.0
radius is: 5
xDelta is: 4.0
yDelta is: 6.0
Ball[(84.0,41.0),speed=(4.0,6.0)]
Ball[(88.0,47.0),speed=(4.0,6.0)]
Ball[(92.0,41.0),speed=(4.0,-6.0)]
Ball[(96.0,35.0),speed=(4.0,-6.0)]
Ball[(92.0,29.0),speed=(-4.0,-6.0)]
Ball[(88.0,23.0),speed=(-4.0,-6.0)]
Ball[(84.0,17.0),speed=(-4.0,-6.0)]
Ball[(80.0,11.0),speed=(-4.0,-6.0)]
Ball[(76.0,5.0),speed=(-4.0,-6.0)]
Ball[(72.0,-1.0),speed=(-4.0,-6.0)]
Ball[(68.0,5.0),speed=(-4.0,6.0)]
Ball[(64.0,11.0),speed=(-4.0,6.0)]
Ball[(60.0,17.0),speed=(-4.0,6.0)]
Ball[(56.0,23.0),speed=(-4.0,6.0)]
Ball[(52.0,29.0),speed=(-4.0,6.0)]
10 is used, the compiler will signal an error.
Ball[(1.1,2.2),speed=(3.3,4.4)]
Ball[(80.0,35.0),speed=(4.0,6.0)]
x is: 80.0
y is: 35.0
radius is: 5
xDelta is: 4.0
yDelta is: 6.0
Ball[(84.0,41.0),speed=(4.0,6.0)]
Ball[(88.0,47.0),speed=(4.0,6.0)]
Ball[(92.0,41.0),speed=(4.0,-6.0)]
Ball[(96.0,35.0),speed=(4.0,-6.0)]
Ball[(92.0,29.0),speed=(-4.0,-6.0)]
Ball[(88.0,23.0),speed=(-4.0,-6.0)]
Ball[(84.0,17.0),speed=(-4.0,-6.0)]
Ball[(80.0,11.0),speed=(-4.0,-6.0)]
Ball[(76.0,5.0),speed=(-4.0,-6.0)]
Ball[(72.0,-1.0),speed=(-4.0,-6.0)]
Ball[(68.0,5.0),speed=(-4.0,6.0)]
Ball[(64.0,11.0),speed=(-4.0,6.0)]
Ball[(60.0,17.0),speed=(-4.0,6.0)]
Ball[(56.0,23.0),speed=(-4.0,6.0)]
Ball[(52.0,29.0),speed=(-4.0,6.0)]
10 annotation is optional, but certainly nice to have.

Ex: Superclass Person and its subclasses

Write the classes as shown in the following class diagram. Mark all the overridden methods with annotation

Ball[(1.1,2.2),speed=(3.3,4.4)]
Ball[(80.0,35.0),speed=(4.0,6.0)]
x is: 80.0
y is: 35.0
radius is: 5
xDelta is: 4.0
yDelta is: 6.0
Ball[(84.0,41.0),speed=(4.0,6.0)]
Ball[(88.0,47.0),speed=(4.0,6.0)]
Ball[(92.0,41.0),speed=(4.0,-6.0)]
Ball[(96.0,35.0),speed=(4.0,-6.0)]
Ball[(92.0,29.0),speed=(-4.0,-6.0)]
Ball[(88.0,23.0),speed=(-4.0,-6.0)]
Ball[(84.0,17.0),speed=(-4.0,-6.0)]
Ball[(80.0,11.0),speed=(-4.0,-6.0)]
Ball[(76.0,5.0),speed=(-4.0,-6.0)]
Ball[(72.0,-1.0),speed=(-4.0,-6.0)]
Ball[(68.0,5.0),speed=(-4.0,6.0)]
Ball[(64.0,11.0),speed=(-4.0,6.0)]
Ball[(60.0,17.0),speed=(-4.0,6.0)]
Ball[(56.0,23.0),speed=(-4.0,6.0)]
Ball[(52.0,29.0),speed=(-4.0,6.0)]
10.

What kind of data is the colors of the cars around the gym in the scenario

Ex: Point2D and Point3D

Write the classes as shown in the following class diagram. Mark all the overridden methods with annotation

Ball[(1.1,2.2),speed=(3.3,4.4)]
Ball[(80.0,35.0),speed=(4.0,6.0)]
x is: 80.0
y is: 35.0
radius is: 5
xDelta is: 4.0
yDelta is: 6.0
Ball[(84.0,41.0),speed=(4.0,6.0)]
Ball[(88.0,47.0),speed=(4.0,6.0)]
Ball[(92.0,41.0),speed=(4.0,-6.0)]
Ball[(96.0,35.0),speed=(4.0,-6.0)]
Ball[(92.0,29.0),speed=(-4.0,-6.0)]
Ball[(88.0,23.0),speed=(-4.0,-6.0)]
Ball[(84.0,17.0),speed=(-4.0,-6.0)]
Ball[(80.0,11.0),speed=(-4.0,-6.0)]
Ball[(76.0,5.0),speed=(-4.0,-6.0)]
Ball[(72.0,-1.0),speed=(-4.0,-6.0)]
Ball[(68.0,5.0),speed=(-4.0,6.0)]
Ball[(64.0,11.0),speed=(-4.0,6.0)]
Ball[(60.0,17.0),speed=(-4.0,6.0)]
Ball[(56.0,23.0),speed=(-4.0,6.0)]
Ball[(52.0,29.0),speed=(-4.0,6.0)]
10.

What kind of data is the colors of the cars around the gym in the scenario
Hints:
  1. You cannot assign floating-point literal say
    Ball[(1.1,2.2),speed=(3.3,4.4)]
    Ball[(80.0,35.0),speed=(4.0,6.0)]
    x is: 80.0
    y is: 35.0
    radius is: 5
    xDelta is: 4.0
    yDelta is: 6.0
    Ball[(84.0,41.0),speed=(4.0,6.0)]
    Ball[(88.0,47.0),speed=(4.0,6.0)]
    Ball[(92.0,41.0),speed=(4.0,-6.0)]
    Ball[(96.0,35.0),speed=(4.0,-6.0)]
    Ball[(92.0,29.0),speed=(-4.0,-6.0)]
    Ball[(88.0,23.0),speed=(-4.0,-6.0)]
    Ball[(84.0,17.0),speed=(-4.0,-6.0)]
    Ball[(80.0,11.0),speed=(-4.0,-6.0)]
    Ball[(76.0,5.0),speed=(-4.0,-6.0)]
    Ball[(72.0,-1.0),speed=(-4.0,-6.0)]
    Ball[(68.0,5.0),speed=(-4.0,6.0)]
    Ball[(64.0,11.0),speed=(-4.0,6.0)]
    Ball[(60.0,17.0),speed=(-4.0,6.0)]
    Ball[(56.0,23.0),speed=(-4.0,6.0)]
    Ball[(52.0,29.0),speed=(-4.0,6.0)]
    19 (which is a
    Account[id=A101,name=Tan Ah Teck,balance=88]
    Account[id=A102,name=Kumar,balance=0]
    ID: A101 
    Name: Tan Ah Teck
    Balance: 88 
    Account[id=A101,name=Tan Ah Teck,balance=188]
    Account[id=A101,name=Tan Ah Teck,balance=138]
    Amount exceeded balance
    Account[id=A101,name=Tan Ah Teck,balance=138]
    Account[id=A101,name=Tan Ah Teck,balance=38]
    Account[id=A102,name=Kumar,balance=100]
    2) to a
    Rectangle[length=1.2,width=3.4]
    Rectangle[length=1.0,width=1.0]
    Rectangle[length=5.6,width=7.8]
    length is: 5.6
    width is: 7.8
    area is: 43.68
    perimeter is: 26.80
    12 variable, you need to add a suffix f, e.g.
    Ball[(1.1,2.2),speed=(3.3,4.4)]
    Ball[(80.0,35.0),speed=(4.0,6.0)]
    x is: 80.0
    y is: 35.0
    radius is: 5
    xDelta is: 4.0
    yDelta is: 6.0
    Ball[(84.0,41.0),speed=(4.0,6.0)]
    Ball[(88.0,47.0),speed=(4.0,6.0)]
    Ball[(92.0,41.0),speed=(4.0,-6.0)]
    Ball[(96.0,35.0),speed=(4.0,-6.0)]
    Ball[(92.0,29.0),speed=(-4.0,-6.0)]
    Ball[(88.0,23.0),speed=(-4.0,-6.0)]
    Ball[(84.0,17.0),speed=(-4.0,-6.0)]
    Ball[(80.0,11.0),speed=(-4.0,-6.0)]
    Ball[(76.0,5.0),speed=(-4.0,-6.0)]
    Ball[(72.0,-1.0),speed=(-4.0,-6.0)]
    Ball[(68.0,5.0),speed=(-4.0,6.0)]
    Ball[(64.0,11.0),speed=(-4.0,6.0)]
    Ball[(60.0,17.0),speed=(-4.0,6.0)]
    Ball[(56.0,23.0),speed=(-4.0,6.0)]
    Ball[(52.0,29.0),speed=(-4.0,6.0)]
    22,
    Ball[(1.1,2.2),speed=(3.3,4.4)]
    Ball[(80.0,35.0),speed=(4.0,6.0)]
    x is: 80.0
    y is: 35.0
    radius is: 5
    xDelta is: 4.0
    yDelta is: 6.0
    Ball[(84.0,41.0),speed=(4.0,6.0)]
    Ball[(88.0,47.0),speed=(4.0,6.0)]
    Ball[(92.0,41.0),speed=(4.0,-6.0)]
    Ball[(96.0,35.0),speed=(4.0,-6.0)]
    Ball[(92.0,29.0),speed=(-4.0,-6.0)]
    Ball[(88.0,23.0),speed=(-4.0,-6.0)]
    Ball[(84.0,17.0),speed=(-4.0,-6.0)]
    Ball[(80.0,11.0),speed=(-4.0,-6.0)]
    Ball[(76.0,5.0),speed=(-4.0,-6.0)]
    Ball[(72.0,-1.0),speed=(-4.0,-6.0)]
    Ball[(68.0,5.0),speed=(-4.0,6.0)]
    Ball[(64.0,11.0),speed=(-4.0,6.0)]
    Ball[(60.0,17.0),speed=(-4.0,6.0)]
    Ball[(56.0,23.0),speed=(-4.0,6.0)]
    Ball[(52.0,29.0),speed=(-4.0,6.0)]
    23.
  2. The instance variables
    Employee[id=8,name=Peter Tan,salary=2500]
    Employee[id=8,name=Peter Tan,salary=999]
    id is: 8
    firstname is: Peter
    lastname is: Tan
    salary is: 999
    name is: Peter Tan
    annual salary is: 11988
    1098
    Employee[id=8,name=Peter Tan,salary=1098]
    55 and
    Employee[id=8,name=Peter Tan,salary=2500]
    Employee[id=8,name=Peter Tan,salary=999]
    id is: 8
    firstname is: Peter
    lastname is: Tan
    salary is: 999
    name is: Peter Tan
    annual salary is: 11988
    1098
    Employee[id=8,name=Peter Tan,salary=1098]
    57 are
    Account[id=A101,name=Tan Ah Teck,balance=88]
    Account[id=A102,name=Kumar,balance=0]
    ID: A101 
    Name: Tan Ah Teck
    Balance: 88 
    Account[id=A101,name=Tan Ah Teck,balance=188]
    Account[id=A101,name=Tan Ah Teck,balance=138]
    Amount exceeded balance
    Account[id=A101,name=Tan Ah Teck,balance=138]
    Account[id=A101,name=Tan Ah Teck,balance=38]
    Account[id=A102,name=Kumar,balance=100]
    0 in
    Ball[(1.1,2.2),speed=(3.3,4.4)]
    Ball[(80.0,35.0),speed=(4.0,6.0)]
    x is: 80.0
    y is: 35.0
    radius is: 5
    xDelta is: 4.0
    yDelta is: 6.0
    Ball[(84.0,41.0),speed=(4.0,6.0)]
    Ball[(88.0,47.0),speed=(4.0,6.0)]
    Ball[(92.0,41.0),speed=(4.0,-6.0)]
    Ball[(96.0,35.0),speed=(4.0,-6.0)]
    Ball[(92.0,29.0),speed=(-4.0,-6.0)]
    Ball[(88.0,23.0),speed=(-4.0,-6.0)]
    Ball[(84.0,17.0),speed=(-4.0,-6.0)]
    Ball[(80.0,11.0),speed=(-4.0,-6.0)]
    Ball[(76.0,5.0),speed=(-4.0,-6.0)]
    Ball[(72.0,-1.0),speed=(-4.0,-6.0)]
    Ball[(68.0,5.0),speed=(-4.0,6.0)]
    Ball[(64.0,11.0),speed=(-4.0,6.0)]
    Ball[(60.0,17.0),speed=(-4.0,6.0)]
    Ball[(56.0,23.0),speed=(-4.0,6.0)]
    Ball[(52.0,29.0),speed=(-4.0,6.0)]
    27 and cannot be accessed directly in the subclass
    Ball[(1.1,2.2),speed=(3.3,4.4)]
    Ball[(80.0,35.0),speed=(4.0,6.0)]
    x is: 80.0
    y is: 35.0
    radius is: 5
    xDelta is: 4.0
    yDelta is: 6.0
    Ball[(84.0,41.0),speed=(4.0,6.0)]
    Ball[(88.0,47.0),speed=(4.0,6.0)]
    Ball[(92.0,41.0),speed=(4.0,-6.0)]
    Ball[(96.0,35.0),speed=(4.0,-6.0)]
    Ball[(92.0,29.0),speed=(-4.0,-6.0)]
    Ball[(88.0,23.0),speed=(-4.0,-6.0)]
    Ball[(84.0,17.0),speed=(-4.0,-6.0)]
    Ball[(80.0,11.0),speed=(-4.0,-6.0)]
    Ball[(76.0,5.0),speed=(-4.0,-6.0)]
    Ball[(72.0,-1.0),speed=(-4.0,-6.0)]
    Ball[(68.0,5.0),speed=(-4.0,6.0)]
    Ball[(64.0,11.0),speed=(-4.0,6.0)]
    Ball[(60.0,17.0),speed=(-4.0,6.0)]
    Ball[(56.0,23.0),speed=(-4.0,6.0)]
    Ball[(52.0,29.0),speed=(-4.0,6.0)]
    28. You need to access via the
    Account[id=A101,name=Tan Ah Teck,balance=88]
    Account[id=A102,name=Kumar,balance=0]
    ID: A101 
    Name: Tan Ah Teck
    Balance: 88 
    Account[id=A101,name=Tan Ah Teck,balance=188]
    Account[id=A101,name=Tan Ah Teck,balance=138]
    Amount exceeded balance
    Account[id=A101,name=Tan Ah Teck,balance=138]
    Account[id=A101,name=Tan Ah Teck,balance=38]
    Account[id=A102,name=Kumar,balance=100]
    7 getters and setters. For example,
  3. The method
    Employee[id=8,name=Peter Tan,salary=2500]
    Employee[id=8,name=Peter Tan,salary=999]
    id is: 8
    firstname is: Peter
    lastname is: Tan
    salary is: 999
    name is: Peter Tan
    annual salary is: 11988
    1098
    Employee[id=8,name=Peter Tan,salary=1098]
    67 shall return a
    Rectangle[length=1.2,width=3.4]
    Rectangle[length=1.0,width=1.0]
    Rectangle[length=5.6,width=7.8]
    length is: 5.6
    width is: 7.8
    area is: 43.68
    perimeter is: 26.80
    12 array:

Ex: Point and MovablePoint

Write the classes as shown in the following class diagram. Mark all the overridden methods with annotation

Ball[(1.1,2.2),speed=(3.3,4.4)]
Ball[(80.0,35.0),speed=(4.0,6.0)]
x is: 80.0
y is: 35.0
radius is: 5
xDelta is: 4.0
yDelta is: 6.0
Ball[(84.0,41.0),speed=(4.0,6.0)]
Ball[(88.0,47.0),speed=(4.0,6.0)]
Ball[(92.0,41.0),speed=(4.0,-6.0)]
Ball[(96.0,35.0),speed=(4.0,-6.0)]
Ball[(92.0,29.0),speed=(-4.0,-6.0)]
Ball[(88.0,23.0),speed=(-4.0,-6.0)]
Ball[(84.0,17.0),speed=(-4.0,-6.0)]
Ball[(80.0,11.0),speed=(-4.0,-6.0)]
Ball[(76.0,5.0),speed=(-4.0,-6.0)]
Ball[(72.0,-1.0),speed=(-4.0,-6.0)]
Ball[(68.0,5.0),speed=(-4.0,6.0)]
Ball[(64.0,11.0),speed=(-4.0,6.0)]
Ball[(60.0,17.0),speed=(-4.0,6.0)]
Ball[(56.0,23.0),speed=(-4.0,6.0)]
Ball[(52.0,29.0),speed=(-4.0,6.0)]
32

What kind of data is the colors of the cars around the gym in the scenario
Hints
  1. You cannot assign floating-point literal say
    Ball[(1.1,2.2),speed=(3.3,4.4)]
    Ball[(80.0,35.0),speed=(4.0,6.0)]
    x is: 80.0
    y is: 35.0
    radius is: 5
    xDelta is: 4.0
    yDelta is: 6.0
    Ball[(84.0,41.0),speed=(4.0,6.0)]
    Ball[(88.0,47.0),speed=(4.0,6.0)]
    Ball[(92.0,41.0),speed=(4.0,-6.0)]
    Ball[(96.0,35.0),speed=(4.0,-6.0)]
    Ball[(92.0,29.0),speed=(-4.0,-6.0)]
    Ball[(88.0,23.0),speed=(-4.0,-6.0)]
    Ball[(84.0,17.0),speed=(-4.0,-6.0)]
    Ball[(80.0,11.0),speed=(-4.0,-6.0)]
    Ball[(76.0,5.0),speed=(-4.0,-6.0)]
    Ball[(72.0,-1.0),speed=(-4.0,-6.0)]
    Ball[(68.0,5.0),speed=(-4.0,6.0)]
    Ball[(64.0,11.0),speed=(-4.0,6.0)]
    Ball[(60.0,17.0),speed=(-4.0,6.0)]
    Ball[(56.0,23.0),speed=(-4.0,6.0)]
    Ball[(52.0,29.0),speed=(-4.0,6.0)]
    19 (which is a
    Account[id=A101,name=Tan Ah Teck,balance=88]
    Account[id=A102,name=Kumar,balance=0]
    ID: A101 
    Name: Tan Ah Teck
    Balance: 88 
    Account[id=A101,name=Tan Ah Teck,balance=188]
    Account[id=A101,name=Tan Ah Teck,balance=138]
    Amount exceeded balance
    Account[id=A101,name=Tan Ah Teck,balance=138]
    Account[id=A101,name=Tan Ah Teck,balance=38]
    Account[id=A102,name=Kumar,balance=100]
    2) to a
    Rectangle[length=1.2,width=3.4]
    Rectangle[length=1.0,width=1.0]
    Rectangle[length=5.6,width=7.8]
    length is: 5.6
    width is: 7.8
    area is: 43.68
    perimeter is: 26.80
    12 variable, you need to add a suffix f, e.g.
    Ball[(1.1,2.2),speed=(3.3,4.4)]
    Ball[(80.0,35.0),speed=(4.0,6.0)]
    x is: 80.0
    y is: 35.0
    radius is: 5
    xDelta is: 4.0
    yDelta is: 6.0
    Ball[(84.0,41.0),speed=(4.0,6.0)]
    Ball[(88.0,47.0),speed=(4.0,6.0)]
    Ball[(92.0,41.0),speed=(4.0,-6.0)]
    Ball[(96.0,35.0),speed=(4.0,-6.0)]
    Ball[(92.0,29.0),speed=(-4.0,-6.0)]
    Ball[(88.0,23.0),speed=(-4.0,-6.0)]
    Ball[(84.0,17.0),speed=(-4.0,-6.0)]
    Ball[(80.0,11.0),speed=(-4.0,-6.0)]
    Ball[(76.0,5.0),speed=(-4.0,-6.0)]
    Ball[(72.0,-1.0),speed=(-4.0,-6.0)]
    Ball[(68.0,5.0),speed=(-4.0,6.0)]
    Ball[(64.0,11.0),speed=(-4.0,6.0)]
    Ball[(60.0,17.0),speed=(-4.0,6.0)]
    Ball[(56.0,23.0),speed=(-4.0,6.0)]
    Ball[(52.0,29.0),speed=(-4.0,6.0)]
    22,
    Ball[(1.1,2.2),speed=(3.3,4.4)]
    Ball[(80.0,35.0),speed=(4.0,6.0)]
    x is: 80.0
    y is: 35.0
    radius is: 5
    xDelta is: 4.0
    yDelta is: 6.0
    Ball[(84.0,41.0),speed=(4.0,6.0)]
    Ball[(88.0,47.0),speed=(4.0,6.0)]
    Ball[(92.0,41.0),speed=(4.0,-6.0)]
    Ball[(96.0,35.0),speed=(4.0,-6.0)]
    Ball[(92.0,29.0),speed=(-4.0,-6.0)]
    Ball[(88.0,23.0),speed=(-4.0,-6.0)]
    Ball[(84.0,17.0),speed=(-4.0,-6.0)]
    Ball[(80.0,11.0),speed=(-4.0,-6.0)]
    Ball[(76.0,5.0),speed=(-4.0,-6.0)]
    Ball[(72.0,-1.0),speed=(-4.0,-6.0)]
    Ball[(68.0,5.0),speed=(-4.0,6.0)]
    Ball[(64.0,11.0),speed=(-4.0,6.0)]
    Ball[(60.0,17.0),speed=(-4.0,6.0)]
    Ball[(56.0,23.0),speed=(-4.0,6.0)]
    Ball[(52.0,29.0),speed=(-4.0,6.0)]
    23.
  2. The instance variables
    Employee[id=8,name=Peter Tan,salary=2500]
    Employee[id=8,name=Peter Tan,salary=999]
    id is: 8
    firstname is: Peter
    lastname is: Tan
    salary is: 999
    name is: Peter Tan
    annual salary is: 11988
    1098
    Employee[id=8,name=Peter Tan,salary=1098]
    55 and
    Employee[id=8,name=Peter Tan,salary=2500]
    Employee[id=8,name=Peter Tan,salary=999]
    id is: 8
    firstname is: Peter
    lastname is: Tan
    salary is: 999
    name is: Peter Tan
    annual salary is: 11988
    1098
    Employee[id=8,name=Peter Tan,salary=1098]
    57 are
    Account[id=A101,name=Tan Ah Teck,balance=88]
    Account[id=A102,name=Kumar,balance=0]
    ID: A101 
    Name: Tan Ah Teck
    Balance: 88 
    Account[id=A101,name=Tan Ah Teck,balance=188]
    Account[id=A101,name=Tan Ah Teck,balance=138]
    Amount exceeded balance
    Account[id=A101,name=Tan Ah Teck,balance=138]
    Account[id=A101,name=Tan Ah Teck,balance=38]
    Account[id=A102,name=Kumar,balance=100]
    0 in
    Ball[(1.1,2.2),speed=(3.3,4.4)]
    Ball[(80.0,35.0),speed=(4.0,6.0)]
    x is: 80.0
    y is: 35.0
    radius is: 5
    xDelta is: 4.0
    yDelta is: 6.0
    Ball[(84.0,41.0),speed=(4.0,6.0)]
    Ball[(88.0,47.0),speed=(4.0,6.0)]
    Ball[(92.0,41.0),speed=(4.0,-6.0)]
    Ball[(96.0,35.0),speed=(4.0,-6.0)]
    Ball[(92.0,29.0),speed=(-4.0,-6.0)]
    Ball[(88.0,23.0),speed=(-4.0,-6.0)]
    Ball[(84.0,17.0),speed=(-4.0,-6.0)]
    Ball[(80.0,11.0),speed=(-4.0,-6.0)]
    Ball[(76.0,5.0),speed=(-4.0,-6.0)]
    Ball[(72.0,-1.0),speed=(-4.0,-6.0)]
    Ball[(68.0,5.0),speed=(-4.0,6.0)]
    Ball[(64.0,11.0),speed=(-4.0,6.0)]
    Ball[(60.0,17.0),speed=(-4.0,6.0)]
    Ball[(56.0,23.0),speed=(-4.0,6.0)]
    Ball[(52.0,29.0),speed=(-4.0,6.0)]
    41 and cannot be accessed directly in the subclass
    Ball[(1.1,2.2),speed=(3.3,4.4)]
    Ball[(80.0,35.0),speed=(4.0,6.0)]
    x is: 80.0
    y is: 35.0
    radius is: 5
    xDelta is: 4.0
    yDelta is: 6.0
    Ball[(84.0,41.0),speed=(4.0,6.0)]
    Ball[(88.0,47.0),speed=(4.0,6.0)]
    Ball[(92.0,41.0),speed=(4.0,-6.0)]
    Ball[(96.0,35.0),speed=(4.0,-6.0)]
    Ball[(92.0,29.0),speed=(-4.0,-6.0)]
    Ball[(88.0,23.0),speed=(-4.0,-6.0)]
    Ball[(84.0,17.0),speed=(-4.0,-6.0)]
    Ball[(80.0,11.0),speed=(-4.0,-6.0)]
    Ball[(76.0,5.0),speed=(-4.0,-6.0)]
    Ball[(72.0,-1.0),speed=(-4.0,-6.0)]
    Ball[(68.0,5.0),speed=(-4.0,6.0)]
    Ball[(64.0,11.0),speed=(-4.0,6.0)]
    Ball[(60.0,17.0),speed=(-4.0,6.0)]
    Ball[(56.0,23.0),speed=(-4.0,6.0)]
    Ball[(52.0,29.0),speed=(-4.0,6.0)]
    42. You need to access via the
    Account[id=A101,name=Tan Ah Teck,balance=88]
    Account[id=A102,name=Kumar,balance=0]
    ID: A101 
    Name: Tan Ah Teck
    Balance: 88 
    Account[id=A101,name=Tan Ah Teck,balance=188]
    Account[id=A101,name=Tan Ah Teck,balance=138]
    Amount exceeded balance
    Account[id=A101,name=Tan Ah Teck,balance=138]
    Account[id=A101,name=Tan Ah Teck,balance=38]
    Account[id=A102,name=Kumar,balance=100]
    7 getters and setters. For example, you cannot write
    Ball[(1.1,2.2),speed=(3.3,4.4)]
    Ball[(80.0,35.0),speed=(4.0,6.0)]
    x is: 80.0
    y is: 35.0
    radius is: 5
    xDelta is: 4.0
    yDelta is: 6.0
    Ball[(84.0,41.0),speed=(4.0,6.0)]
    Ball[(88.0,47.0),speed=(4.0,6.0)]
    Ball[(92.0,41.0),speed=(4.0,-6.0)]
    Ball[(96.0,35.0),speed=(4.0,-6.0)]
    Ball[(92.0,29.0),speed=(-4.0,-6.0)]
    Ball[(88.0,23.0),speed=(-4.0,-6.0)]
    Ball[(84.0,17.0),speed=(-4.0,-6.0)]
    Ball[(80.0,11.0),speed=(-4.0,-6.0)]
    Ball[(76.0,5.0),speed=(-4.0,-6.0)]
    Ball[(72.0,-1.0),speed=(-4.0,-6.0)]
    Ball[(68.0,5.0),speed=(-4.0,6.0)]
    Ball[(64.0,11.0),speed=(-4.0,6.0)]
    Ball[(60.0,17.0),speed=(-4.0,6.0)]
    Ball[(56.0,23.0),speed=(-4.0,6.0)]
    Ball[(52.0,29.0),speed=(-4.0,6.0)]
    44, you need to write
    Ball[(1.1,2.2),speed=(3.3,4.4)]
    Ball[(80.0,35.0),speed=(4.0,6.0)]
    x is: 80.0
    y is: 35.0
    radius is: 5
    xDelta is: 4.0
    yDelta is: 6.0
    Ball[(84.0,41.0),speed=(4.0,6.0)]
    Ball[(88.0,47.0),speed=(4.0,6.0)]
    Ball[(92.0,41.0),speed=(4.0,-6.0)]
    Ball[(96.0,35.0),speed=(4.0,-6.0)]
    Ball[(92.0,29.0),speed=(-4.0,-6.0)]
    Ball[(88.0,23.0),speed=(-4.0,-6.0)]
    Ball[(84.0,17.0),speed=(-4.0,-6.0)]
    Ball[(80.0,11.0),speed=(-4.0,-6.0)]
    Ball[(76.0,5.0),speed=(-4.0,-6.0)]
    Ball[(72.0,-1.0),speed=(-4.0,-6.0)]
    Ball[(68.0,5.0),speed=(-4.0,6.0)]
    Ball[(64.0,11.0),speed=(-4.0,6.0)]
    Ball[(60.0,17.0),speed=(-4.0,6.0)]
    Ball[(56.0,23.0),speed=(-4.0,6.0)]
    Ball[(52.0,29.0),speed=(-4.0,6.0)]
    45.

Ex: Superclass Shape and its subclasses Circle, Rectangle and Square

What kind of data is the colors of the cars around the gym in the scenario

Write a superclass called

Ball[(1.1,2.2),speed=(3.3,4.4)]
Ball[(80.0,35.0),speed=(4.0,6.0)]
x is: 80.0
y is: 35.0
radius is: 5
xDelta is: 4.0
yDelta is: 6.0
Ball[(84.0,41.0),speed=(4.0,6.0)]
Ball[(88.0,47.0),speed=(4.0,6.0)]
Ball[(92.0,41.0),speed=(4.0,-6.0)]
Ball[(96.0,35.0),speed=(4.0,-6.0)]
Ball[(92.0,29.0),speed=(-4.0,-6.0)]
Ball[(88.0,23.0),speed=(-4.0,-6.0)]
Ball[(84.0,17.0),speed=(-4.0,-6.0)]
Ball[(80.0,11.0),speed=(-4.0,-6.0)]
Ball[(76.0,5.0),speed=(-4.0,-6.0)]
Ball[(72.0,-1.0),speed=(-4.0,-6.0)]
Ball[(68.0,5.0),speed=(-4.0,6.0)]
Ball[(64.0,11.0),speed=(-4.0,6.0)]
Ball[(60.0,17.0),speed=(-4.0,6.0)]
Ball[(56.0,23.0),speed=(-4.0,6.0)]
Ball[(52.0,29.0),speed=(-4.0,6.0)]
46 (as shown in the class diagram), which contains:

  • Two instance variables
    Account[id=A101,name=Tan Ah Teck,balance=88]
    Account[id=A102,name=Kumar,balance=0]
    ID: A101 
    Name: Tan Ah Teck
    Balance: 88 
    Account[id=A101,name=Tan Ah Teck,balance=188]
    Account[id=A101,name=Tan Ah Teck,balance=138]
    Amount exceeded balance
    Account[id=A101,name=Tan Ah Teck,balance=138]
    Account[id=A101,name=Tan Ah Teck,balance=38]
    Account[id=A102,name=Kumar,balance=100]
    3 (
    Account[id=A101,name=Tan Ah Teck,balance=88]
    Account[id=A102,name=Kumar,balance=0]
    ID: A101 
    Name: Tan Ah Teck
    Balance: 88 
    Account[id=A101,name=Tan Ah Teck,balance=188]
    Account[id=A101,name=Tan Ah Teck,balance=138]
    Amount exceeded balance
    Account[id=A101,name=Tan Ah Teck,balance=138]
    Account[id=A101,name=Tan Ah Teck,balance=38]
    Account[id=A102,name=Kumar,balance=100]
    4) and
    Ball[(1.1,2.2),speed=(3.3,4.4)]
    Ball[(80.0,35.0),speed=(4.0,6.0)]
    x is: 80.0
    y is: 35.0
    radius is: 5
    xDelta is: 4.0
    yDelta is: 6.0
    Ball[(84.0,41.0),speed=(4.0,6.0)]
    Ball[(88.0,47.0),speed=(4.0,6.0)]
    Ball[(92.0,41.0),speed=(4.0,-6.0)]
    Ball[(96.0,35.0),speed=(4.0,-6.0)]
    Ball[(92.0,29.0),speed=(-4.0,-6.0)]
    Ball[(88.0,23.0),speed=(-4.0,-6.0)]
    Ball[(84.0,17.0),speed=(-4.0,-6.0)]
    Ball[(80.0,11.0),speed=(-4.0,-6.0)]
    Ball[(76.0,5.0),speed=(-4.0,-6.0)]
    Ball[(72.0,-1.0),speed=(-4.0,-6.0)]
    Ball[(68.0,5.0),speed=(-4.0,6.0)]
    Ball[(64.0,11.0),speed=(-4.0,6.0)]
    Ball[(60.0,17.0),speed=(-4.0,6.0)]
    Ball[(56.0,23.0),speed=(-4.0,6.0)]
    Ball[(52.0,29.0),speed=(-4.0,6.0)]
    49 (
    01:02:03
    04:05:06
    Hour: 4
    Minute: 5
    Second: 6
    23:59:58
    23:59:59
    00:00:01
    00:00:00
    23:59:58
    61).
  • Two constructors: a no-arg (no-argument) constructor that initializes the
    Account[id=A101,name=Tan Ah Teck,balance=88]
    Account[id=A102,name=Kumar,balance=0]
    ID: A101 
    Name: Tan Ah Teck
    Balance: 88 
    Account[id=A101,name=Tan Ah Teck,balance=188]
    Account[id=A101,name=Tan Ah Teck,balance=138]
    Amount exceeded balance
    Account[id=A101,name=Tan Ah Teck,balance=138]
    Account[id=A101,name=Tan Ah Teck,balance=38]
    Account[id=A102,name=Kumar,balance=100]
    3 to "green" and
    Ball[(1.1,2.2),speed=(3.3,4.4)]
    Ball[(80.0,35.0),speed=(4.0,6.0)]
    x is: 80.0
    y is: 35.0
    radius is: 5
    xDelta is: 4.0
    yDelta is: 6.0
    Ball[(84.0,41.0),speed=(4.0,6.0)]
    Ball[(88.0,47.0),speed=(4.0,6.0)]
    Ball[(92.0,41.0),speed=(4.0,-6.0)]
    Ball[(96.0,35.0),speed=(4.0,-6.0)]
    Ball[(92.0,29.0),speed=(-4.0,-6.0)]
    Ball[(88.0,23.0),speed=(-4.0,-6.0)]
    Ball[(84.0,17.0),speed=(-4.0,-6.0)]
    Ball[(80.0,11.0),speed=(-4.0,-6.0)]
    Ball[(76.0,5.0),speed=(-4.0,-6.0)]
    Ball[(72.0,-1.0),speed=(-4.0,-6.0)]
    Ball[(68.0,5.0),speed=(-4.0,6.0)]
    Ball[(64.0,11.0),speed=(-4.0,6.0)]
    Ball[(60.0,17.0),speed=(-4.0,6.0)]
    Ball[(56.0,23.0),speed=(-4.0,6.0)]
    Ball[(52.0,29.0),speed=(-4.0,6.0)]
    49 to
    InvoiceItem[id=A101,desc=Pen Red,qty=888,unitPrice=0.08]
    InvoiceItem[id=A101,desc=Pen Red,qty=999,unitPrice=0.99]
    id is: A101
    desc is: Pen Red
    qty is: 999
    unitPrice is: 0.99
    The total is: 989.01
    
    70, and a constructor that initializes the
    Account[id=A101,name=Tan Ah Teck,balance=88]
    Account[id=A102,name=Kumar,balance=0]
    ID: A101 
    Name: Tan Ah Teck
    Balance: 88 
    Account[id=A101,name=Tan Ah Teck,balance=188]
    Account[id=A101,name=Tan Ah Teck,balance=138]
    Amount exceeded balance
    Account[id=A101,name=Tan Ah Teck,balance=138]
    Account[id=A101,name=Tan Ah Teck,balance=38]
    Account[id=A102,name=Kumar,balance=100]
    3 and
    Ball[(1.1,2.2),speed=(3.3,4.4)]
    Ball[(80.0,35.0),speed=(4.0,6.0)]
    x is: 80.0
    y is: 35.0
    radius is: 5
    xDelta is: 4.0
    yDelta is: 6.0
    Ball[(84.0,41.0),speed=(4.0,6.0)]
    Ball[(88.0,47.0),speed=(4.0,6.0)]
    Ball[(92.0,41.0),speed=(4.0,-6.0)]
    Ball[(96.0,35.0),speed=(4.0,-6.0)]
    Ball[(92.0,29.0),speed=(-4.0,-6.0)]
    Ball[(88.0,23.0),speed=(-4.0,-6.0)]
    Ball[(84.0,17.0),speed=(-4.0,-6.0)]
    Ball[(80.0,11.0),speed=(-4.0,-6.0)]
    Ball[(76.0,5.0),speed=(-4.0,-6.0)]
    Ball[(72.0,-1.0),speed=(-4.0,-6.0)]
    Ball[(68.0,5.0),speed=(-4.0,6.0)]
    Ball[(64.0,11.0),speed=(-4.0,6.0)]
    Ball[(60.0,17.0),speed=(-4.0,6.0)]
    Ball[(56.0,23.0),speed=(-4.0,6.0)]
    Ball[(52.0,29.0),speed=(-4.0,6.0)]
    49 to the given values.
  • Getter and setter for all the instance variables. By convention, the getter for a
    01:02:03
    04:05:06
    Hour: 4
    Minute: 5
    Second: 6
    23:59:58
    23:59:59
    00:00:01
    00:00:00
    23:59:58
    61 variable
    Ball[(1.1,2.2),speed=(3.3,4.4)]
    Ball[(80.0,35.0),speed=(4.0,6.0)]
    x is: 80.0
    y is: 35.0
    radius is: 5
    xDelta is: 4.0
    yDelta is: 6.0
    Ball[(84.0,41.0),speed=(4.0,6.0)]
    Ball[(88.0,47.0),speed=(4.0,6.0)]
    Ball[(92.0,41.0),speed=(4.0,-6.0)]
    Ball[(96.0,35.0),speed=(4.0,-6.0)]
    Ball[(92.0,29.0),speed=(-4.0,-6.0)]
    Ball[(88.0,23.0),speed=(-4.0,-6.0)]
    Ball[(84.0,17.0),speed=(-4.0,-6.0)]
    Ball[(80.0,11.0),speed=(-4.0,-6.0)]
    Ball[(76.0,5.0),speed=(-4.0,-6.0)]
    Ball[(72.0,-1.0),speed=(-4.0,-6.0)]
    Ball[(68.0,5.0),speed=(-4.0,6.0)]
    Ball[(64.0,11.0),speed=(-4.0,6.0)]
    Ball[(60.0,17.0),speed=(-4.0,6.0)]
    Ball[(56.0,23.0),speed=(-4.0,6.0)]
    Ball[(52.0,29.0),speed=(-4.0,6.0)]
    57 is called
    Ball[(1.1,2.2),speed=(3.3,4.4)]
    Ball[(80.0,35.0),speed=(4.0,6.0)]
    x is: 80.0
    y is: 35.0
    radius is: 5
    xDelta is: 4.0
    yDelta is: 6.0
    Ball[(84.0,41.0),speed=(4.0,6.0)]
    Ball[(88.0,47.0),speed=(4.0,6.0)]
    Ball[(92.0,41.0),speed=(4.0,-6.0)]
    Ball[(96.0,35.0),speed=(4.0,-6.0)]
    Ball[(92.0,29.0),speed=(-4.0,-6.0)]
    Ball[(88.0,23.0),speed=(-4.0,-6.0)]
    Ball[(84.0,17.0),speed=(-4.0,-6.0)]
    Ball[(80.0,11.0),speed=(-4.0,-6.0)]
    Ball[(76.0,5.0),speed=(-4.0,-6.0)]
    Ball[(72.0,-1.0),speed=(-4.0,-6.0)]
    Ball[(68.0,5.0),speed=(-4.0,6.0)]
    Ball[(64.0,11.0),speed=(-4.0,6.0)]
    Ball[(60.0,17.0),speed=(-4.0,6.0)]
    Ball[(56.0,23.0),speed=(-4.0,6.0)]
    Ball[(52.0,29.0),speed=(-4.0,6.0)]
    58 (instead of
    Ball[(1.1,2.2),speed=(3.3,4.4)]
    Ball[(80.0,35.0),speed=(4.0,6.0)]
    x is: 80.0
    y is: 35.0
    radius is: 5
    xDelta is: 4.0
    yDelta is: 6.0
    Ball[(84.0,41.0),speed=(4.0,6.0)]
    Ball[(88.0,47.0),speed=(4.0,6.0)]
    Ball[(92.0,41.0),speed=(4.0,-6.0)]
    Ball[(96.0,35.0),speed=(4.0,-6.0)]
    Ball[(92.0,29.0),speed=(-4.0,-6.0)]
    Ball[(88.0,23.0),speed=(-4.0,-6.0)]
    Ball[(84.0,17.0),speed=(-4.0,-6.0)]
    Ball[(80.0,11.0),speed=(-4.0,-6.0)]
    Ball[(76.0,5.0),speed=(-4.0,-6.0)]
    Ball[(72.0,-1.0),speed=(-4.0,-6.0)]
    Ball[(68.0,5.0),speed=(-4.0,6.0)]
    Ball[(64.0,11.0),speed=(-4.0,6.0)]
    Ball[(60.0,17.0),speed=(-4.0,6.0)]
    Ball[(56.0,23.0),speed=(-4.0,6.0)]
    Ball[(52.0,29.0),speed=(-4.0,6.0)]
    59 for all the other types).
  • A
    public Author (String name, String email, char gender) {......}
    5 method that returns "
    Ball[(1.1,2.2),speed=(3.3,4.4)]
    Ball[(80.0,35.0),speed=(4.0,6.0)]
    x is: 80.0
    y is: 35.0
    radius is: 5
    xDelta is: 4.0
    yDelta is: 6.0
    Ball[(84.0,41.0),speed=(4.0,6.0)]
    Ball[(88.0,47.0),speed=(4.0,6.0)]
    Ball[(92.0,41.0),speed=(4.0,-6.0)]
    Ball[(96.0,35.0),speed=(4.0,-6.0)]
    Ball[(92.0,29.0),speed=(-4.0,-6.0)]
    Ball[(88.0,23.0),speed=(-4.0,-6.0)]
    Ball[(84.0,17.0),speed=(-4.0,-6.0)]
    Ball[(80.0,11.0),speed=(-4.0,-6.0)]
    Ball[(76.0,5.0),speed=(-4.0,-6.0)]
    Ball[(72.0,-1.0),speed=(-4.0,-6.0)]
    Ball[(68.0,5.0),speed=(-4.0,6.0)]
    Ball[(64.0,11.0),speed=(-4.0,6.0)]
    Ball[(60.0,17.0),speed=(-4.0,6.0)]
    Ball[(56.0,23.0),speed=(-4.0,6.0)]
    Ball[(52.0,29.0),speed=(-4.0,6.0)]
    61".

Write a test program to test all the methods defined in

Ball[(1.1,2.2),speed=(3.3,4.4)]
Ball[(80.0,35.0),speed=(4.0,6.0)]
x is: 80.0
y is: 35.0
radius is: 5
xDelta is: 4.0
yDelta is: 6.0
Ball[(84.0,41.0),speed=(4.0,6.0)]
Ball[(88.0,47.0),speed=(4.0,6.0)]
Ball[(92.0,41.0),speed=(4.0,-6.0)]
Ball[(96.0,35.0),speed=(4.0,-6.0)]
Ball[(92.0,29.0),speed=(-4.0,-6.0)]
Ball[(88.0,23.0),speed=(-4.0,-6.0)]
Ball[(84.0,17.0),speed=(-4.0,-6.0)]
Ball[(80.0,11.0),speed=(-4.0,-6.0)]
Ball[(76.0,5.0),speed=(-4.0,-6.0)]
Ball[(72.0,-1.0),speed=(-4.0,-6.0)]
Ball[(68.0,5.0),speed=(-4.0,6.0)]
Ball[(64.0,11.0),speed=(-4.0,6.0)]
Ball[(60.0,17.0),speed=(-4.0,6.0)]
Ball[(56.0,23.0),speed=(-4.0,6.0)]
Ball[(52.0,29.0),speed=(-4.0,6.0)]
46.

Write two subclasses of

Ball[(1.1,2.2),speed=(3.3,4.4)]
Ball[(80.0,35.0),speed=(4.0,6.0)]
x is: 80.0
y is: 35.0
radius is: 5
xDelta is: 4.0
yDelta is: 6.0
Ball[(84.0,41.0),speed=(4.0,6.0)]
Ball[(88.0,47.0),speed=(4.0,6.0)]
Ball[(92.0,41.0),speed=(4.0,-6.0)]
Ball[(96.0,35.0),speed=(4.0,-6.0)]
Ball[(92.0,29.0),speed=(-4.0,-6.0)]
Ball[(88.0,23.0),speed=(-4.0,-6.0)]
Ball[(84.0,17.0),speed=(-4.0,-6.0)]
Ball[(80.0,11.0),speed=(-4.0,-6.0)]
Ball[(76.0,5.0),speed=(-4.0,-6.0)]
Ball[(72.0,-1.0),speed=(-4.0,-6.0)]
Ball[(68.0,5.0),speed=(-4.0,6.0)]
Ball[(64.0,11.0),speed=(-4.0,6.0)]
Ball[(60.0,17.0),speed=(-4.0,6.0)]
Ball[(56.0,23.0),speed=(-4.0,6.0)]
Ball[(52.0,29.0),speed=(-4.0,6.0)]
46 called
01/02/2014
09/12/2099
Month: 12
Day: 9
Year: 2099
03/04/2016
2 and
Rectangle[length=1.2,width=3.4]
Rectangle[length=1.0,width=1.0]
Rectangle[length=5.6,width=7.8]
length is: 5.6
width is: 7.8
area is: 43.68
perimeter is: 26.80
11, as shown in the class diagram.

The

01/02/2014
09/12/2099
Month: 12
Day: 9
Year: 2099
03/04/2016
2 class contains:

  • An instance variable
    Account[id=A101,name=Tan Ah Teck,balance=88]
    Account[id=A102,name=Kumar,balance=0]
    ID: A101 
    Name: Tan Ah Teck
    Balance: 88 
    Account[id=A101,name=Tan Ah Teck,balance=188]
    Account[id=A101,name=Tan Ah Teck,balance=138]
    Amount exceeded balance
    Account[id=A101,name=Tan Ah Teck,balance=138]
    Account[id=A101,name=Tan Ah Teck,balance=38]
    Account[id=A102,name=Kumar,balance=100]
    1 (
    Account[id=A101,name=Tan Ah Teck,balance=88]
    Account[id=A102,name=Kumar,balance=0]
    ID: A101 
    Name: Tan Ah Teck
    Balance: 88 
    Account[id=A101,name=Tan Ah Teck,balance=188]
    Account[id=A101,name=Tan Ah Teck,balance=138]
    Amount exceeded balance
    Account[id=A101,name=Tan Ah Teck,balance=138]
    Account[id=A101,name=Tan Ah Teck,balance=38]
    Account[id=A102,name=Kumar,balance=100]
    2).
  • Three constructors as shown. The no-arg constructor initializes the radius to
    Account[id=A101,name=Tan Ah Teck,balance=88]
    Account[id=A102,name=Kumar,balance=0]
    ID: A101 
    Name: Tan Ah Teck
    Balance: 88 
    Account[id=A101,name=Tan Ah Teck,balance=188]
    Account[id=A101,name=Tan Ah Teck,balance=138]
    Amount exceeded balance
    Account[id=A101,name=Tan Ah Teck,balance=138]
    Account[id=A101,name=Tan Ah Teck,balance=38]
    Account[id=A102,name=Kumar,balance=100]
    5.
  • Getter and setter for the instance variable
    Account[id=A101,name=Tan Ah Teck,balance=88]
    Account[id=A102,name=Kumar,balance=0]
    ID: A101 
    Name: Tan Ah Teck
    Balance: 88 
    Account[id=A101,name=Tan Ah Teck,balance=188]
    Account[id=A101,name=Tan Ah Teck,balance=138]
    Amount exceeded balance
    Account[id=A101,name=Tan Ah Teck,balance=138]
    Account[id=A101,name=Tan Ah Teck,balance=38]
    Account[id=A102,name=Kumar,balance=100]
    1.
  • Methods
    Account[id=A101,name=Tan Ah Teck,balance=88]
    Account[id=A102,name=Kumar,balance=0]
    ID: A101 
    Name: Tan Ah Teck
    Balance: 88 
    Account[id=A101,name=Tan Ah Teck,balance=188]
    Account[id=A101,name=Tan Ah Teck,balance=138]
    Amount exceeded balance
    Account[id=A101,name=Tan Ah Teck,balance=138]
    Account[id=A101,name=Tan Ah Teck,balance=38]
    Account[id=A102,name=Kumar,balance=100]
    9 and
    InvoiceItem[id=A101,desc=Pen Red,qty=888,unitPrice=0.08]
    InvoiceItem[id=A101,desc=Pen Red,qty=999,unitPrice=0.99]
    id is: A101
    desc is: Pen Red
    qty is: 999
    unitPrice is: 0.99
    The total is: 989.01
    
    42.
  • Override the
    public Author (String name, String email, char gender) {......}
    5 method inherited, to return "
    Ball[(1.1,2.2),speed=(3.3,4.4)]
    Ball[(80.0,35.0),speed=(4.0,6.0)]
    x is: 80.0
    y is: 35.0
    radius is: 5
    xDelta is: 4.0
    yDelta is: 6.0
    Ball[(84.0,41.0),speed=(4.0,6.0)]
    Ball[(88.0,47.0),speed=(4.0,6.0)]
    Ball[(92.0,41.0),speed=(4.0,-6.0)]
    Ball[(96.0,35.0),speed=(4.0,-6.0)]
    Ball[(92.0,29.0),speed=(-4.0,-6.0)]
    Ball[(88.0,23.0),speed=(-4.0,-6.0)]
    Ball[(84.0,17.0),speed=(-4.0,-6.0)]
    Ball[(80.0,11.0),speed=(-4.0,-6.0)]
    Ball[(76.0,5.0),speed=(-4.0,-6.0)]
    Ball[(72.0,-1.0),speed=(-4.0,-6.0)]
    Ball[(68.0,5.0),speed=(-4.0,6.0)]
    Ball[(64.0,11.0),speed=(-4.0,6.0)]
    Ball[(60.0,17.0),speed=(-4.0,6.0)]
    Ball[(56.0,23.0),speed=(-4.0,6.0)]
    Ball[(52.0,29.0),speed=(-4.0,6.0)]
    74", where
    Ball[(1.1,2.2),speed=(3.3,4.4)]
    Ball[(80.0,35.0),speed=(4.0,6.0)]
    x is: 80.0
    y is: 35.0
    radius is: 5
    xDelta is: 4.0
    yDelta is: 6.0
    Ball[(84.0,41.0),speed=(4.0,6.0)]
    Ball[(88.0,47.0),speed=(4.0,6.0)]
    Ball[(92.0,41.0),speed=(4.0,-6.0)]
    Ball[(96.0,35.0),speed=(4.0,-6.0)]
    Ball[(92.0,29.0),speed=(-4.0,-6.0)]
    Ball[(88.0,23.0),speed=(-4.0,-6.0)]
    Ball[(84.0,17.0),speed=(-4.0,-6.0)]
    Ball[(80.0,11.0),speed=(-4.0,-6.0)]
    Ball[(76.0,5.0),speed=(-4.0,-6.0)]
    Ball[(72.0,-1.0),speed=(-4.0,-6.0)]
    Ball[(68.0,5.0),speed=(-4.0,6.0)]
    Ball[(64.0,11.0),speed=(-4.0,6.0)]
    Ball[(60.0,17.0),speed=(-4.0,6.0)]
    Ball[(56.0,23.0),speed=(-4.0,6.0)]
    Ball[(52.0,29.0),speed=(-4.0,6.0)]
    75 is the output of the
    public Author (String name, String email, char gender) {......}
    5 method from the superclass.

The

Rectangle[length=1.2,width=3.4]
Rectangle[length=1.0,width=1.0]
Rectangle[length=5.6,width=7.8]
length is: 5.6
width is: 7.8
area is: 43.68
perimeter is: 26.80
11 class contains:

  • Two instance variables
    01:02:03
    04:05:06
    Hour: 4
    Minute: 5
    Second: 6
    23:59:58
    23:59:59
    00:00:01
    00:00:00
    23:59:58
    53 (
    Account[id=A101,name=Tan Ah Teck,balance=88]
    Account[id=A102,name=Kumar,balance=0]
    ID: A101 
    Name: Tan Ah Teck
    Balance: 88 
    Account[id=A101,name=Tan Ah Teck,balance=188]
    Account[id=A101,name=Tan Ah Teck,balance=138]
    Amount exceeded balance
    Account[id=A101,name=Tan Ah Teck,balance=138]
    Account[id=A101,name=Tan Ah Teck,balance=38]
    Account[id=A102,name=Kumar,balance=100]
    2) and
    Ball[(1.1,2.2),speed=(3.3,4.4)]
    Ball[(80.0,35.0),speed=(4.0,6.0)]
    x is: 80.0
    y is: 35.0
    radius is: 5
    xDelta is: 4.0
    yDelta is: 6.0
    Ball[(84.0,41.0),speed=(4.0,6.0)]
    Ball[(88.0,47.0),speed=(4.0,6.0)]
    Ball[(92.0,41.0),speed=(4.0,-6.0)]
    Ball[(96.0,35.0),speed=(4.0,-6.0)]
    Ball[(92.0,29.0),speed=(-4.0,-6.0)]
    Ball[(88.0,23.0),speed=(-4.0,-6.0)]
    Ball[(84.0,17.0),speed=(-4.0,-6.0)]
    Ball[(80.0,11.0),speed=(-4.0,-6.0)]
    Ball[(76.0,5.0),speed=(-4.0,-6.0)]
    Ball[(72.0,-1.0),speed=(-4.0,-6.0)]
    Ball[(68.0,5.0),speed=(-4.0,6.0)]
    Ball[(64.0,11.0),speed=(-4.0,6.0)]
    Ball[(60.0,17.0),speed=(-4.0,6.0)]
    Ball[(56.0,23.0),speed=(-4.0,6.0)]
    Ball[(52.0,29.0),speed=(-4.0,6.0)]
    80 (
    Account[id=A101,name=Tan Ah Teck,balance=88]
    Account[id=A102,name=Kumar,balance=0]
    ID: A101 
    Name: Tan Ah Teck
    Balance: 88 
    Account[id=A101,name=Tan Ah Teck,balance=188]
    Account[id=A101,name=Tan Ah Teck,balance=138]
    Amount exceeded balance
    Account[id=A101,name=Tan Ah Teck,balance=138]
    Account[id=A101,name=Tan Ah Teck,balance=38]
    Account[id=A102,name=Kumar,balance=100]
    2).
  • Three constructors as shown. The no-arg constructor initializes the
    01:02:03
    04:05:06
    Hour: 4
    Minute: 5
    Second: 6
    23:59:58
    23:59:59
    00:00:01
    00:00:00
    23:59:58
    53 and
    Ball[(1.1,2.2),speed=(3.3,4.4)]
    Ball[(80.0,35.0),speed=(4.0,6.0)]
    x is: 80.0
    y is: 35.0
    radius is: 5
    xDelta is: 4.0
    yDelta is: 6.0
    Ball[(84.0,41.0),speed=(4.0,6.0)]
    Ball[(88.0,47.0),speed=(4.0,6.0)]
    Ball[(92.0,41.0),speed=(4.0,-6.0)]
    Ball[(96.0,35.0),speed=(4.0,-6.0)]
    Ball[(92.0,29.0),speed=(-4.0,-6.0)]
    Ball[(88.0,23.0),speed=(-4.0,-6.0)]
    Ball[(84.0,17.0),speed=(-4.0,-6.0)]
    Ball[(80.0,11.0),speed=(-4.0,-6.0)]
    Ball[(76.0,5.0),speed=(-4.0,-6.0)]
    Ball[(72.0,-1.0),speed=(-4.0,-6.0)]
    Ball[(68.0,5.0),speed=(-4.0,6.0)]
    Ball[(64.0,11.0),speed=(-4.0,6.0)]
    Ball[(60.0,17.0),speed=(-4.0,6.0)]
    Ball[(56.0,23.0),speed=(-4.0,6.0)]
    Ball[(52.0,29.0),speed=(-4.0,6.0)]
    80 to
    Account[id=A101,name=Tan Ah Teck,balance=88]
    Account[id=A102,name=Kumar,balance=0]
    ID: A101 
    Name: Tan Ah Teck
    Balance: 88 
    Account[id=A101,name=Tan Ah Teck,balance=188]
    Account[id=A101,name=Tan Ah Teck,balance=138]
    Amount exceeded balance
    Account[id=A101,name=Tan Ah Teck,balance=138]
    Account[id=A101,name=Tan Ah Teck,balance=38]
    Account[id=A102,name=Kumar,balance=100]
    5.
  • Getter and setter for all the instance variables.
  • Methods
    Account[id=A101,name=Tan Ah Teck,balance=88]
    Account[id=A102,name=Kumar,balance=0]
    ID: A101 
    Name: Tan Ah Teck
    Balance: 88 
    Account[id=A101,name=Tan Ah Teck,balance=188]
    Account[id=A101,name=Tan Ah Teck,balance=138]
    Amount exceeded balance
    Account[id=A101,name=Tan Ah Teck,balance=138]
    Account[id=A101,name=Tan Ah Teck,balance=38]
    Account[id=A102,name=Kumar,balance=100]
    9 and
    InvoiceItem[id=A101,desc=Pen Red,qty=888,unitPrice=0.08]
    InvoiceItem[id=A101,desc=Pen Red,qty=999,unitPrice=0.99]
    id is: A101
    desc is: Pen Red
    qty is: 999
    unitPrice is: 0.99
    The total is: 989.01
    
    42.
  • Override the
    public Author (String name, String email, char gender) {......}
    5 method inherited, to return "
    Ball[(1.1,2.2),speed=(3.3,4.4)]
    Ball[(80.0,35.0),speed=(4.0,6.0)]
    x is: 80.0
    y is: 35.0
    radius is: 5
    xDelta is: 4.0
    yDelta is: 6.0
    Ball[(84.0,41.0),speed=(4.0,6.0)]
    Ball[(88.0,47.0),speed=(4.0,6.0)]
    Ball[(92.0,41.0),speed=(4.0,-6.0)]
    Ball[(96.0,35.0),speed=(4.0,-6.0)]
    Ball[(92.0,29.0),speed=(-4.0,-6.0)]
    Ball[(88.0,23.0),speed=(-4.0,-6.0)]
    Ball[(84.0,17.0),speed=(-4.0,-6.0)]
    Ball[(80.0,11.0),speed=(-4.0,-6.0)]
    Ball[(76.0,5.0),speed=(-4.0,-6.0)]
    Ball[(72.0,-1.0),speed=(-4.0,-6.0)]
    Ball[(68.0,5.0),speed=(-4.0,6.0)]
    Ball[(64.0,11.0),speed=(-4.0,6.0)]
    Ball[(60.0,17.0),speed=(-4.0,6.0)]
    Ball[(56.0,23.0),speed=(-4.0,6.0)]
    Ball[(52.0,29.0),speed=(-4.0,6.0)]
    88", where
    Ball[(1.1,2.2),speed=(3.3,4.4)]
    Ball[(80.0,35.0),speed=(4.0,6.0)]
    x is: 80.0
    y is: 35.0
    radius is: 5
    xDelta is: 4.0
    yDelta is: 6.0
    Ball[(84.0,41.0),speed=(4.0,6.0)]
    Ball[(88.0,47.0),speed=(4.0,6.0)]
    Ball[(92.0,41.0),speed=(4.0,-6.0)]
    Ball[(96.0,35.0),speed=(4.0,-6.0)]
    Ball[(92.0,29.0),speed=(-4.0,-6.0)]
    Ball[(88.0,23.0),speed=(-4.0,-6.0)]
    Ball[(84.0,17.0),speed=(-4.0,-6.0)]
    Ball[(80.0,11.0),speed=(-4.0,-6.0)]
    Ball[(76.0,5.0),speed=(-4.0,-6.0)]
    Ball[(72.0,-1.0),speed=(-4.0,-6.0)]
    Ball[(68.0,5.0),speed=(-4.0,6.0)]
    Ball[(64.0,11.0),speed=(-4.0,6.0)]
    Ball[(60.0,17.0),speed=(-4.0,6.0)]
    Ball[(56.0,23.0),speed=(-4.0,6.0)]
    Ball[(52.0,29.0),speed=(-4.0,6.0)]
    75 is the output of the
    public Author (String name, String email, char gender) {......}
    5 method from the superclass.

Write a class called

Ball[(1.1,2.2),speed=(3.3,4.4)]
Ball[(80.0,35.0),speed=(4.0,6.0)]
x is: 80.0
y is: 35.0
radius is: 5
xDelta is: 4.0
yDelta is: 6.0
Ball[(84.0,41.0),speed=(4.0,6.0)]
Ball[(88.0,47.0),speed=(4.0,6.0)]
Ball[(92.0,41.0),speed=(4.0,-6.0)]
Ball[(96.0,35.0),speed=(4.0,-6.0)]
Ball[(92.0,29.0),speed=(-4.0,-6.0)]
Ball[(88.0,23.0),speed=(-4.0,-6.0)]
Ball[(84.0,17.0),speed=(-4.0,-6.0)]
Ball[(80.0,11.0),speed=(-4.0,-6.0)]
Ball[(76.0,5.0),speed=(-4.0,-6.0)]
Ball[(72.0,-1.0),speed=(-4.0,-6.0)]
Ball[(68.0,5.0),speed=(-4.0,6.0)]
Ball[(64.0,11.0),speed=(-4.0,6.0)]
Ball[(60.0,17.0),speed=(-4.0,6.0)]
Ball[(56.0,23.0),speed=(-4.0,6.0)]
Ball[(52.0,29.0),speed=(-4.0,6.0)]
91, as a subclass of
Rectangle[length=1.2,width=3.4]
Rectangle[length=1.0,width=1.0]
Rectangle[length=5.6,width=7.8]
length is: 5.6
width is: 7.8
area is: 43.68
perimeter is: 26.80
11. Convince yourself that
Ball[(1.1,2.2),speed=(3.3,4.4)]
Ball[(80.0,35.0),speed=(4.0,6.0)]
x is: 80.0
y is: 35.0
radius is: 5
xDelta is: 4.0
yDelta is: 6.0
Ball[(84.0,41.0),speed=(4.0,6.0)]
Ball[(88.0,47.0),speed=(4.0,6.0)]
Ball[(92.0,41.0),speed=(4.0,-6.0)]
Ball[(96.0,35.0),speed=(4.0,-6.0)]
Ball[(92.0,29.0),speed=(-4.0,-6.0)]
Ball[(88.0,23.0),speed=(-4.0,-6.0)]
Ball[(84.0,17.0),speed=(-4.0,-6.0)]
Ball[(80.0,11.0),speed=(-4.0,-6.0)]
Ball[(76.0,5.0),speed=(-4.0,-6.0)]
Ball[(72.0,-1.0),speed=(-4.0,-6.0)]
Ball[(68.0,5.0),speed=(-4.0,6.0)]
Ball[(64.0,11.0),speed=(-4.0,6.0)]
Ball[(60.0,17.0),speed=(-4.0,6.0)]
Ball[(56.0,23.0),speed=(-4.0,6.0)]
Ball[(52.0,29.0),speed=(-4.0,6.0)]
91 can be modeled as a subclass of
Rectangle[length=1.2,width=3.4]
Rectangle[length=1.0,width=1.0]
Rectangle[length=5.6,width=7.8]
length is: 5.6
width is: 7.8
area is: 43.68
perimeter is: 26.80
11.
Ball[(1.1,2.2),speed=(3.3,4.4)]
Ball[(80.0,35.0),speed=(4.0,6.0)]
x is: 80.0
y is: 35.0
radius is: 5
xDelta is: 4.0
yDelta is: 6.0
Ball[(84.0,41.0),speed=(4.0,6.0)]
Ball[(88.0,47.0),speed=(4.0,6.0)]
Ball[(92.0,41.0),speed=(4.0,-6.0)]
Ball[(96.0,35.0),speed=(4.0,-6.0)]
Ball[(92.0,29.0),speed=(-4.0,-6.0)]
Ball[(88.0,23.0),speed=(-4.0,-6.0)]
Ball[(84.0,17.0),speed=(-4.0,-6.0)]
Ball[(80.0,11.0),speed=(-4.0,-6.0)]
Ball[(76.0,5.0),speed=(-4.0,-6.0)]
Ball[(72.0,-1.0),speed=(-4.0,-6.0)]
Ball[(68.0,5.0),speed=(-4.0,6.0)]
Ball[(64.0,11.0),speed=(-4.0,6.0)]
Ball[(60.0,17.0),speed=(-4.0,6.0)]
Ball[(56.0,23.0),speed=(-4.0,6.0)]
Ball[(52.0,29.0),speed=(-4.0,6.0)]
91 has no instance variable, but inherits the instance variables width and length from its superclass Rectangle.

  • Provide the appropriate constructors (as shown in the class diagram). Hint:
  • Override the
    public Author (String name, String email, char gender) {......}
    5 method to return "
    Ball[(1.1,2.2),speed=(3.3,4.4)]
    Ball[(80.0,35.0),speed=(4.0,6.0)]
    x is: 80.0
    y is: 35.0
    radius is: 5
    xDelta is: 4.0
    yDelta is: 6.0
    Ball[(84.0,41.0),speed=(4.0,6.0)]
    Ball[(88.0,47.0),speed=(4.0,6.0)]
    Ball[(92.0,41.0),speed=(4.0,-6.0)]
    Ball[(96.0,35.0),speed=(4.0,-6.0)]
    Ball[(92.0,29.0),speed=(-4.0,-6.0)]
    Ball[(88.0,23.0),speed=(-4.0,-6.0)]
    Ball[(84.0,17.0),speed=(-4.0,-6.0)]
    Ball[(80.0,11.0),speed=(-4.0,-6.0)]
    Ball[(76.0,5.0),speed=(-4.0,-6.0)]
    Ball[(72.0,-1.0),speed=(-4.0,-6.0)]
    Ball[(68.0,5.0),speed=(-4.0,6.0)]
    Ball[(64.0,11.0),speed=(-4.0,6.0)]
    Ball[(60.0,17.0),speed=(-4.0,6.0)]
    Ball[(56.0,23.0),speed=(-4.0,6.0)]
    Ball[(52.0,29.0),speed=(-4.0,6.0)]
    97", where
    Ball[(1.1,2.2),speed=(3.3,4.4)]
    Ball[(80.0,35.0),speed=(4.0,6.0)]
    x is: 80.0
    y is: 35.0
    radius is: 5
    xDelta is: 4.0
    yDelta is: 6.0
    Ball[(84.0,41.0),speed=(4.0,6.0)]
    Ball[(88.0,47.0),speed=(4.0,6.0)]
    Ball[(92.0,41.0),speed=(4.0,-6.0)]
    Ball[(96.0,35.0),speed=(4.0,-6.0)]
    Ball[(92.0,29.0),speed=(-4.0,-6.0)]
    Ball[(88.0,23.0),speed=(-4.0,-6.0)]
    Ball[(84.0,17.0),speed=(-4.0,-6.0)]
    Ball[(80.0,11.0),speed=(-4.0,-6.0)]
    Ball[(76.0,5.0),speed=(-4.0,-6.0)]
    Ball[(72.0,-1.0),speed=(-4.0,-6.0)]
    Ball[(68.0,5.0),speed=(-4.0,6.0)]
    Ball[(64.0,11.0),speed=(-4.0,6.0)]
    Ball[(60.0,17.0),speed=(-4.0,6.0)]
    Ball[(56.0,23.0),speed=(-4.0,6.0)]
    Ball[(52.0,29.0),speed=(-4.0,6.0)]
    75 is the output of the
    public Author (String name, String email, char gender) {......}
    5 method from the superclass.
  • Do you need to override the
    Account[id=A101,name=Tan Ah Teck,balance=88]
    Account[id=A102,name=Kumar,balance=0]
    ID: A101 
    Name: Tan Ah Teck
    Balance: 88 
    Account[id=A101,name=Tan Ah Teck,balance=188]
    Account[id=A101,name=Tan Ah Teck,balance=138]
    Amount exceeded balance
    Account[id=A101,name=Tan Ah Teck,balance=138]
    Account[id=A101,name=Tan Ah Teck,balance=38]
    Account[id=A102,name=Kumar,balance=100]
    9 and
    InvoiceItem[id=A101,desc=Pen Red,qty=888,unitPrice=0.08]
    InvoiceItem[id=A101,desc=Pen Red,qty=999,unitPrice=0.99]
    id is: A101
    desc is: Pen Red
    qty is: 999
    unitPrice is: 0.99
    The total is: 989.01
    
    42? Try them out.
  • Override the
    public Ball(float x, float y, int radius, int speed, int directionInDegree)
    02 and
    public Ball(float x, float y, int radius, int speed, int directionInDegree)
    03 to change both the
    01:02:03
    04:05:06
    Hour: 4
    Minute: 5
    Second: 6
    23:59:58
    23:59:59
    00:00:01
    00:00:00
    23:59:58
    53 and
    Ball[(1.1,2.2),speed=(3.3,4.4)]
    Ball[(80.0,35.0),speed=(4.0,6.0)]
    x is: 80.0
    y is: 35.0
    radius is: 5
    xDelta is: 4.0
    yDelta is: 6.0
    Ball[(84.0,41.0),speed=(4.0,6.0)]
    Ball[(88.0,47.0),speed=(4.0,6.0)]
    Ball[(92.0,41.0),speed=(4.0,-6.0)]
    Ball[(96.0,35.0),speed=(4.0,-6.0)]
    Ball[(92.0,29.0),speed=(-4.0,-6.0)]
    Ball[(88.0,23.0),speed=(-4.0,-6.0)]
    Ball[(84.0,17.0),speed=(-4.0,-6.0)]
    Ball[(80.0,11.0),speed=(-4.0,-6.0)]
    Ball[(76.0,5.0),speed=(-4.0,-6.0)]
    Ball[(72.0,-1.0),speed=(-4.0,-6.0)]
    Ball[(68.0,5.0),speed=(-4.0,6.0)]
    Ball[(64.0,11.0),speed=(-4.0,6.0)]
    Ball[(60.0,17.0),speed=(-4.0,6.0)]
    Ball[(56.0,23.0),speed=(-4.0,6.0)]
    Ball[(52.0,29.0),speed=(-4.0,6.0)]
    80, so as to maintain the square geometry.

Ex: Superclass Animal and its subclasses

Write the codes for all the classes as shown in the class diagram.

What kind of data is the colors of the cars around the gym in the scenario

Exercises on Composition vs Inheritance

They are two ways to reuse a class in your applications: composition and inheritance.

Ex: The Point and Line Classes

Let us begin with composition with the statement "a line composes of two points".

Complete the definition of the following two classes:

Ball[(1.1,2.2),speed=(3.3,4.4)]
Ball[(80.0,35.0),speed=(4.0,6.0)]
x is: 80.0
y is: 35.0
radius is: 5
xDelta is: 4.0
yDelta is: 6.0
Ball[(84.0,41.0),speed=(4.0,6.0)]
Ball[(88.0,47.0),speed=(4.0,6.0)]
Ball[(92.0,41.0),speed=(4.0,-6.0)]
Ball[(96.0,35.0),speed=(4.0,-6.0)]
Ball[(92.0,29.0),speed=(-4.0,-6.0)]
Ball[(88.0,23.0),speed=(-4.0,-6.0)]
Ball[(84.0,17.0),speed=(-4.0,-6.0)]
Ball[(80.0,11.0),speed=(-4.0,-6.0)]
Ball[(76.0,5.0),speed=(-4.0,-6.0)]
Ball[(72.0,-1.0),speed=(-4.0,-6.0)]
Ball[(68.0,5.0),speed=(-4.0,6.0)]
Ball[(64.0,11.0),speed=(-4.0,6.0)]
Ball[(60.0,17.0),speed=(-4.0,6.0)]
Ball[(56.0,23.0),speed=(-4.0,6.0)]
Ball[(52.0,29.0),speed=(-4.0,6.0)]
41 and
public Ball(float x, float y, int radius, int speed, int directionInDegree)
07. The class
public Ball(float x, float y, int radius, int speed, int directionInDegree)
07 composes 2 instances of class
Ball[(1.1,2.2),speed=(3.3,4.4)]
Ball[(80.0,35.0),speed=(4.0,6.0)]
x is: 80.0
y is: 35.0
radius is: 5
xDelta is: 4.0
yDelta is: 6.0
Ball[(84.0,41.0),speed=(4.0,6.0)]
Ball[(88.0,47.0),speed=(4.0,6.0)]
Ball[(92.0,41.0),speed=(4.0,-6.0)]
Ball[(96.0,35.0),speed=(4.0,-6.0)]
Ball[(92.0,29.0),speed=(-4.0,-6.0)]
Ball[(88.0,23.0),speed=(-4.0,-6.0)]
Ball[(84.0,17.0),speed=(-4.0,-6.0)]
Ball[(80.0,11.0),speed=(-4.0,-6.0)]
Ball[(76.0,5.0),speed=(-4.0,-6.0)]
Ball[(72.0,-1.0),speed=(-4.0,-6.0)]
Ball[(68.0,5.0),speed=(-4.0,6.0)]
Ball[(64.0,11.0),speed=(-4.0,6.0)]
Ball[(60.0,17.0),speed=(-4.0,6.0)]
Ball[(56.0,23.0),speed=(-4.0,6.0)]
Ball[(52.0,29.0),speed=(-4.0,6.0)]
41, representing the beginning and ending points of the line. Also write test classes for
Ball[(1.1,2.2),speed=(3.3,4.4)]
Ball[(80.0,35.0),speed=(4.0,6.0)]
x is: 80.0
y is: 35.0
radius is: 5
xDelta is: 4.0
yDelta is: 6.0
Ball[(84.0,41.0),speed=(4.0,6.0)]
Ball[(88.0,47.0),speed=(4.0,6.0)]
Ball[(92.0,41.0),speed=(4.0,-6.0)]
Ball[(96.0,35.0),speed=(4.0,-6.0)]
Ball[(92.0,29.0),speed=(-4.0,-6.0)]
Ball[(88.0,23.0),speed=(-4.0,-6.0)]
Ball[(84.0,17.0),speed=(-4.0,-6.0)]
Ball[(80.0,11.0),speed=(-4.0,-6.0)]
Ball[(76.0,5.0),speed=(-4.0,-6.0)]
Ball[(72.0,-1.0),speed=(-4.0,-6.0)]
Ball[(68.0,5.0),speed=(-4.0,6.0)]
Ball[(64.0,11.0),speed=(-4.0,6.0)]
Ball[(60.0,17.0),speed=(-4.0,6.0)]
Ball[(56.0,23.0),speed=(-4.0,6.0)]
Ball[(52.0,29.0),speed=(-4.0,6.0)]
41 and
public Ball(float x, float y, int radius, int speed, int directionInDegree)
07 (says
public Ball(float x, float y, int radius, int speed, int directionInDegree)
12 and
public Ball(float x, float y, int radius, int speed, int directionInDegree)
13).

InvoiceItem[id=A101,desc=Pen Red,qty=888,unitPrice=0.08]
InvoiceItem[id=A101,desc=Pen Red,qty=999,unitPrice=0.99]
id is: A101
desc is: Pen Red
qty is: 999
unitPrice is: 0.99
The total is: 989.01
0

The class diagram for composition is as follows (where a diamond-hollow-head arrow pointing to its constituents):

What kind of data is the colors of the cars around the gym in the scenario

Instead of composition, we can design a

public Ball(float x, float y, int radius, int speed, int directionInDegree)
07 class using
public Ball(float x, float y, int radius, int speed, int directionInDegree)
15. Instead of "a line composes of two points", we can say that "a line is a point extended by another point", as shown in the following class diagram:

What kind of data is the colors of the cars around the gym in the scenario

Let's re-design the

public Ball(float x, float y, int radius, int speed, int directionInDegree)
07 class (called
public Ball(float x, float y, int radius, int speed, int directionInDegree)
17) as a subclass of class
Ball[(1.1,2.2),speed=(3.3,4.4)]
Ball[(80.0,35.0),speed=(4.0,6.0)]
x is: 80.0
y is: 35.0
radius is: 5
xDelta is: 4.0
yDelta is: 6.0
Ball[(84.0,41.0),speed=(4.0,6.0)]
Ball[(88.0,47.0),speed=(4.0,6.0)]
Ball[(92.0,41.0),speed=(4.0,-6.0)]
Ball[(96.0,35.0),speed=(4.0,-6.0)]
Ball[(92.0,29.0),speed=(-4.0,-6.0)]
Ball[(88.0,23.0),speed=(-4.0,-6.0)]
Ball[(84.0,17.0),speed=(-4.0,-6.0)]
Ball[(80.0,11.0),speed=(-4.0,-6.0)]
Ball[(76.0,5.0),speed=(-4.0,-6.0)]
Ball[(72.0,-1.0),speed=(-4.0,-6.0)]
Ball[(68.0,5.0),speed=(-4.0,6.0)]
Ball[(64.0,11.0),speed=(-4.0,6.0)]
Ball[(60.0,17.0),speed=(-4.0,6.0)]
Ball[(56.0,23.0),speed=(-4.0,6.0)]
Ball[(52.0,29.0),speed=(-4.0,6.0)]
41.
public Ball(float x, float y, int radius, int speed, int directionInDegree)
17 inherits the starting point from its superclass
Ball[(1.1,2.2),speed=(3.3,4.4)]
Ball[(80.0,35.0),speed=(4.0,6.0)]
x is: 80.0
y is: 35.0
radius is: 5
xDelta is: 4.0
yDelta is: 6.0
Ball[(84.0,41.0),speed=(4.0,6.0)]
Ball[(88.0,47.0),speed=(4.0,6.0)]
Ball[(92.0,41.0),speed=(4.0,-6.0)]
Ball[(96.0,35.0),speed=(4.0,-6.0)]
Ball[(92.0,29.0),speed=(-4.0,-6.0)]
Ball[(88.0,23.0),speed=(-4.0,-6.0)]
Ball[(84.0,17.0),speed=(-4.0,-6.0)]
Ball[(80.0,11.0),speed=(-4.0,-6.0)]
Ball[(76.0,5.0),speed=(-4.0,-6.0)]
Ball[(72.0,-1.0),speed=(-4.0,-6.0)]
Ball[(68.0,5.0),speed=(-4.0,6.0)]
Ball[(64.0,11.0),speed=(-4.0,6.0)]
Ball[(60.0,17.0),speed=(-4.0,6.0)]
Ball[(56.0,23.0),speed=(-4.0,6.0)]
Ball[(52.0,29.0),speed=(-4.0,6.0)]
41, and adds an ending point. Complete the class definition. Write a testing class called
public Ball(float x, float y, int radius, int speed, int directionInDegree)
21 to test
public Ball(float x, float y, int radius, int speed, int directionInDegree)
17.

Summary: There are two approaches that you can design a line,

public Ball(float x, float y, int radius, int speed, int directionInDegree)
23 or
public Ball(float x, float y, int radius, int speed, int directionInDegree)
15. "A line composes two points" or "A line is a point extended with another point"”. Compare the
public Ball(float x, float y, int radius, int speed, int directionInDegree)
07 and
public Ball(float x, float y, int radius, int speed, int directionInDegree)
17 designs:
public Ball(float x, float y, int radius, int speed, int directionInDegree)
07 uses composition and
public Ball(float x, float y, int radius, int speed, int directionInDegree)
17 uses inheritance. Which design is better?

Ex: The Circle and Cylinder Classes Using Composition

What kind of data is the colors of the cars around the gym in the scenario

Try rewriting the

public Ball(float x, float y, int radius, int speed, int directionInDegree)
29 of the previous exercise using composition (as shown in the class diagram) instead of inheritance. That is, "a cylinder is composed of a base circle and a height".

Which design (inheritance or composition) is better?

Exercises on Polymorphism, Abstract Classes and Interfaces

Ex: Abstract Superclass Shape and Its Concrete Subclasses

Rewrite the superclass

Ball[(1.1,2.2),speed=(3.3,4.4)]
Ball[(80.0,35.0),speed=(4.0,6.0)]
x is: 80.0
y is: 35.0
radius is: 5
xDelta is: 4.0
yDelta is: 6.0
Ball[(84.0,41.0),speed=(4.0,6.0)]
Ball[(88.0,47.0),speed=(4.0,6.0)]
Ball[(92.0,41.0),speed=(4.0,-6.0)]
Ball[(96.0,35.0),speed=(4.0,-6.0)]
Ball[(92.0,29.0),speed=(-4.0,-6.0)]
Ball[(88.0,23.0),speed=(-4.0,-6.0)]
Ball[(84.0,17.0),speed=(-4.0,-6.0)]
Ball[(80.0,11.0),speed=(-4.0,-6.0)]
Ball[(76.0,5.0),speed=(-4.0,-6.0)]
Ball[(72.0,-1.0),speed=(-4.0,-6.0)]
Ball[(68.0,5.0),speed=(-4.0,6.0)]
Ball[(64.0,11.0),speed=(-4.0,6.0)]
Ball[(60.0,17.0),speed=(-4.0,6.0)]
Ball[(56.0,23.0),speed=(-4.0,6.0)]
Ball[(52.0,29.0),speed=(-4.0,6.0)]
46 and its subclasses
01/02/2014
09/12/2099
Month: 12
Day: 9
Year: 2099
03/04/2016
2,
Rectangle[length=1.2,width=3.4]
Rectangle[length=1.0,width=1.0]
Rectangle[length=5.6,width=7.8]
length is: 5.6
width is: 7.8
area is: 43.68
perimeter is: 26.80
11 and
Ball[(1.1,2.2),speed=(3.3,4.4)]
Ball[(80.0,35.0),speed=(4.0,6.0)]
x is: 80.0
y is: 35.0
radius is: 5
xDelta is: 4.0
yDelta is: 6.0
Ball[(84.0,41.0),speed=(4.0,6.0)]
Ball[(88.0,47.0),speed=(4.0,6.0)]
Ball[(92.0,41.0),speed=(4.0,-6.0)]
Ball[(96.0,35.0),speed=(4.0,-6.0)]
Ball[(92.0,29.0),speed=(-4.0,-6.0)]
Ball[(88.0,23.0),speed=(-4.0,-6.0)]
Ball[(84.0,17.0),speed=(-4.0,-6.0)]
Ball[(80.0,11.0),speed=(-4.0,-6.0)]
Ball[(76.0,5.0),speed=(-4.0,-6.0)]
Ball[(72.0,-1.0),speed=(-4.0,-6.0)]
Ball[(68.0,5.0),speed=(-4.0,6.0)]
Ball[(64.0,11.0),speed=(-4.0,6.0)]
Ball[(60.0,17.0),speed=(-4.0,6.0)]
Ball[(56.0,23.0),speed=(-4.0,6.0)]
Ball[(52.0,29.0),speed=(-4.0,6.0)]
91, as shown in the class diagram.

Ball[(1.1,2.2),speed=(3.3,4.4)]
Ball[(80.0,35.0),speed=(4.0,6.0)]
x is: 80.0
y is: 35.0
radius is: 5
xDelta is: 4.0
yDelta is: 6.0
Ball[(84.0,41.0),speed=(4.0,6.0)]
Ball[(88.0,47.0),speed=(4.0,6.0)]
Ball[(92.0,41.0),speed=(4.0,-6.0)]
Ball[(96.0,35.0),speed=(4.0,-6.0)]
Ball[(92.0,29.0),speed=(-4.0,-6.0)]
Ball[(88.0,23.0),speed=(-4.0,-6.0)]
Ball[(84.0,17.0),speed=(-4.0,-6.0)]
Ball[(80.0,11.0),speed=(-4.0,-6.0)]
Ball[(76.0,5.0),speed=(-4.0,-6.0)]
Ball[(72.0,-1.0),speed=(-4.0,-6.0)]
Ball[(68.0,5.0),speed=(-4.0,6.0)]
Ball[(64.0,11.0),speed=(-4.0,6.0)]
Ball[(60.0,17.0),speed=(-4.0,6.0)]
Ball[(56.0,23.0),speed=(-4.0,6.0)]
Ball[(52.0,29.0),speed=(-4.0,6.0)]
46 is an
public Ball(float x, float y, int radius, int speed, int directionInDegree)
35 class containing 2
public Ball(float x, float y, int radius, int speed, int directionInDegree)
35 methods:
Account[id=A101,name=Tan Ah Teck,balance=88]
Account[id=A102,name=Kumar,balance=0]
ID: A101 
Name: Tan Ah Teck
Balance: 88 
Account[id=A101,name=Tan Ah Teck,balance=188]
Account[id=A101,name=Tan Ah Teck,balance=138]
Amount exceeded balance
Account[id=A101,name=Tan Ah Teck,balance=138]
Account[id=A101,name=Tan Ah Teck,balance=38]
Account[id=A102,name=Kumar,balance=100]
9 and
InvoiceItem[id=A101,desc=Pen Red,qty=888,unitPrice=0.08]
InvoiceItem[id=A101,desc=Pen Red,qty=999,unitPrice=0.99]
id is: A101
desc is: Pen Red
qty is: 999
unitPrice is: 0.99
The total is: 989.01
42, where its concrete subclasses must provide its implementation. All instance variables shall have
public Ball(float x, float y, int radius, int speed, int directionInDegree)
39 access, i.e., accessible by its subclasses and classes in the same package. Mark all the overridden methods with annotation
Ball[(1.1,2.2),speed=(3.3,4.4)]
Ball[(80.0,35.0),speed=(4.0,6.0)]
x is: 80.0
y is: 35.0
radius is: 5
xDelta is: 4.0
yDelta is: 6.0
Ball[(84.0,41.0),speed=(4.0,6.0)]
Ball[(88.0,47.0),speed=(4.0,6.0)]
Ball[(92.0,41.0),speed=(4.0,-6.0)]
Ball[(96.0,35.0),speed=(4.0,-6.0)]
Ball[(92.0,29.0),speed=(-4.0,-6.0)]
Ball[(88.0,23.0),speed=(-4.0,-6.0)]
Ball[(84.0,17.0),speed=(-4.0,-6.0)]
Ball[(80.0,11.0),speed=(-4.0,-6.0)]
Ball[(76.0,5.0),speed=(-4.0,-6.0)]
Ball[(72.0,-1.0),speed=(-4.0,-6.0)]
Ball[(68.0,5.0),speed=(-4.0,6.0)]
Ball[(64.0,11.0),speed=(-4.0,6.0)]
Ball[(60.0,17.0),speed=(-4.0,6.0)]
Ball[(56.0,23.0),speed=(-4.0,6.0)]
Ball[(52.0,29.0),speed=(-4.0,6.0)]
10.

What kind of data is the colors of the cars around the gym in the scenario

In this exercise,

Ball[(1.1,2.2),speed=(3.3,4.4)]
Ball[(80.0,35.0),speed=(4.0,6.0)]
x is: 80.0
y is: 35.0
radius is: 5
xDelta is: 4.0
yDelta is: 6.0
Ball[(84.0,41.0),speed=(4.0,6.0)]
Ball[(88.0,47.0),speed=(4.0,6.0)]
Ball[(92.0,41.0),speed=(4.0,-6.0)]
Ball[(96.0,35.0),speed=(4.0,-6.0)]
Ball[(92.0,29.0),speed=(-4.0,-6.0)]
Ball[(88.0,23.0),speed=(-4.0,-6.0)]
Ball[(84.0,17.0),speed=(-4.0,-6.0)]
Ball[(80.0,11.0),speed=(-4.0,-6.0)]
Ball[(76.0,5.0),speed=(-4.0,-6.0)]
Ball[(72.0,-1.0),speed=(-4.0,-6.0)]
Ball[(68.0,5.0),speed=(-4.0,6.0)]
Ball[(64.0,11.0),speed=(-4.0,6.0)]
Ball[(60.0,17.0),speed=(-4.0,6.0)]
Ball[(56.0,23.0),speed=(-4.0,6.0)]
Ball[(52.0,29.0),speed=(-4.0,6.0)]
46 shall be defined as an
public Ball(float x, float y, int radius, int speed, int directionInDegree)
35 class, which contains:

  • Two
    public Ball(float x, float y, int radius, int speed, int directionInDegree)
    39 instance variables
    Account[id=A101,name=Tan Ah Teck,balance=88]
    Account[id=A102,name=Kumar,balance=0]
    ID: A101 
    Name: Tan Ah Teck
    Balance: 88 
    Account[id=A101,name=Tan Ah Teck,balance=188]
    Account[id=A101,name=Tan Ah Teck,balance=138]
    Amount exceeded balance
    Account[id=A101,name=Tan Ah Teck,balance=138]
    Account[id=A101,name=Tan Ah Teck,balance=38]
    Account[id=A102,name=Kumar,balance=100]
    3(
    Account[id=A101,name=Tan Ah Teck,balance=88]
    Account[id=A102,name=Kumar,balance=0]
    ID: A101 
    Name: Tan Ah Teck
    Balance: 88 
    Account[id=A101,name=Tan Ah Teck,balance=188]
    Account[id=A101,name=Tan Ah Teck,balance=138]
    Amount exceeded balance
    Account[id=A101,name=Tan Ah Teck,balance=138]
    Account[id=A101,name=Tan Ah Teck,balance=38]
    Account[id=A102,name=Kumar,balance=100]
    4) and
    Ball[(1.1,2.2),speed=(3.3,4.4)]
    Ball[(80.0,35.0),speed=(4.0,6.0)]
    x is: 80.0
    y is: 35.0
    radius is: 5
    xDelta is: 4.0
    yDelta is: 6.0
    Ball[(84.0,41.0),speed=(4.0,6.0)]
    Ball[(88.0,47.0),speed=(4.0,6.0)]
    Ball[(92.0,41.0),speed=(4.0,-6.0)]
    Ball[(96.0,35.0),speed=(4.0,-6.0)]
    Ball[(92.0,29.0),speed=(-4.0,-6.0)]
    Ball[(88.0,23.0),speed=(-4.0,-6.0)]
    Ball[(84.0,17.0),speed=(-4.0,-6.0)]
    Ball[(80.0,11.0),speed=(-4.0,-6.0)]
    Ball[(76.0,5.0),speed=(-4.0,-6.0)]
    Ball[(72.0,-1.0),speed=(-4.0,-6.0)]
    Ball[(68.0,5.0),speed=(-4.0,6.0)]
    Ball[(64.0,11.0),speed=(-4.0,6.0)]
    Ball[(60.0,17.0),speed=(-4.0,6.0)]
    Ball[(56.0,23.0),speed=(-4.0,6.0)]
    Ball[(52.0,29.0),speed=(-4.0,6.0)]
    49(
    01:02:03
    04:05:06
    Hour: 4
    Minute: 5
    Second: 6
    23:59:58
    23:59:59
    00:00:01
    00:00:00
    23:59:58
    61). The
    public Ball(float x, float y, int radius, int speed, int directionInDegree)
    39 variables can be accessed by its subclasses and classes in the same package. They are denoted with a
    public Ball(float x, float y, int radius, int speed, int directionInDegree)
    49 sign in the class diagram.
  • Getter and setter for all the instance variables, and
    public Author (String name, String email, char gender) {......}
    5.
  • Two
    public Ball(float x, float y, int radius, int speed, int directionInDegree)
    35 methods
    Account[id=A101,name=Tan Ah Teck,balance=88]
    Account[id=A102,name=Kumar,balance=0]
    ID: A101 
    Name: Tan Ah Teck
    Balance: 88 
    Account[id=A101,name=Tan Ah Teck,balance=188]
    Account[id=A101,name=Tan Ah Teck,balance=138]
    Amount exceeded balance
    Account[id=A101,name=Tan Ah Teck,balance=138]
    Account[id=A101,name=Tan Ah Teck,balance=38]
    Account[id=A102,name=Kumar,balance=100]
    9 and
    InvoiceItem[id=A101,desc=Pen Red,qty=888,unitPrice=0.08]
    InvoiceItem[id=A101,desc=Pen Red,qty=999,unitPrice=0.99]
    id is: A101
    desc is: Pen Red
    qty is: 999
    unitPrice is: 0.99
    The total is: 989.01
    
    42 (shown in italics in the class diagram).

The subclasses

01/02/2014
09/12/2099
Month: 12
Day: 9
Year: 2099
03/04/2016
2 and
Rectangle[length=1.2,width=3.4]
Rectangle[length=1.0,width=1.0]
Rectangle[length=5.6,width=7.8]
length is: 5.6
width is: 7.8
area is: 43.68
perimeter is: 26.80
11 shall override the
public Ball(float x, float y, int radius, int speed, int directionInDegree)
35 methods
Account[id=A101,name=Tan Ah Teck,balance=88]
Account[id=A102,name=Kumar,balance=0]
ID: A101 
Name: Tan Ah Teck
Balance: 88 
Account[id=A101,name=Tan Ah Teck,balance=188]
Account[id=A101,name=Tan Ah Teck,balance=138]
Amount exceeded balance
Account[id=A101,name=Tan Ah Teck,balance=138]
Account[id=A101,name=Tan Ah Teck,balance=38]
Account[id=A102,name=Kumar,balance=100]
9 and
InvoiceItem[id=A101,desc=Pen Red,qty=888,unitPrice=0.08]
InvoiceItem[id=A101,desc=Pen Red,qty=999,unitPrice=0.99]
id is: A101
desc is: Pen Red
qty is: 999
unitPrice is: 0.99
The total is: 989.01
42 and provide the proper implementation. They also override the
public Author (String name, String email, char gender) {......}
5.

Write a test class to test these statements involving polymorphism and explain the outputs. Some statements may trigger compilation errors. Explain the errors, if any.

What is the usage of the

public Ball(float x, float y, int radius, int speed, int directionInDegree)
35 method and
public Ball(float x, float y, int radius, int speed, int directionInDegree)
35 class?

Ex: GeometricObject Interface and its Implementation Classes Circle and Rectangle

Write an interface called

public Ball(float x, float y, int radius, int speed, int directionInDegree)
62, which contains 2
public Ball(float x, float y, int radius, int speed, int directionInDegree)
35 methods:
Account[id=A101,name=Tan Ah Teck,balance=88]
Account[id=A102,name=Kumar,balance=0]
ID: A101 
Name: Tan Ah Teck
Balance: 88 
Account[id=A101,name=Tan Ah Teck,balance=188]
Account[id=A101,name=Tan Ah Teck,balance=138]
Amount exceeded balance
Account[id=A101,name=Tan Ah Teck,balance=138]
Account[id=A101,name=Tan Ah Teck,balance=38]
Account[id=A102,name=Kumar,balance=100]
9 and
InvoiceItem[id=A101,desc=Pen Red,qty=888,unitPrice=0.08]
InvoiceItem[id=A101,desc=Pen Red,qty=999,unitPrice=0.99]
id is: A101
desc is: Pen Red
qty is: 999
unitPrice is: 0.99
The total is: 989.01
42, as shown in the class diagram. Also write an implementation class called
01/02/2014
09/12/2099
Month: 12
Day: 9
Year: 2099
03/04/2016
2. Mark all the overridden methods with annotation
Ball[(1.1,2.2),speed=(3.3,4.4)]
Ball[(80.0,35.0),speed=(4.0,6.0)]
x is: 80.0
y is: 35.0
radius is: 5
xDelta is: 4.0
yDelta is: 6.0
Ball[(84.0,41.0),speed=(4.0,6.0)]
Ball[(88.0,47.0),speed=(4.0,6.0)]
Ball[(92.0,41.0),speed=(4.0,-6.0)]
Ball[(96.0,35.0),speed=(4.0,-6.0)]
Ball[(92.0,29.0),speed=(-4.0,-6.0)]
Ball[(88.0,23.0),speed=(-4.0,-6.0)]
Ball[(84.0,17.0),speed=(-4.0,-6.0)]
Ball[(80.0,11.0),speed=(-4.0,-6.0)]
Ball[(76.0,5.0),speed=(-4.0,-6.0)]
Ball[(72.0,-1.0),speed=(-4.0,-6.0)]
Ball[(68.0,5.0),speed=(-4.0,6.0)]
Ball[(64.0,11.0),speed=(-4.0,6.0)]
Ball[(60.0,17.0),speed=(-4.0,6.0)]
Ball[(56.0,23.0),speed=(-4.0,6.0)]
Ball[(52.0,29.0),speed=(-4.0,6.0)]
10.

What kind of data is the colors of the cars around the gym in the scenario

Ex: Movable Interface and its Implementation MovablePoint Class

Write an interface called

public Ball(float x, float y, int radius, int speed, int directionInDegree)
68, which contains 4
public Ball(float x, float y, int radius, int speed, int directionInDegree)
35 methods
public Ball(float x, float y, int radius, int speed, int directionInDegree)
70,
public Ball(float x, float y, int radius, int speed, int directionInDegree)
71,
public Ball(float x, float y, int radius, int speed, int directionInDegree)
72 and
public Ball(float x, float y, int radius, int speed, int directionInDegree)
73, as shown in the class diagram. Also write an implementation class called
Ball[(1.1,2.2),speed=(3.3,4.4)]
Ball[(80.0,35.0),speed=(4.0,6.0)]
x is: 80.0
y is: 35.0
radius is: 5
xDelta is: 4.0
yDelta is: 6.0
Ball[(84.0,41.0),speed=(4.0,6.0)]
Ball[(88.0,47.0),speed=(4.0,6.0)]
Ball[(92.0,41.0),speed=(4.0,-6.0)]
Ball[(96.0,35.0),speed=(4.0,-6.0)]
Ball[(92.0,29.0),speed=(-4.0,-6.0)]
Ball[(88.0,23.0),speed=(-4.0,-6.0)]
Ball[(84.0,17.0),speed=(-4.0,-6.0)]
Ball[(80.0,11.0),speed=(-4.0,-6.0)]
Ball[(76.0,5.0),speed=(-4.0,-6.0)]
Ball[(72.0,-1.0),speed=(-4.0,-6.0)]
Ball[(68.0,5.0),speed=(-4.0,6.0)]
Ball[(64.0,11.0),speed=(-4.0,6.0)]
Ball[(60.0,17.0),speed=(-4.0,6.0)]
Ball[(56.0,23.0),speed=(-4.0,6.0)]
Ball[(52.0,29.0),speed=(-4.0,6.0)]
42. Mark all the overridden methods with annotation
Ball[(1.1,2.2),speed=(3.3,4.4)]
Ball[(80.0,35.0),speed=(4.0,6.0)]
x is: 80.0
y is: 35.0
radius is: 5
xDelta is: 4.0
yDelta is: 6.0
Ball[(84.0,41.0),speed=(4.0,6.0)]
Ball[(88.0,47.0),speed=(4.0,6.0)]
Ball[(92.0,41.0),speed=(4.0,-6.0)]
Ball[(96.0,35.0),speed=(4.0,-6.0)]
Ball[(92.0,29.0),speed=(-4.0,-6.0)]
Ball[(88.0,23.0),speed=(-4.0,-6.0)]
Ball[(84.0,17.0),speed=(-4.0,-6.0)]
Ball[(80.0,11.0),speed=(-4.0,-6.0)]
Ball[(76.0,5.0),speed=(-4.0,-6.0)]
Ball[(72.0,-1.0),speed=(-4.0,-6.0)]
Ball[(68.0,5.0),speed=(-4.0,6.0)]
Ball[(64.0,11.0),speed=(-4.0,6.0)]
Ball[(60.0,17.0),speed=(-4.0,6.0)]
Ball[(56.0,23.0),speed=(-4.0,6.0)]
Ball[(52.0,29.0),speed=(-4.0,6.0)]
10.

What kind of data is the colors of the cars around the gym in the scenario

Ex: Movable Interface and its Implementation Classes MovablePoint and MovableCircle

Write an interface called

public Ball(float x, float y, int radius, int speed, int directionInDegree)
68, which contains 4
public Ball(float x, float y, int radius, int speed, int directionInDegree)
35 methods
public Ball(float x, float y, int radius, int speed, int directionInDegree)
70,
public Ball(float x, float y, int radius, int speed, int directionInDegree)
71,
public Ball(float x, float y, int radius, int speed, int directionInDegree)
72 and
public Ball(float x, float y, int radius, int speed, int directionInDegree)
73, as shown in the class diagram. Also write the implementation classes called
Ball[(1.1,2.2),speed=(3.3,4.4)]
Ball[(80.0,35.0),speed=(4.0,6.0)]
x is: 80.0
y is: 35.0
radius is: 5
xDelta is: 4.0
yDelta is: 6.0
Ball[(84.0,41.0),speed=(4.0,6.0)]
Ball[(88.0,47.0),speed=(4.0,6.0)]
Ball[(92.0,41.0),speed=(4.0,-6.0)]
Ball[(96.0,35.0),speed=(4.0,-6.0)]
Ball[(92.0,29.0),speed=(-4.0,-6.0)]
Ball[(88.0,23.0),speed=(-4.0,-6.0)]
Ball[(84.0,17.0),speed=(-4.0,-6.0)]
Ball[(80.0,11.0),speed=(-4.0,-6.0)]
Ball[(76.0,5.0),speed=(-4.0,-6.0)]
Ball[(72.0,-1.0),speed=(-4.0,-6.0)]
Ball[(68.0,5.0),speed=(-4.0,6.0)]
Ball[(64.0,11.0),speed=(-4.0,6.0)]
Ball[(60.0,17.0),speed=(-4.0,6.0)]
Ball[(56.0,23.0),speed=(-4.0,6.0)]
Ball[(52.0,29.0),speed=(-4.0,6.0)]
42 and
public Ball(float x, float y, int radius, int speed, int directionInDegree)
83. Mark all the overridden methods with annotation
Ball[(1.1,2.2),speed=(3.3,4.4)]
Ball[(80.0,35.0),speed=(4.0,6.0)]
x is: 80.0
y is: 35.0
radius is: 5
xDelta is: 4.0
yDelta is: 6.0
Ball[(84.0,41.0),speed=(4.0,6.0)]
Ball[(88.0,47.0),speed=(4.0,6.0)]
Ball[(92.0,41.0),speed=(4.0,-6.0)]
Ball[(96.0,35.0),speed=(4.0,-6.0)]
Ball[(92.0,29.0),speed=(-4.0,-6.0)]
Ball[(88.0,23.0),speed=(-4.0,-6.0)]
Ball[(84.0,17.0),speed=(-4.0,-6.0)]
Ball[(80.0,11.0),speed=(-4.0,-6.0)]
Ball[(76.0,5.0),speed=(-4.0,-6.0)]
Ball[(72.0,-1.0),speed=(-4.0,-6.0)]
Ball[(68.0,5.0),speed=(-4.0,6.0)]
Ball[(64.0,11.0),speed=(-4.0,6.0)]
Ball[(60.0,17.0),speed=(-4.0,6.0)]
Ball[(56.0,23.0),speed=(-4.0,6.0)]
Ball[(52.0,29.0),speed=(-4.0,6.0)]
10.

What kind of data is the colors of the cars around the gym in the scenario

Ex: Interfaces Resizable and GeometricObject

What kind of data is the colors of the cars around the gym in the scenario
  1. Write the
    public Ball(float x, float y, int radius, int speed, int directionInDegree)
    85 called
    public Ball(float x, float y, int radius, int speed, int directionInDegree)
    62, which declares two
    public Ball(float x, float y, int radius, int speed, int directionInDegree)
    35 methods:
    public Ball(float x, float y, int radius, int speed, int directionInDegree)
    88 and
    Account[id=A101,name=Tan Ah Teck,balance=88]
    Account[id=A102,name=Kumar,balance=0]
    ID: A101 
    Name: Tan Ah Teck
    Balance: 88 
    Account[id=A101,name=Tan Ah Teck,balance=188]
    Account[id=A101,name=Tan Ah Teck,balance=138]
    Amount exceeded balance
    Account[id=A101,name=Tan Ah Teck,balance=138]
    Account[id=A101,name=Tan Ah Teck,balance=38]
    Account[id=A102,name=Kumar,balance=100]
    9, as specified in the class diagram.
    Hints:
    InvoiceItem[id=A101,desc=Pen Red,qty=888,unitPrice=0.08]
    InvoiceItem[id=A101,desc=Pen Red,qty=999,unitPrice=0.99]
    id is: A101
    desc is: Pen Red
    qty is: 999
    unitPrice is: 0.99
    The total is: 989.01
    
    1
  2. Write the implementation class
    01/02/2014
    09/12/2099
    Month: 12
    Day: 9
    Year: 2099
    03/04/2016
    2, with a protected variable
    Account[id=A101,name=Tan Ah Teck,balance=88]
    Account[id=A102,name=Kumar,balance=0]
    ID: A101 
    Name: Tan Ah Teck
    Balance: 88 
    Account[id=A101,name=Tan Ah Teck,balance=188]
    Account[id=A101,name=Tan Ah Teck,balance=138]
    Amount exceeded balance
    Account[id=A101,name=Tan Ah Teck,balance=138]
    Account[id=A101,name=Tan Ah Teck,balance=38]
    Account[id=A102,name=Kumar,balance=100]
    1, which implements the interface
    public Ball(float x, float y, int radius, int speed, int directionInDegree)
    62.
    Hints:
  3. Write a test program called
    01/02/2014
    09/12/2099
    Month: 12
    Day: 9
    Year: 2099
    03/04/2016
    6 to test the methods defined in
    01/02/2014
    09/12/2099
    Month: 12
    Day: 9
    Year: 2099
    03/04/2016
    2.
  4. The class
    public Ball(float x, float y, int radius, int speed, int directionInDegree)
    95 is defined as a subclass of the class
    01/02/2014
    09/12/2099
    Month: 12
    Day: 9
    Year: 2099
    03/04/2016
    2, which also implements an interface called
    public Ball(float x, float y, int radius, int speed, int directionInDegree)
    97, as shown in class diagram. The interface
    public Ball(float x, float y, int radius, int speed, int directionInDegree)
    97 declares an
    public Ball(float x, float y, int radius, int speed, int directionInDegree)
    35 method
    public Author (String name, String email, char gender) {......}
    00, which modifies the dimension (such as
    Account[id=A101,name=Tan Ah Teck,balance=88]
    Account[id=A102,name=Kumar,balance=0]
    ID: A101 
    Name: Tan Ah Teck
    Balance: 88 
    Account[id=A101,name=Tan Ah Teck,balance=188]
    Account[id=A101,name=Tan Ah Teck,balance=138]
    Amount exceeded balance
    Account[id=A101,name=Tan Ah Teck,balance=138]
    Account[id=A101,name=Tan Ah Teck,balance=38]
    Account[id=A102,name=Kumar,balance=100]
    1) by the given percentage. Write the interface
    public Ball(float x, float y, int radius, int speed, int directionInDegree)
    97 and the class
    public Ball(float x, float y, int radius, int speed, int directionInDegree)
    95.
    Hints:
    InvoiceItem[id=A101,desc=Pen Red,qty=888,unitPrice=0.08]
    InvoiceItem[id=A101,desc=Pen Red,qty=999,unitPrice=0.99]
    id is: A101
    desc is: Pen Red
    qty is: 999
    unitPrice is: 0.99
    The total is: 989.01
    
    2
  5. Write a test program called
    public Author (String name, String email, char gender) {......}
    04 to test the methods defined in
    public Ball(float x, float y, int radius, int speed, int directionInDegree)
    95.

Ex: Abstract Superclass Animal and its Implementation Subclasses

Write the codes for all the classes shown in the class diagram. Mark all the overridden methods with annotation @Override.

What kind of data is the colors of the cars around the gym in the scenario

Ex: Another View of Abstract Superclass Animal and its Implementation Subclasses

Examine the following codes and draw the class diagram.

InvoiceItem[id=A101,desc=Pen Red,qty=888,unitPrice=0.08]
InvoiceItem[id=A101,desc=Pen Red,qty=999,unitPrice=0.99]
id is: A101
desc is: Pen Red
qty is: 999
unitPrice is: 0.99
The total is: 989.01
3
InvoiceItem[id=A101,desc=Pen Red,qty=888,unitPrice=0.08]
InvoiceItem[id=A101,desc=Pen Red,qty=999,unitPrice=0.99]
id is: A101
desc is: Pen Red
qty is: 999
unitPrice is: 0.99
The total is: 989.01
4
InvoiceItem[id=A101,desc=Pen Red,qty=888,unitPrice=0.08]
InvoiceItem[id=A101,desc=Pen Red,qty=999,unitPrice=0.99]
id is: A101
desc is: Pen Red
qty is: 999
unitPrice is: 0.99
The total is: 989.01
5
InvoiceItem[id=A101,desc=Pen Red,qty=888,unitPrice=0.08]
InvoiceItem[id=A101,desc=Pen Red,qty=999,unitPrice=0.99]
id is: A101
desc is: Pen Red
qty is: 999
unitPrice is: 0.99
The total is: 989.01
6

Explain the outputs (or error) for the following test program.

Ex: Interface Movable and its implementation subclasses MovablePoint and MovableCircle

Suppose that we have a set of objects with some common behaviors: they could move up, down, left or right. The exact behaviors (such as how to move and how far to move) depend on the objects themselves. One common way to model these common behaviors is to define an interface called

public Author (String name, String email, char gender) {......}
06, with
public Ball(float x, float y, int radius, int speed, int directionInDegree)
35 methods
public Ball(float x, float y, int radius, int speed, int directionInDegree)
70,
public Ball(float x, float y, int radius, int speed, int directionInDegree)
71,
public Ball(float x, float y, int radius, int speed, int directionInDegree)
72 and
public Ball(float x, float y, int radius, int speed, int directionInDegree)
73. The classes that implement the
public Author (String name, String email, char gender) {......}
06 interface will provide actual implementation to these
public Ball(float x, float y, int radius, int speed, int directionInDegree)
35 methods.

Let's write two concrete classes -

Ball[(1.1,2.2),speed=(3.3,4.4)]
Ball[(80.0,35.0),speed=(4.0,6.0)]
x is: 80.0
y is: 35.0
radius is: 5
xDelta is: 4.0
yDelta is: 6.0
Ball[(84.0,41.0),speed=(4.0,6.0)]
Ball[(88.0,47.0),speed=(4.0,6.0)]
Ball[(92.0,41.0),speed=(4.0,-6.0)]
Ball[(96.0,35.0),speed=(4.0,-6.0)]
Ball[(92.0,29.0),speed=(-4.0,-6.0)]
Ball[(88.0,23.0),speed=(-4.0,-6.0)]
Ball[(84.0,17.0),speed=(-4.0,-6.0)]
Ball[(80.0,11.0),speed=(-4.0,-6.0)]
Ball[(76.0,5.0),speed=(-4.0,-6.0)]
Ball[(72.0,-1.0),speed=(-4.0,-6.0)]
Ball[(68.0,5.0),speed=(-4.0,6.0)]
Ball[(64.0,11.0),speed=(-4.0,6.0)]
Ball[(60.0,17.0),speed=(-4.0,6.0)]
Ball[(56.0,23.0),speed=(-4.0,6.0)]
Ball[(52.0,29.0),speed=(-4.0,6.0)]
42 and
public Ball(float x, float y, int radius, int speed, int directionInDegree)
83 - that implement the Movable interface.

What kind of data is the colors of the cars around the gym in the scenario

The code for the interface

public Author (String name, String email, char gender) {......}
06 is straight forward.

For the

Ball[(1.1,2.2),speed=(3.3,4.4)]
Ball[(80.0,35.0),speed=(4.0,6.0)]
x is: 80.0
y is: 35.0
radius is: 5
xDelta is: 4.0
yDelta is: 6.0
Ball[(84.0,41.0),speed=(4.0,6.0)]
Ball[(88.0,47.0),speed=(4.0,6.0)]
Ball[(92.0,41.0),speed=(4.0,-6.0)]
Ball[(96.0,35.0),speed=(4.0,-6.0)]
Ball[(92.0,29.0),speed=(-4.0,-6.0)]
Ball[(88.0,23.0),speed=(-4.0,-6.0)]
Ball[(84.0,17.0),speed=(-4.0,-6.0)]
Ball[(80.0,11.0),speed=(-4.0,-6.0)]
Ball[(76.0,5.0),speed=(-4.0,-6.0)]
Ball[(72.0,-1.0),speed=(-4.0,-6.0)]
Ball[(68.0,5.0),speed=(-4.0,6.0)]
Ball[(64.0,11.0),speed=(-4.0,6.0)]
Ball[(60.0,17.0),speed=(-4.0,6.0)]
Ball[(56.0,23.0),speed=(-4.0,6.0)]
Ball[(52.0,29.0),speed=(-4.0,6.0)]
42 class, declare the instance variable
Employee[id=8,name=Peter Tan,salary=2500]
Employee[id=8,name=Peter Tan,salary=999]
id is: 8
firstname is: Peter
lastname is: Tan
salary is: 999
name is: Peter Tan
annual salary is: 11988
1098
Employee[id=8,name=Peter Tan,salary=1098]
55,
Employee[id=8,name=Peter Tan,salary=2500]
Employee[id=8,name=Peter Tan,salary=999]
id is: 8
firstname is: Peter
lastname is: Tan
salary is: 999
name is: Peter Tan
annual salary is: 11988
1098
Employee[id=8,name=Peter Tan,salary=1098]
57,
public Author (String name, String email, char gender) {......}
20 and
public Author (String name, String email, char gender) {......}
21 with package access as shown with
public Author (String name, String email, char gender) {......}
22 in the class diagram (i.e., classes in the same package can access these variables directly). For the
public Ball(float x, float y, int radius, int speed, int directionInDegree)
83 class, use a
Ball[(1.1,2.2),speed=(3.3,4.4)]
Ball[(80.0,35.0),speed=(4.0,6.0)]
x is: 80.0
y is: 35.0
radius is: 5
xDelta is: 4.0
yDelta is: 6.0
Ball[(84.0,41.0),speed=(4.0,6.0)]
Ball[(88.0,47.0),speed=(4.0,6.0)]
Ball[(92.0,41.0),speed=(4.0,-6.0)]
Ball[(96.0,35.0),speed=(4.0,-6.0)]
Ball[(92.0,29.0),speed=(-4.0,-6.0)]
Ball[(88.0,23.0),speed=(-4.0,-6.0)]
Ball[(84.0,17.0),speed=(-4.0,-6.0)]
Ball[(80.0,11.0),speed=(-4.0,-6.0)]
Ball[(76.0,5.0),speed=(-4.0,-6.0)]
Ball[(72.0,-1.0),speed=(-4.0,-6.0)]
Ball[(68.0,5.0),speed=(-4.0,6.0)]
Ball[(64.0,11.0),speed=(-4.0,6.0)]
Ball[(60.0,17.0),speed=(-4.0,6.0)]
Ball[(56.0,23.0),speed=(-4.0,6.0)]
Ball[(52.0,29.0),speed=(-4.0,6.0)]
42 to represent its center (which contains four variable
Employee[id=8,name=Peter Tan,salary=2500]
Employee[id=8,name=Peter Tan,salary=999]
id is: 8
firstname is: Peter
lastname is: Tan
salary is: 999
name is: Peter Tan
annual salary is: 11988
1098
Employee[id=8,name=Peter Tan,salary=1098]
55,
Employee[id=8,name=Peter Tan,salary=2500]
Employee[id=8,name=Peter Tan,salary=999]
id is: 8
firstname is: Peter
lastname is: Tan
salary is: 999
name is: Peter Tan
annual salary is: 11988
1098
Employee[id=8,name=Peter Tan,salary=1098]
57,
public Author (String name, String email, char gender) {......}
20 and
public Author (String name, String email, char gender) {......}
21). In other words, the
public Ball(float x, float y, int radius, int speed, int directionInDegree)
83 composes a
Ball[(1.1,2.2),speed=(3.3,4.4)]
Ball[(80.0,35.0),speed=(4.0,6.0)]
x is: 80.0
y is: 35.0
radius is: 5
xDelta is: 4.0
yDelta is: 6.0
Ball[(84.0,41.0),speed=(4.0,6.0)]
Ball[(88.0,47.0),speed=(4.0,6.0)]
Ball[(92.0,41.0),speed=(4.0,-6.0)]
Ball[(96.0,35.0),speed=(4.0,-6.0)]
Ball[(92.0,29.0),speed=(-4.0,-6.0)]
Ball[(88.0,23.0),speed=(-4.0,-6.0)]
Ball[(84.0,17.0),speed=(-4.0,-6.0)]
Ball[(80.0,11.0),speed=(-4.0,-6.0)]
Ball[(76.0,5.0),speed=(-4.0,-6.0)]
Ball[(72.0,-1.0),speed=(-4.0,-6.0)]
Ball[(68.0,5.0),speed=(-4.0,6.0)]
Ball[(64.0,11.0),speed=(-4.0,6.0)]
Ball[(60.0,17.0),speed=(-4.0,6.0)]
Ball[(56.0,23.0),speed=(-4.0,6.0)]
Ball[(52.0,29.0),speed=(-4.0,6.0)]
42, and its
Account[id=A101,name=Tan Ah Teck,balance=88]
Account[id=A102,name=Kumar,balance=0]
ID: A101 
Name: Tan Ah Teck
Balance: 88 
Account[id=A101,name=Tan Ah Teck,balance=188]
Account[id=A101,name=Tan Ah Teck,balance=138]
Amount exceeded balance
Account[id=A101,name=Tan Ah Teck,balance=138]
Account[id=A101,name=Tan Ah Teck,balance=38]
Account[id=A102,name=Kumar,balance=100]
1.

Write a test program and try out these statements:

Write a new class called

public Author (String name, String email, char gender) {......}
32, which composes two
public Author (String name, String email, char gender) {......}
33 (representing the top-left and bottom-right corners) and implementing the
public Author (String name, String email, char gender) {......}
06 Interface. Make sure that the two points has the same speed.

What kind of data is the colors of the cars around the gym in the scenario

What is the difference between an interface and an abstract class?

More Exercises on OOP

Ex: The Discount System

You are asked to write a discount system for a beauty saloon, which provides services and sells beauty products. It offers 3 types of memberships: Premium, Gold and Silver. Premium, gold and silver members receive a discount of 20%, 15%, and 10%, respectively, for all services provided. Customers without membership receive no discount. All members receives a flat 10% discount on products purchased (this might change in future). Your system shall consist of three classes:

Employee[id=8,name=Peter Tan,salary=2500]
Employee[id=8,name=Peter Tan,salary=999]
id is: 8
firstname is: Peter
lastname is: Tan
salary is: 999
name is: Peter Tan
annual salary is: 11988
1098
Employee[id=8,name=Peter Tan,salary=1098]
42,
public Author (String name, String email, char gender) {......}
36 and
public Author (String name, String email, char gender) {......}
37, as shown in the class diagram. It shall compute the total bill if a customer purchases $x of products and $y of services, for a visit. Also write a test program to exercise all the classes.

What kind of data is the colors of the cars around the gym in the scenario

The class

public Author (String name, String email, char gender) {......}
38 contains only
01/02/2014
09/12/2099
Month: 12
Day: 9
Year: 2099
03/04/2016
24 variables and methods (underlined in the class diagram).

Ex: Polyline of Points with ArrayList

What kind of data is the colors of the cars around the gym in the scenario

A polyline is a line with segments formed by points. Let's use the

public Author (String name, String email, char gender) {......}
40 (dynamically allocated array) to keep the points, but upcast to
public Author (String name, String email, char gender) {......}
41 in the instance variable. (Take note that array is of fixed-length, and you need to set the initial length).

InvoiceItem[id=A101,desc=Pen Red,qty=888,unitPrice=0.08]
InvoiceItem[id=A101,desc=Pen Red,qty=999,unitPrice=0.99]
id is: A101
desc is: Pen Red
qty is: 999
unitPrice is: 0.99
The total is: 989.01
7

Exercises on Data Structures

Ex: MyIntStack

A stack is a first-in-last-out queue. Write a program called

public Author (String name, String email, char gender) {......}
42, which uses an array to store the contents, restricted to
Rectangle[length=1.2,width=3.4]
Rectangle[length=1.0,width=1.0]
Rectangle[length=5.6,width=7.8]
length is: 5.6
width is: 7.8
area is: 43.68
perimeter is: 26.80
81.