自己动动手coding,数学原理主要是海伦公式(根据3边求面积)
public class Triangle {
//三边的长度
public Double a;
public Double b;
public Double c;
public Double getA() {
return a;
}
public void setA(Double a) {
this.a = a;
}
public Double getB() {
return b;
}
public void setB(Double b) {
this.b = b;
}
public Double getC() {
return c;
}
public void setC(Double c) {
this.c = c;
}
public Triangle(Double a,Double b,Double c){
this.a = a;
this.b = b;
this.c = c;
}
/**
* 得到周长
* @return
*/
public Double getPerimeter(){
Double l = 0d;
l = a+b+c;
return l;
};
/**
* 得到面积
* @return
*/
public Double getArea(){
Double s = 0d;
Double p = getPerimeter()/2;
s = Math.sqrt(p*(p-a)*(p-b)*(p-c));
return s;
}
}
自己写测试方法就可以了。