Circle.java
Select all
/* Circle.java CIS 260 2005-02-09 David Klick This is a subclass of the Shape class. To create an object from this class, the abstract methods draw and area had to be implemented. */ import java.awt.Graphics; public class Circle extends Shape { private int radius; public Circle() { super(); setRadius(1); } public Circle(int x, int y, int r) { super(x, y); setRadius(r); } public Circle(Circle c) { super(c.origin); setRadius(c.radius); } public void setRadius(int r) { radius = r<0 ? -r : r; } public double area() { return Math.PI * radius * radius; } public int getRadius() { return radius; } public void draw(Graphics g) { g.drawOval(origin.x-radius, origin.y-radius, radius * 2, radius * 2); } public String toString() { return origin + ", r=" + radius; } }