Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package gd;
- import java.awt.Graphics;
- /**
- * A specific shape: A circle.
- * This cirlce inherits from Shape
- * @author hypesystem
- * @email [email protected]
- */
- public class Circle extends Shape implements Drawable, DrawableAndMovable {
- private double r;
- /**
- * Creates a circle witout a coordinate argument (sets coordinates to 0,0).
- * @param r radius of circle
- */
- public Circle(double r) {
- super(new Coordinate(0,0));
- setAttr(r);
- }
- /**
- * Creates a circle with a coordinate argument.
- * @param r radius of circle
- * @param coordinates coordinates of circle
- */
- public Circle(double r, Coordinate coordinates) {
- super(coordinates);
- setAttr(r);
- }
- /**
- * Sets the attributes of the Circle. Called from constructors (hence
- * private)
- * @param r radius of circle
- */
- private void setAttr(double r) {
- this.r = r;
- }
- /**
- * Calculates and returns the circumference of the circle. Inherited from
- * Shape.
- * @return circumference of circle
- */
- @Override
- public double circumference() {
- return (2 * r * Math.PI);
- }
- /**
- * Calculates and returns the area of the circle Inherited from Shape.
- * @return area of circle
- */
- @Override
- public double area() {
- return (r * r * Math.PI);
- }
- /**
- * Counts the amount of simple shapes in this shape. This is a simple shape.
- * Inherited from Shape.
- * @return 1
- */
- @Override
- public int countSimple() {
- return 1;
- }
- /**
- * Draws the cirlce to a specified graphic. Implemented from Drawable.
- * @param g graphic to draw to
- */
- @Override
- public void draw(Graphics g) {
- g.fillOval(getCoordinate().getX(), getCoordinate().getY(),
- (int)(2*r), (int)(2*r));
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment