/* File: Circle.java - February 2019 */ package l01; /** * A basic Circle class inspired by Geogebra. Java tends to use American * spelling for method names in libraries etc. hence "center" rather than * "centre". Sorry. * * @author Michael Albert * */ public class Circle{ private Point center; private Point handle; public Circle(Point center, Point handle) { this.center = center; this.handle = handle; } // An alternative construction given just center and radius. // Intentionally a bit "tricky" -- try and figure it out public Circle(Point center, double radius) { this(center, center.clone()); this.moveHandle(radius, 0.0); } public Point getCenter() { return center; } public Point getHandle() { return handle; } public double getRadius() { return center.distance(handle); } public void moveCenter(double dx, double dy) { center.move(dx, dy); } public void moveHandle(double dx, double dy) { handle.move(dx, dy); } // Move the whole circle public void move(double dx, double dy) { center.move(dx, dy); handle.move(dx, dy); } public String toString() { return "C[" + this.center + "," + this.getRadius() + "]"; } }