JAVA上机实验求圆的面积和周长 第2页

package fox.math.kmust;

 

import java.util.logging.Logger;

 

/**

 * @file Shape.java

 */

public abstract class Shape {

    public abstract double area();

 

    public abstract double perimeter();

 

    public final String message() {

       Logger logger = Logger.getLogger("INFO");

       logger.info("Message()");

       return toString();

    }

}

 

package fox.math.kmust;

 

/**

 * @file Graph.java

 */

public interface Graph {

    public void draw();

}

 

package fox.math.kmust;

 

import java.util.logging.Logger;

 

/**

 * @file Circle.java

 */

public final class Circle extends Shape implements Graph {

 

    private double radius = 0.0;

 

    @Override

    public double area() {

       return Math.PI * radius * radius;

    }

 

    @Override

    public double perimeter() {

       return 2 * Math.PI * radius;

    }

 

    @Override

    public void draw() {

       Logger logger = Logger.getLogger("INFO");

       logger.info("draw()");

       System.out.println(message());

    }

 

    public double getRadius() {

       return radius;

    }

 

    public void setRadius(double radius) {

       this.radius = radius;

    }

 

    @Override

    public String toString() {

       return "My real Class is:" + Circle.class.getName() + "\nMy radius is:"

              + radius + "\nMy area is:" + area() + "\nMy perimeter is:"

              + perimeter();

    }

 

    public Circle(double radius) {

       this.radius = radius;

    }

 

    public Circle() {

       this(2.0);

    }

}

 

package fox.math.kmust;

 

import java.util.logging.Logger;

 

/**

 * @file Graph.java

 */

public class Rectangle extends Shape implements Graph {

 

    private double length = 0.0;

 

    private double width = 0.0;

 

    public Rectangle() {

       this(2.0, 2.0);

    }

上一页  [1] [2] [3] [4] [5] 下一页

Copyright © 2007-2012 www.chuibin.com 六维论文网 版权所有