X462: Find Largest Shape

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

public class Shape {


public class Circle extends Shape
   private double radius;

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

   public double getRadius() {
       return radius;

   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 class Square extends Shape  {

    private double side;

    public Square(double len) {
        side = len;

    public double getSide() {
        return side;

    public double getPerimeter() {
        return 4 * side;

    public double getArea() {
        return side * side;


Write a method that takes in two variables: one of type Square, one of type Circle. This code should assign the object with the larger area the variable max defined below, then return max. The two shapes will never have the same Area.

Your Answer:


Practice a different Java exercise


Your feedback will appear here when you check your answer.