interface Shape {
    public double computeArea();
    public double computeCircumference();
}
class Circle implements Shape {
    private double radius = 0.0;
    private double circleArea = 0.0;
    private double circumference = 0.0;
    
    public Circle( double radius ) {
        this.radius = radius;
        circleArea = radius * radius * Math.PI;
        circumference = 2 * Math.PI * radius;
    }
    public double getCircleArea() {
        return circleArea;
    }
    
    public double getCircleCircumference() {
        return circumference;
    }
    
    public double computeArea() {
        circleArea = getCircleArea();
        return circleArea;
    }
    
    public double computeCircumference() {
        circumference = getCircleCircumference();
        return circumference;
    }
}
class Rectangle implements Shape {
    private double wide = 0.0;
    private double length = 0.0;
    private double rectangleArea = 0.0;
    private double circumference  = 0.0;
    
    public Rectangle( double wide , double length ) {
        this.wide = wide;
        this.length = length;
        rectangleArea = wide * length;
        circumference = 2 * ( length + wide );
    }
    
    public double getRectangleArea() {
        return rectangleArea;
    }
    
    public double getRectangleCircumference() {
        return circumference;
    }
    public double computeArea() {
        rectangleArea = getRectangleArea();
        return rectangleArea;
    }
    public double computeCircumference() {
        circumference = getRectangleCircumference();
        return circumference;
    }
}

public class main1 {
    public static void main(String[] args) {
        double rectanglearea = 0.0;
        double recCircumference = 0.0;
        double circlearea = 0.0;
        double cirCircumference = 0.0;
        
        Circle circle1 = new Circle(12);
        Rectangle rectangle1 = new Rectangle(10,10);
        circlearea = circle1.computeArea();
        rectanglearea = rectangle1.computeArea();
        cirCircumference = circle1.computeCircumference();
        recCircumference = rectangle1.computeCircumference();
        System.out.println("Rectangle 's circumference is : " + recCircumference);
        System.out.println("Rectangle 's area is : " + rectanglearea);
        System.out.println("Circle 's circumference is : " + cirCircumference);
        System.out.println("Circle 's area is : " + circlearea);
    }
}

全站熱搜

Walter Blyss 發表在 痞客邦 留言(0) 人氣()