• 手机版

    扫码体验手机版

  • 微信公众号

    扫码关注公众号

国内首家协议开发

软芯音视解码保护平台

在线
客服

发布
需求

在线
聊天

天盟
APP

天盟APP下载

关注
微信

微信扫一扫访问
顶部

代码运行结果显示最后的几个函数体未定义:trangle() is undefined,要怎么

class Trangle{
double sideA,sideB,sideC,area,length;
boolean boo;
public Trangle(double a,double b,double c)
{
  
   this.sideA=a;
         this.sideB=b;
         this.sideC=c;
   
if(this.sideA+this.sideB>this.sideC&&this.sideA+this.sideC>this.sideB&&this.sideB+this.sideC>this.sideA)
{
  this.boo=true;
  
}
else
{
  this.boo=false;
  
}
return boo;

}
public double getLength(){
  if(this.sideA+this.sideB>this.sideC&&this.sideA+this.sideC>this.sideB&&this.sideB+this.sideC>this.sideA)
  {
   double p=(sideA+sideB+sideC)/2.0;
   area=Math.sqrt(p*(p-sideA)*(p-sideB)*(p-sideC));
   return area;
   
  }
  else
  {
   System.out.println("不是一个三角形,不能计算面积");
   return 0;
  }
  
}
public void setABC(double a,double b,double c)
{
this.sideA=a;
    this.sideB=b;
    this.sideC=c;
    if(this.sideA+this.sideB>this.sideC&&this.sideA+this.sideC>this.sideB&&this.sideB+this.sideC>this.sideA)
    {
     this.boo=true;
    }
    else
    {
     this.boo=false;
    }
  
  }
}
class Lader{
double above,bottom,height,area;
Lader(double a,double b,double h)
{
  this.above=a;
  this.bottom=b;
  this.height=h;
  
}
public double getArea(){
  this.area=(this.above+this.bottom)*this.height/2;
  return this.area;
}

}

public class AreaAndLength {
public static void main(String[] args)
{
double length,area;
Trangle trangle=null;
Lader lader;
trangle=new Trangle();
lader=new Lader();
length=trangle.getLength();
System.out.println("三角形的周长:"+length);
area=trangle.getArea();
System.out.println("三角形的面积:"+area);
area=lader.getArea();
System.out.println("梯形的面积:"+area);
trangle.setABC(12,34,1);
area=trangle.getArea();
System.out.println("三角形的面积:"+area);
length=trangle.getLength();
System.out.println("三角形的周长:"+length);
}
}class Trangle{
double sideA,sideB,sideC,area,length;
boolean boo;
public Trangle(double a,double b,double c)
{
  
   this.sideA=a;
         this.sideB=b;
         this.sideC=c;
   
if(this.sideA+this.sideB>this.sideC&&this.sideA+this.sideC>this.sideB&&this.sideB+this.sideC>this.sideA)
{
  this.boo=true;
  
}
else
{
  this.boo=false;
  
}
return boo;

}
public double getLength(){
  if(this.sideA+this.sideB>this.sideC&&this.sideA+this.sideC>this.sideB&&this.sideB+this.sideC>this.sideA)
  {
   double p=(sideA+sideB+sideC)/2.0;
   area=Math.sqrt(p*(p-sideA)*(p-sideB)*(p-sideC));
   return area;
   
  }
  else
  {
   System.out.println("不是一个三角形,不能计算面积");
   return 0;
  }
  
}
public void setABC(double a,double b,double c)
{
this.sideA=a;
    this.sideB=b;
    this.sideC=c;
    if(this.sideA+this.sideB>this.sideC&&this.sideA+this.sideC>this.sideB&&this.sideB+this.sideC>this.sideA)
    {
     this.boo=true;
    }
    else
    {
     this.boo=false;
    }
  
  }
}
class Lader{
double above,bottom,height,area;
Lader(double a,double b,double h)
{
  this.above=a;
  this.bottom=b;
  this.height=h;
  
}
public double getArea(){
  this.area=(this.above+this.bottom)*this.height/2;
  return this.area;
}

}

public class AreaAndLength {
public static void main(String[] args)
{
double length,area;
Trangle trangle=null;
Lader lader;
trangle=new Trangle();
lader=new Lader();
length=trangle.getLength();
System.out.println("三角形的周长:"+length);
area=trangle.getArea();
System.out.println("三角形的面积:"+area);
area=lader.getArea();
System.out.println("梯形的面积:"+area);
trangle.setABC(12,34,1);
area=trangle.getArea();
System.out.println("三角形的面积:"+area);
length=trangle.getLength();
System.out.println("三角形的周长:"+length);
}
}

免责声明:本内容仅代表回答会员见解不代表天盟观点,请谨慎对待。

版权声明:作者保留权利,不代表天盟立场。

使用道具 举报

全部参与1

查看编译器的报错提示 查找代码的错误
Trangle和Lader两个类中有构造方法 需要传入参数才可以:

trangle=new Trangle(1.0,2.0,3.0);
lader=new Lader(1.0,2.0,3.0);
getArea你定义在Lader类中了 但却在trangle对象上调用的 当然找不到

使用道具 举报

发新帖

发布任务需求已有1031167位用户正在使用天盟网服务

发布分类: *
任务预算: *
需求内容: *
手机号码: *
任务商家报价为
  • 预算价 :
  • 成交价 :
  • 完工期 :
  • 质保期 :

* 最终任务项目以服务商报价、双方协商为准!