import java.awt.Color; import java.awt.Point; /** * * Implementation of Shape as a Circle, plus some Circle-specific methods. * * @author Gene Fisher (gfisher@calpoly.edu) * */ public class Circle extends Shape { /** The radius */ private double radius; /** The position of this' center */ private Point position; int x; int y; int width; int height; /** * Construct this by intializing the data fields to the values of given * parameters. */ public Circle(double radius, Point position, Color color, boolean filled) { super(color, filled); this.radius = radius; this.position = position; } /** * Construct this via its framing rectangle. */ public Circle(int width, int height, Point lt, Color color, boolean filled) { super(color, filled); position = new Point(lt.x + width/2, lt.y + height/2); radius = lt.distance(position); } /** Return this' radius. */ public double getRadius() { return radius; } /** Return this' radius to the given radius. */ public void setRadius(double radius) { this.radius = radius; } /** Return this' position. */ public Point getPosition() { return position; } /** * Return true if this and the given other Circle are logically equivalent * based on the state of all of their instance variables. */ public boolean equals(Object other) { if ((other == null) || ! (other instanceof Circle)) { return false; } Circle c = (Circle) other; return super.equals(c) && position.equals(c.position) && radius == c.radius; } /*-* * Specialized methods for Circle */ public double getArea() { return Math.PI * radius * radius; } public void move(Point delta) { // Yipee, we got public data fields in java.awt.Point! position.x += delta.x; position.y += delta.y; } /* * Return the Java AWT representation of this as a Line2D.Double. */ public java.awt.Shape getAwtRep(int canvas_height) { return null; } }