This week's book giveaway is in the OCAJP 8 forum. We're giving away four copies of OCA Java SE 8 Programmer I Study Guide and have Edward Finegan & Robert Liguori on-line! See this thread for details.

ok im supposed to design an abstract class called Shape. It's methods are area and circumference. Then i have 3 child classes called circle, rectangle, and square....their methods are how they specifically calculate area and circumference...then i have a main driver class called ShapeAnalyzer that exercises these behaviors...however i don't think i wrote my classes correctly....can someone tell me what i did wrong..my rectangle class is the only one thats producing the correct output..here is my code's....

public abstract class Shapes ///this is my abstract class { protected double area, circumference;

public double getArea() { return area; } public double getCircumference() { return circumference; } } public class Circle extends Shapes //this is my circle child class { protected double radius;

public Circle(int radius) { } public double getArea() { area = Math.PI*Math.pow(radius,2); return area; } public double getCircumference() { circumference = 2*Math.PI*radius; return circumference; } } public class Rectangle extends Shapes //this is the only producing correct output { protected double w,h; public Rectangle(double w,double h) { this.w=w; this.h=h; } public double getWidth() { return w; } public double getHeight() { return h; } public double getArea() { area = w*h; return area;

} public double getCircumference() { circumference = 2*(w+h); return circumference;

} } public class Square extends Shapes //this is the square child class { protected int s;

public Square(int s) { } public double getArea() { return s*s; } public double getCircumference() { return 4*s; } public double getSide() { return s; } } public class ShapeAnalyzer //main driver class to exercise the behaviors { public static void main(String[] args) { Circle myCircle = new Circle(4); Square mySquare = new Square(6); Rectangle myRectangle = new Rectangle(10, 5);

System.out.println("The Circle's area is: " + myCircle.getArea()); System.out.println("The Circles circumference is: " + myCircle.getCircumference()); System.out.println("The Square's area is: " + mySquare.getArea()); System.out.println("The Square's circumference is: " + mySquare.getCircumference()); System.out.println("The Rectangle's area is: " + myRectangle.getArea()); System.out.println("The Rectangle's circumference is: " + myRectangle.getCircumference()); } }

Also, at least for "version one" I would try to keep code as simple as possible. You are caching the values for the circumference and area in your base class, but not consistently:

You can simplify this be getting rid of variables area and circumference. Then Shapes could even be an interface, because it has no code or data.