Java Exercises
Java Exercises
Exercise 3:
1. Creating class called Point as below (can use Point class in exercise 2):
1. Creating class called Circle as below (can use Point class in exercise 2):
It contains:
Two private member variables: a radius (double) and a center (an instance
of Point class, which we created earlier).
The constructors, public getters and setters.
Methods getCenterX(), setCenterX(), getCenterY(), setCenterY(), getCenterXY(),
setCenterXY(), etc.
A toString() method that returns a string description of this instance in the format of
"Circle[center=(x,y),radius=r]". You should re-use the Point's toString() to print
"(x,y)".
A distance(Circle another) method that returns the distance from the center
of this instance to the center of the given Circle instance (called another).
Exercise 4:
Exercise 6: designing a superclass called Shape, which defines the public interfaces (or behaviors) of
all the shapes. For example, we would like all the shapes to have a method called getArea(), which
returns the area of that particular shape. The Shape class can be written as follow.