编辑代码

class Main {
    public static viod main (String[] args){

        GeometricObject test = new GeometricObject();
        GeometricObject test1 = new GeometricObject("bule",tuer);

        GeometricObject cc = new Circle(5.0,"red",false);
        double ss = ((Circle)cc).getarea();
        System.out.println("矩形%"+ss);
        GeometricObject rc = new Rectangle(12.0,2.6,"white",ture);
    }
    public static void area(GeometricObject gg){
        double s;
        if (gg instanceof CirCle){
            s =((Circle)gg).getArea();
            System.out.println("圆面积%"+s);
        }else if ( gg instanceof Rectangle){
            s = ((Rectangle)gg).getArea();
            System.out.println("矩形%"+s);
        }
    }
}


class GeometricObject{
    private String color;
    private boolean filled;
    private Date dateCreated;

    public GeometricObject(){};
    public GeometricObject(String color, boolean filled){
        this.color = color;
        this.filled = filled;
    }
    public String getColor(){return this.color;}
    public void setColor(String color) { color = color; }
    public boolean isFilled(){return filled;}
    public void setFilled(boolean filled){

    }
    public Date getDateCreated(){ return this.dateCreated;}
    public String tostring (){return super.tostring();}

}
class Circle extends GeometricObject{
    private double radius;
    public Circle(){}
    public Circle(double radius,string color,boolean filled){
        super(color,filled);
        this.radius = radius;
    }
    public double getRadius(){
        return radius;
    }
    public void setRadius(double radius){
        this.radius = radius;
    }
    public double getArea(){
        return getRadius()*getRadius()*Math.PI;
}
class Rectangle extends GeometricObject{
    private double width;
    private double height;
    public Rectangle(){}
    public Rectangle(double width, double height){

    }
    public Rectangle(double width, double height, String color, boolean filled){
        super(color, filled);
        this.width = width;
        this.height = height;
    }
    public double getWidth(){
        return width;
    }
    public void setWidth(double width){
        this.width = width;
    }
    public void setHeight(double height){
        this.height = height;
    }
    public double getHeight(){
        return height;
    }
    public double getArea(){
        return getWidth()*getHeight();
    }
}