import javafx.scene.paint.Color; public abstract class Shape { private Color color; public Shape(Color color) { this.color = color; } public Color getColor() { return color; } public void setColor(Color color) { this.color = color; } public abstract double getArea(); } //---------------------------------------------------- import javafx.scene.paint.Color; public class Circle extends Shape { private double radius; public Circle(Color color, double radius) { super(color); this.radius = radius; } public double getRadius() { return radius; } public void setRadius(double radius) { this.radius = radius; } public double getArea() { return Math.PI * radius * radius; } public String toString() { return "I'm a circle of radius " + radius; } } //---------------------------------------------------- import javafx.scene.paint.Color; public class Rectangle extends Shape { private double length; private double width; public Rectangle(Color color, double length, double width) { super(color); this.length = length; this.width = width; } public double getArea() { return length * width; } } //---------------------------------------------------- import javafx.scene.paint.Color; public class Triangle extends Shape { private double height; private double base; public Triangle(Color color, double height, double base) { super(color); this.height = height; this.base = base; } public double getArea() { return 0.5 * height * base; } } //---------------------------------------------------- import javafx.scene.paint.Color; public class TestProgram { public static void main() { Color color = Color.RED; Circle c = new Circle(color,2); Triangle t = new Triangle(color,1,2); Rectangle r = new Rectangle(color,1,2); Shape[] shapes = new Shape[3]; shapes[0] = c; shapes[1] = t; shapes[2] = r; for (Shape shape : shapes) { System.out.println(shape.getClass().getName() + " Area: " + shape.getArea()); } //System.out.println(shapes[0].getClass().getName()); //System.out.println(shapes[0].getClass().getCanonicalName()); //System.out.println(shapes[0].getClass().getTypeName()); } }