hypesystem

GD - TwoShapes.java

Nov 1st, 2011
31
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.56 KB | None | 0 0
  1. package gd;
  2.  
  3. /**
  4.  * This is a shape consisting of two shapes. Yes, two shapes in a shape. It's
  5.  * like inception, but more.
  6.  * @author hypesystem
  7.  * @email  [email protected]
  8.  */
  9. public class TwoShapes extends Shape {
  10.     private Shape shape1, shape2;
  11.    
  12.     /**
  13.      * Creates a shape consisting of two other shapes.
  14.      * @param shape1 the first shape
  15.      * @param shape2 the second shape
  16.      */
  17.     public TwoShapes(Shape shape1, Shape shape2) {
  18.         super(null);
  19.         this.shape1 = shape1;
  20.         this.shape2 = shape2;
  21.     }
  22.    
  23.     /**
  24.      * Returns the area of the multishape (the sum of the areas of the two
  25.      * subshapes).
  26.      * @return area of shape
  27.      */
  28.     @Override
  29.     public double area() {
  30.         return shape1.area() + shape2.area();
  31.     }
  32.    
  33.     /**
  34.      * If a shape consists of two shapes, its circumference is NOT equal to the
  35.      * circumference of each shape. Even if they don't overlap, if it is still
  36.      * ONE shape, its sides will touch at certain places, hence making the cir-
  37.      * cumference smaller. However for the sake of this assignment I will do as
  38.      * it insinuates in the assignment.
  39.      * @return circumference of shape (as if)
  40.      */
  41.     @Override
  42.     public double circumference() {
  43.         return shape1.circumference() + shape2.circumference();
  44.     }
  45.    
  46.     /**
  47.      * Counts the simple shapes in this composite shape.
  48.      * @return amount of simple shapes
  49.      */
  50.     @Override
  51.     public int countSimple() {
  52.         return shape1.countSimple() + shape2.countSimple();
  53.     }
  54. }
Advertisement
Add Comment
Please, Sign In to add comment