অনুশীলন
Design a class named Point which will model a 2D point with X
and Y
coordinates.
Two instance variable variables
X
(int
) andX
(int
)A "no-argument" (or "no-arg") constructor that construct a point at
(0, 0)
.A constructor that constructs a point with the given
x
andy
coordinates.Getter and setter for the instance variables
x
and y.A method
setXY()
to set both x and y.A
toString()
method that returns a string description of the instance in the format `"(x,y)"`.
A method called
distance(int x, int y)
that returns the distance from this point toanother point at the given
(x, y)
coordinates.An overloaded
distance(Point another)
that returns the distance from this point tothe given
Point
instance another.
For example -
Now write a program that allocates 10 points in an array of Point
, and initializes to (1, 1), (2, 2), ... (10, 10).
Last updated