日期:2014-05-20 浏览次数:20925 次
import java.util.*;
 abstract class Figure
{
    protected String shape;
    protected Figure(String shape)
    {
        this.shape = shape;
    }
    protected Figure()
    {
        this("未知");
    }
    public abstract double area();
    public abstract double perimeter();
    public void print()
    {
        System.out.println("一个" + this.shape + "," + this.toString() + ",周长为"
                + this.perimeter() + ",面积为" + this.area());
    }
}
class Triangle extends Figure
{
    protected double a;
    protected double b;
    protected double c;
    public Triangle(double a, double b, double c)
    {
        super("三角形");
        this.a = a;
        this.b = b;
        this.c = c;
    }
    public Triangle()
    {
        this(0, 0, 0);
    }
    public String toString()
    {
        return "a边长" + this.a + ",b边长" + this.b + ",c边长" + this.c;
    }
    public double area()
    {
        return (Math.sqrt((a + b + c) / 2.0) * (((a + b + c) / 2.0) - a)
                * (((a + b + c) / 2.0) - b) * (((a + b + c) / 2.0) - c));
    }
    public double perimeter()
    {
        return (a + b + c);
    }
}