Consider the following class definitions.
class Point {
int x; // its x-coordinate
int y; // its y-coordinate
private static int n = 0; // number of Points created
Point(int x, int y) {
this.x = x;
this.y = y;
n++;
}
static int numberOfPointsCreated() {
return n;
}
}
class Color {
String name; // its name
int intensity; // its intensity
Color(String name, int intensity) {
this.name = name;
this.intensity = intensity;
}
}
Complete the class definition
class ColoredCircle {
Point origin; // its origin
int radius; // its radius
Color color; // its color
ColoredCircle(Point origin, int radius, Color color) {
this.origin = origin;
this.radius = radius;
this.color = color;
}
ColoredCircle setOrigin(Point origin) {
this.origin = origin;
return this;
}
public static void main(String[] args) {
/* create a ColoredCircle object named myColoredCircle
with x-coordinate 5, y-coordinate 6, radius 7,
color red and color intensity 8 */
int myRadius;
/* initialize myRadius to myColoredCircle's radius */
Point newOrigin;
/* instantiate and initialize Point object named
newOrigin with x-coordinate 9 and y-coordinate 10 */
/* change myColoredCircle's origin to newOrigin using
setOrigin */
int numberOfPointsCreated;
/* initialize numberOfPointsCreated to the number of Points
created so far using numberOfPointsCreated */
}
}
by
- creating a ColoredCircle object named myColoredCircle with
x-coordinate 5, y-coordinate 6, radius 7, color red and
color intensity 8,
- initializing myRadius to myColoredCircle's radius,
- instantiating and initializing Point object named newOrigin with
x-coordinate 9 and y-coordinate 10,
- changing myColoredCircle's origin to newOrigin using setOrigin and
- initializing numberOfPointsCreated to the number of Points
created so far using numberOfPointsCreated.