Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package gd;
- /**
- * This is a shape consisting of two shapes. Yes, two shapes in a shape. It's
- * like inception, but more.
- * @author hypesystem
- * @email [email protected]
- */
- public class TwoShapes extends Shape {
- private Shape shape1, shape2;
- /**
- * Creates a shape consisting of two other shapes.
- * @param shape1 the first shape
- * @param shape2 the second shape
- */
- public TwoShapes(Shape shape1, Shape shape2) {
- super(null);
- this.shape1 = shape1;
- this.shape2 = shape2;
- }
- /**
- * Returns the area of the multishape (the sum of the areas of the two
- * subshapes).
- * @return area of shape
- */
- @Override
- public double area() {
- return shape1.area() + shape2.area();
- }
- /**
- * If a shape consists of two shapes, its circumference is NOT equal to the
- * circumference of each shape. Even if they don't overlap, if it is still
- * ONE shape, its sides will touch at certain places, hence making the cir-
- * cumference smaller. However for the sake of this assignment I will do as
- * it insinuates in the assignment.
- * @return circumference of shape (as if)
- */
- @Override
- public double circumference() {
- return shape1.circumference() + shape2.circumference();
- }
- /**
- * Counts the simple shapes in this composite shape.
- * @return amount of simple shapes
- */
- @Override
- public int countSimple() {
- return shape1.countSimple() + shape2.countSimple();
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment