# 请教哪位大侠知道这个程序有什么东东，多谢

www.MyException.Cn  网友分享于：2013-02-08  浏览：5次

package edward;
public class Triangle{
double sideA,sideB,sideC;
boolean isTriangle;
public Triangle(double a,double b,double c){
if(a+b>c&&b+c>a&&a+c>b){
isTriangle=ture;
}
else{
isTriangle=flase;
}
public void 计算面积{
if(isTriangle){
double p=(sideA+sideB+sideC)/2.0;
double area=Math.sqrt(p*(p-sideA)*(p-sideB)*(p-sideC));
System.out.println("是一个三角形,面积为:"+area);
}
else{
System.out.println("不是一个三角形,不能计算面积");
}
public void 修整三边(double a,double b,double c){
sideA=a;
sideB=b;
sideC=c;
if(a+b>c&&a+c>b&&b+c>a){
isTriangle=ture;
}
else{
isTriangle=flase;
}
}
}

import edward.Triangle;
public class Example4_14{
public static void main(String args[]){
Triangle tri=new Triangle(3,4,5);
tri.计算面积();
tri.修整三边(4,5,6);
tri.计算面积();
}
}

------解决方案--------------------

------解决方案--------------------

------解决方案--------------------
public class Triangle {
double sideA, sideB, sideC;
boolean isTriangle;

public Triangle(double a, double b, double c) {
this.sideA = a;
this.sideB = b;
this.sideC = c;
if (a + b > c && b + c > a && a + c > b) {
isTriangle = true;
} else {
isTriangle = false;
}
}

public void 修整三边(double a, double b, double c) {
sideA = a;
sideB = b;
sideC = c;
if (a + b > c && a + c > b && b + c > a) {
isTriangle = true;
} else {
isTriangle = false;
}
}

public void 计算面积() {
if (isTriangle) {
double p = (sideA + sideB + sideC) / 2.0;
double area = Math
.sqrt(p * (p - sideA) * (p - sideB) * (p - sideC));
System.out.println("是一个三角形,面积为:" + area);
} else {
System.out.println("不是一个三角形,不能计算面积");
}
}
}