| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 5424 人关注过本帖
标题:cannot find symbol
只看楼主 加入收藏
Annie5
Rank: 1
等 级:新手上路
帖 子:9
专家分:5
注 册:2010-10-22
结帖率:100%
收藏
已结贴  问题点数:20 回复次数:12 
cannot find symbol
写有三角类如下代码:

class triangle {
    double a;
    double b;
    double c;
    public triangle(double a ,double b,double c){
        if((a+b>c)&&(a+c>b)&&(b+c>a)&&(a-c<b)&&(a-b<c)&&(b-c<a)){
        
            this.a=a;
            this.b=b;
            this.c=c;
        }
        else {
            System.out.println("输入边长有错");
            }
        
        }
    public double GetCircle(){
        return (a+b+c);
        }
    public double GetArea(){
        double p;
        p=(a+b+c)/2.0;
        return (Math.sqrt(p*(p-a)*(p-b)*(p-c)));
        }
    }
class Tprism extends triangle{
    double height;
        public Tprism (double a ,double b,double c,double height){
        if((a+b>c)&&(a+c>b)&&(b+c>a)&&(a-c<b)&&(a-b<c)&&(b-c<a)){
        
            this.a=a;
            this.b=b;
            this.c=c;
            this.height=height;
        }
        else {
            System.out.println("输入边长有错");
            }
        
        }
        
        
   
    }
   


class exp1{
  public static void main(String [] args){

    triangle r = new triangle(3.0,4.0,5.0);
     Tprism c=new Tprism(3.0,4.0,5.0,6.0);
    System.out.println("三角形的周长" + r.GetCircle());
    System.out.println("三角形的面积"+r.GetArea());
    System.out.println("三棱柱的底面积"+c.GetCircle());
    System.out.println("三棱柱的底周长"+c.GetArea());
    System.out.println("三棱柱的体积"+c.GetArea()*c.height);
  }
}


但是编译如下:
--------------------Configuration: question1 - JDK version 1.5.0_02 <Default>--------------------
E:\question1\exp1.java:29: cannot find symbol
symbol  : constructor triangle()
location: class triangle
        public Tprism (double a ,double b,double c,double height){
                                                                         ^
1 error

Process completed.
求正解,请赐教
搜索更多相关主题的帖子: symbol cannot find 
2010-10-22 17:19
legend817
Rank: 2
等 级:论坛游民
帖 子:23
专家分:51
注 册:2010-9-1
收藏
得分:15 
class Tprism extends triangle{
    double height;
        public Tprism (double a ,double b,double c,double height){
            super(a,b,c);
        if((a+b>c)&&(a+c>b)&&(b+c>a)&&(a-c<b)&&(a-b<c)&&(b-c<a)){
        
            this.a=a;
            this.b=b;
            this.c=c;
            this.height=height;
        }
        else {
            System.out.println("输入边长有错");
            }
        
        }
        
        
   
    }
   


public class exp1{
  public static void main(String [] args){

    triangle r = new triangle(3.0,4.0,5.0);
     Tprism c=new Tprism(3.0,4.0,5.0,6.0);
    System.out.println("三角形的周长" + r.GetCircle());
    System.out.println("三角形的面积"+r.GetArea());
    System.out.println("三棱柱的底面积"+c.GetCircle());
    System.out.println("三棱柱的底周长"+c.GetArea());
    System.out.println("三棱柱的体积"+c.GetArea()*c.height);
  }
}



   
修改以上几点就行了。。。
2010-10-22 21:52
爱心流沙
Rank: 1
等 级:新手上路
帖 子:10
专家分:7
注 册:2010-10-20
收藏
得分:5 
要用super调用父类的变量
2010-10-22 22:21
Annie5
Rank: 1
等 级:新手上路
帖 子:9
专家分:5
注 册:2010-10-22
收藏
得分:0 
回复 2楼 legend817
谢谢 正解
不过 还要请教一下 下面那个代码为何就不存在上述问题呢?请赐教
class rectangle{
  double width;
  double length;

  public rectangle(){
    width = 10;
    length = 10;
  }
  public rectangle(int width, int length){
    this.width = width;
    this.length = length;
  }
  public rectangle(double width, double length){
    this.width = width;
    this.length = length;
  }
  public double getCircle(){
    return 2*(width + length);
  }
  public double getArea(){
    return width * length;
  }
}
class cube extends rectangle{
  double height;
  public cube(){
    width = 10;
    length = 10;
    height = 10;
  }
  public cube(double width1, double length1, double height){
    width = width1;
    length = length1;
    this.height = height;
  }
  public double getVol(){
    return width * length * height;
  }
  public double getArea(){
    return 2*(width * length + width * height + length * height);
  }
}

class example{
  public static void main(String [] args){
    rectangle r = new rectangle(20, 20);
    cube c = new cube(11, 22, 33);
    System.out.println("矩形的面积" + r.getArea());
    System.out.println("长方体的体积" + c.getVol());
    System.out.println("长方体的面积" + c.getArea());
  }
}
2010-10-23 10:02
Annie5
Rank: 1
等 级:新手上路
帖 子:9
专家分:5
注 册:2010-10-22
收藏
得分:0 
回复 3楼 爱心流沙
谢谢
2010-10-23 10:02
legend817
Rank: 2
等 级:论坛游民
帖 子:23
专家分:51
注 册:2010-9-1
收藏
得分:0 
class example 改成public class example 就行了。。。。
2010-10-23 11:58
legend817
Rank: 2
等 级:论坛游民
帖 子:23
专家分:51
注 册:2010-9-1
收藏
得分:0 
子类构造函数要调用父类构造函数
上边的子类构造函数默认调用的是super()
也就是
 public rectangle(){
    width = 10;
    length = 10;
  }
2010-10-23 13:09
Annie5
Rank: 1
等 级:新手上路
帖 子:9
专家分:5
注 册:2010-10-22
收藏
得分:0 
回复 7楼 legend817
又学到了些东西哦,谢谢赐教
2010-10-23 14:06
legend817
Rank: 2
等 级:论坛游民
帖 子:23
专家分:51
注 册:2010-9-1
收藏
得分:0 
回复 8楼 Annie5
呵呵,不客气,共同学习。。。。。
2010-10-23 16:55
Annie5
Rank: 1
等 级:新手上路
帖 子:9
专家分:5
注 册:2010-10-22
收藏
得分:0 
class triangle {
    double a;
    double b;
    double c;
    public triangle(double a ,double b,double c){
        if((a+b>c)&&(a+c>b)&&(b+c>a)&&(a-c<b)&&(a-b<c)&&(b-c<a)){
        
            this.a=a;
            this.b=b;
            this.c=c;
        }
        else {
                    System.out.println("输入边长有错");
            }
        
        }
    public double GetCircle(){
        return (a+b+c);
        }
    public double GetArea(){
        double p;
        p=(a+b+c)/2.0;
        return (Math.sqrt(p*(p-a)*(p-b)*(p-c)));
        }
    }
class Tprism extends triangle{
    double height;
    public Tprism (double a ,double b,double c,double height){
           super(a,b,c);
        if((a+b>c)&&(a+c>b)&&(b+c>a)&&(a-c<b)&&(a-b<c)&&(b-c<a)){
        
            this.a=a;
            this.b=b;
            this.c=c;
            this.height=height;
        }
        else {
            System.out.println("输入边长有错");
            }
        
        }
        
            public double volume(){
            return (super.GetArea()*height);
            }
        
   
    }
   
class pramid extends rectangle{
   
        double height;
        public pramid(double a, double b, double c,double height){
            super(a,b,c);
                 if((a+b>c)&&(a+c>b)&&(b+c>a)&&(a-c<b)&&(a-b<c)&&(b-c<a)){
               
                    this.a=a;
                    this.b=b;
                    this.c=c;
                    this.height=height;
                }
                else {
                    System.out.println("输入边长有错");
                    }
               
                }
                    public  double volume(){
            return (super.GetArea()*height*(1/3));
            }
        
            }
   

class exp1{
  public static void main(String [] args){

    triangle r = new triangle(3.0,4.0,5.0);
     Tprism c=new Tprism(3.0,4.0,5.0,6.0);
     pramid d=new pramid(3.0,4.0,5.0,6.0);
    System.out.println("三角形的周长" + r.GetCircle());
    System.out.println("三角形的面积"+r.GetArea());
    System.out.println("三棱柱的底面积"+c.GetCircle());
    System.out.println("三棱柱的底周长"+c.GetArea());
    System.out.println("三棱柱的体积"+c.volume());
     System.out.println("三棱锥的底面积"+d.GetArea());
    System.out.println("三棱锥的体积"+d.volume());
  }
}

--------------------Configuration: hh - JDK version 1.5.0_02 <Default>--------------------
G:\java\hh\exp1.java:50: cannot find symbol
symbol: class rectangle
class pramid extends rectangle{
                     ^
G:\java\hh\exp1.java:57: cannot find symbol
symbol  : variable a
location: class pramid
                    this.a=a;
                            ^
G:\java\hh\exp1.java:58: cannot find symbol
symbol  : variable b
location: class pramid
                    this.b=b;
                            ^
G:\java\hh\exp1.java:59: cannot find symbol
symbol  : variable c
location: class pramid
                    this.c=c;
                            ^
G:\java\hh\exp1.java:68: cannot find symbol
symbol  : variable super
location: class pramid
            return (super.GetArea()*height*(1/3));
                                ^
G:\java\hh\exp1.java:85: cannot find symbol
symbol  : method GetArea()
location: class pramid
     System.out.println("三棱锥的底面积"+d.GetArea());
                                   ^
6 errors

Process completed.

那这个问题又出在哪呢?菜鸟级别,请大家指教
2010-10-24 11:30
快速回复:cannot find symbol
数据加载中...
 
   



关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.017900 second(s), 7 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved