public class Shapes { public final static double PI = 3.14159; // compute area of rectangle public int areaRec(int length, int width){ return length * width; } // compute area of square public int areaRec(int width){ return areaRec(width, width); } public void doRectangularShapes(){ // area of rectangle int area = areaRec(9,5); System.out.println("9 by 5 rectangle has area " + area); // area of square area = areaRec(12); System.out.println("square with width 12 has area " + area); } // compute area of ellipse public double areaEllipse(int major, int minor){ return major * minor * PI; } // compute area of circle public double areaEllipse(int radius){ return areaEllipse(radius, radius); } public void doOvalShapes(){ // area of ellipse 1 System.out.println("major 9 by minor 5 ellipse has area " + areaEllipse(9,5)); // area of circle System.out.println("circle with radius 12 has area " + areaEllipse(12)); } public static void main(String[] args) { // TODO compute area and volume of some shapes // THIS IS WHAT WE WANT: // 1. methods with clear meaning // 2. main is simple and high level Shapes shapes = new Shapes(); shapes.doRectangularShapes(); System.out.println(); shapes.doOvalShapes(); } }