11.1Trianfle
public class GeometricObject { private String color=\ private boolean filled=false; public GeometricObject(){ }
public GeometricObject(String color,boolean filled){ this.color=color; this.filled=filled; }
public boolean isFilled(){
if (this.color != null) filled=true; return filled; }
public void setColor(String color) { this.color = color; }
public String toString() { isFilled();
return \颜色及是否填充{\ \ \ '}'; } }
public class Triangle extends GeometricObject { double side1; double side2; double side3; public Triangle(){ side1=1; side2=1; side3=1; }
public Triangle(double side1,double side2,double side3){ this.side1=side1; this.side2=side2; this.side3=side3; }
public double getSide1() { return side1; }
public double getSide2() { return side2; }
public double getSide3() { return side3; }
public double getPerimeter(){ return side1+side2+side3; }
public double getArea(){
double a=getPerimeter()/2;
double b=a*(a-side1)*(a-side2)*(a-side3); return Math.pow(b,0.5); }
public String toString() { return \三边为{\
\ \ \ \ } }
public class Test {
public static void main(String[] args) {
Triangle triangle=new Triangle(3,4,5); triangle.setColor(\
System.out.println(\面积为\
System.out.println(\周长为\ System.out.println(triangle.toString());
} }