abstract class Shape{
public abstract double getS();
public abstract double getC();
}
class Trangle extends Shape{
double a;
double b;
double c;
public void setSide(double a,double b,double c){
this.a=a;
this.b=b;
this.c=c;
}
public boolean YN(){
if(a+b>c&&a+c>b&&b+c>a)
{
return true;
}
else
{
return false;
}
}
public double getS(){
return Math.sqrt(((a+b+c)/2)*(((a+b+c)/2)-a)*(((a+b+c)/2)-b)*(((a+b+c)/2)-c));
}
public double getC(){
return a+b+c;
}
}
class Tectangle extends Shape{
double x;
double y;
public Tectangle(double x,double y){
this.x=x;
this.y=y;
}
public double getS(){
return x*y;
}
public double getC(){
return (x+y)*2;
}
}
class test{
public static void main(String[] args){
Trangle aa=new Trangle(3,4,5);
boolean YN();
if(YN=true)
{
System.out.println("这三条边可以构成三角形");
System.out.println("三角形的面积为"+aa.getS());
System.out.println("三角形的周长为"+aa.getC());
}
else
{
System.out.println("这三条边不能构成三角形");
}
}
请问怎么修改??? |
|