I'm new to java and I have to use a 3 argument Circle()
constructor to set 2 instance variables radius
and center
. I have to use x
and y
for the center
. Bellow is the UML diagram I'm working with. Thanks in advance.
public class Circle extends Point
{
private double radius;
private Point center;
public Circle(double x, double y, double radius)
{
super(x, y);
this.radius = radius;
}
CodePudding user response:
Okay so I figured it out. The constructor should be like this:
public Circle(double x, double y, double radius)
{
center = new Point(x, y);
this.radius = radius;
}
CodePudding user response:
That diagram indicates that the relationship between Circle
and Point
is a Composition.
So the relevant java code is:
public class Circle
{
private double radius;
private Point center;
public Circle(double x, double y, double radius)
{
this.radius = radius;
center = new Point(x, y);
}