Title: Shape.java, etc.
Course: CPS 261: Advanced Java Concepts ~ DL & MM MASTER

Shape.java

Note that Shape is Derived from Object


package exercise;
public abstract class Shape
{
   public Shape()
   {
     System.out.println("Shape Constructor");
   }
   public abstract double getPerimeter();
   public abstract double getArea();

   public double getAPRatio()
   {
           return getArea()/getPerimeter();
   }

   public static void main (String arguments[])
   {

   }

}


Rectangle.java


package exercise;
public class Rectangle extends Shape
{
   double width=1.0;
   double height=2.0;
   public Rectangle()
   {
    System.out.println("Rectangle Constructor");
   }
   public Rectangle(double height, double width)
   {
    System.out.println("Rectangle Constructor");
   }
   public double getPerimeter()
   {
    return 2*(width+height);
   }
   public double getArea()
   {
    return width*height;
   }
   public void setHeight(double h)
   {
    height =h;
   }
   public void setWidth(double w)
   {
    width = w;
   }
   public static void main (String arguments[])
   {
       // Put in some code to create some circles and print out
    // characteristics by calling the getXXX routines
   }


}




Square.java


package exercise;
public class Square extends Rectangle
{
   public Square()
   {
    super(2.0, 2.0);
    System.out.println("Square Constructor");
   }
   public Square(double side)
   {
    super(side, side);
    System.out.println("Square Constructor");
   }
   public void setHeight(double h)
   {
    super.setHeight(h);
    super.setWidth(h);
   }
   public void setWidth(double w)
   {
    super.setHeight(w);
    super.setWidth(w);
   }
   public static void main (String arguments[])
   {
       // Put in some code to create some circles and print out
    // characteristics by calling the getXXX routines
   }
}


Circle.java


package exercise;
public class Circle extends Shape
{
   double radius;
   public Circle()
   {
    System.out.println("Circle Constructor");
   }
   public Circle(double r)
   {
    System.out.println("Circle Constructor");
   }
   public double getPerimeter()
   {
    return -1.0; // Not done
   }
   public double getArea()
   {
    return -1.0; // Not done
   }

   public static void main (String arguments[])
   {
       // Put in some code to create some circles and print out
    // characteristics by calling the getXXX routines
   }


}




Last Updated: September 2, 2002 4:26 PM