Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package gd;
- /**
- * This is a superclass: A shape. Cirlce, Rectangle and Triangle inherit from
- * it.
- * This class was from the beginning defined (by me) as an abstract class. This
- * is because this class should never exist: You can't just add a "shape". It
- * has to be a certain kind of shape (as "shape" doesn't tell you anything about
- * it's properties).
- * A new class has been defines: Coordinate. This holds an x and a y coordinate
- * for the movable classes (making the coordinate set returnable in one state-
- * ment).
- * @author hypesystem
- * @email [email protected]
- */
- public abstract class Shape implements Movable {
- protected Coordinate coordinates;
- /**
- * Creates a Shape.
- * @param coordinates a coordinate object holding the shapes position
- */
- public Shape(Coordinate coordinates) {
- if(coordinates != null) this.coordinates = coordinates;
- else this.coordinates = new Coordinate(0,0);
- }
- /**
- * Returns the area of the shape
- * @return area of shape
- */
- abstract double area();
- /**
- * Returns circumference of shape
- * @return circumference of shape
- */
- abstract double circumference();
- /**
- * Counts simple shapes in the shape
- * @return simple shapes in shape
- */
- abstract int countSimple();
- /**
- * Moves the shape's coordinates. Inherited from Movable interface.
- * @param dx distance to move horizontally
- * @param dy distance to move vertically
- */
- @Override
- public void move(int dx, int dy) {
- if(coordinates != null)
- coordinates.set(coordinates.getX() + dx,coordinates.getY() + dy);
- }
- /**
- * Gets the coordinates of the shape in a Coordinate-object. Inherited from
- * Movable interface
- * @return coordinates of shape
- */
- @Override
- public Coordinate getCoordinate() {
- return coordinates;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment