You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

47 lines
942 B

package Shape;
abstract public class Shape {
abstract double getArea();
}
class Circle extends Shape{
private double r;
public Circle(double r){
this.r=r;
}
@Override
double getArea(){
return Math.PI*r*r;
}
}
class Rectangle extends Shape{
private double chang;
private double kuan;
public Rectangle(double chang,double kuan){
this.chang=chang;
this.kuan=kuan;
}
@Override
double getArea(){
return chang*kuan;
}
}
class Triangle extends Shape{
private double di;
private double height;
public Triangle(double di,double height){
this.di=di;
this.height=height;
}
@Override
double getArea(){
return 0.5*di*height;
}
}
class ShapeUtil{
public static void printArea(Shape shape){
System.out.println("面积是"+shape.getArea());
}
}