X777: Is Big Shape

For the question below, assume the following implementation of the Measurable interface and Square and Circle classes:

public interface Measurable
{
   /** Gets the perimeter.
       @return  The perimeter. */
   public double getPerimeter();

   /** Gets the area.
       @return  The area. */
   public double getArea();
} // end Measurable

public static final class Circle implements Measurable
{
   private double radius;


   public Circle(double newRadius)
   {
      radius = newRadius;
   } // end constructor


   public double getCircumference()
   {
      return 2.0 * Math.PI * radius;
   } // end getCircumference

   public double getPerimeter() // Measurable interface
   {
      return getCircumference();
   } // end getPerimeter

   public double getArea()      // Measurable interface
   {
      return Math.PI * radius * radius;
   } // end getArea

} // end Circle

public static class Square implements Measurable  {

    private double side;

    public Square(double len) {
        side = len;
    }

    @Override
    public double getPerimeter() {
        return 4 * side;
    }

    @Override
    public double getArea() {
        return side * side;
    }

}

For this exercise, you will be writing a method that takes in a variable of type Measurable and...

  • If perimeter is greater than 10 and area is greater than 20, return true
  • Otherwise, return false

Your Answer:

Feedback

Your feedback will appear here when you check your answer.