Question: For my HW assignment we're working with composition, and I've never used it before. I know how to use inheritance kind of, but I'm having

For my HW assignment we're working with composition, and I've never used it before. I know how to use inheritance kind of, but I'm having trouble figuring out how to impliment composition. I'll paste my class Point underneath what I need help doing.

So for the section I need help on, it says "Using the class Point, define another class Circle to model a circle. A circle should have a center and a radius. The circle contains: -a method that returns a Point instance

-a method that returns the circle's area

-a method that moves the circle's center(X,Y) to another position, the method heading should be like "public void move (Point newCenter){}"

-a method that resizes the circle radius according to the parameter, the method heading should be like "public void resize (double resizeRate){}"

-at least one alternate constructor which takes arguments (parameters) to initialize instance variables

Thank you in advance for the help!

---Point.java---

public class Point { private int X; private int Y;

public Point(int Xcoord, int Ycoord) { X = Xcoord; Y = Ycoord; }

public int getX() { return X; }

public void setX() { this.X = X; }

public int getY() { return Y; }

public void setY() { this.Y = Y; }

public String toString() { return "(" + X + "," + Y + ")"; }

}

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!