The Rectangle and Circle classes both extend from a common superclass named Shape. Your task is to implement this class so that the tester program compiles and runs successfully.

Complete the following file:

Shape.java

/** A two-dimensional shape */ public class Shape { . . . }

Use the following files:

Circle.java

public class Circle extends Shape
{
   private double radius;

   /**
      Constructs a circle.
      @param aRadius: the radius of the circle
   */
   public Circle(double aRadius) 
   { 
      radius = aRadius;
   }

   /**
      Computes the perimeter.
      @return the perimeter of the circle
   */
   public double perimeter() 
   {
      return 2 * Math.PI * radius;
   }

   /**
      Computes the area.
      @return the area of the circle
   */
   public double area() 
   {
      return Math.PI * radius * radius;
   }

   /** 
      Gets the radius of this circle
      @return the radius
   */
   public double getRadius()
   {
      return radius;
   }
}

Rectangle.java

public class Rectangle extends Shape
{
   private double height;
   private double width;

   /**
      Constructs a rectangle.
      @param aHeight: the height of the rectangle
      @param aWidth: the width of the rectangle
   */
   public Rectangle(double aHeight, double aWidth) 
   { 
      height = aHeight;
      width = aWidth;
   }

   /**
      Computes the perimeter.
      @return the perimeter of the rectangle
   */
   public double perimeter() 
   {
      return 2*(height + width);
   }

   /**
      Computes the area.
      @return the area of the rectangle
   */
   public double area() 
   {
      return height * width;
   }

   /**
      Gets the height of this rectangle
      @return the height
   */
   public double getHeight()
   {
      return height;
   }

   /**
      Gets the width of this rectangle
      @return the width
   */
   public double getWidth()
   {
      return width;
   }
}

ShapeTester.java

public class ShapeTester
{
   public static void main(String[] args)
   {
      Shape s1 = new Circle (1.0);
      Shape s2 = new Rectangle(2.0, 3.0);

      System.out.printf("%.2f ", s1.perimeter());
      System.out.printf("%.2f ", s1.area());
      System.out.printf("%.2f ", s2.perimeter());
      System.out.printf("%.2f\n", s2.area());
      System.out.print("Expected: 6.28 3.14 10.00 6.00");    
   }
}