A股上市公司传智教育(股票代码 003032)旗下技术交流社区北京昌平校区

 找回密码
 加入黑马

QQ登录

只需一步,快速开始

© 李涛兴 中级黑马   /  2012-11-19 21:53  /  1493 人查看  /  6 人回复  /   0 人收藏 转载请遵从CC协议 禁止商业使用本文

本帖最后由 李涛兴 于 2012-11-19 22:11 编辑
  1. class  StudentTreeSet
  2. {
  3.         public static void main(String[] args)
  4.         {
  5.                 TreeSet ts=new TreeSet();
  6.                 ts.add(new Student("zhangsan",19,85));
  7.                 ts.add(new Student("lisi",19,95));
  8.                 ts.add(new Student("wangwu",20,83));
  9.                 ts.add(new Student("tom",21,90));
  10.                 ts.add(new Student("davil",18,80));
  11.                 Iterator it=ts.iterator();
  12.                 while(it.hasNext())
  13.                 {
  14.                         Student stu=(Student)it.next();
  15.                         System.out.println(stu.getName()+"  "+stu.getAge()+"  "+stu.getFens());
  16.                 }
  17.         }
  18. }


  19. class Student implements Comparable
  20. {
  21.         private String name;
  22.         private int age;
  23.         private double fens;
  24.         Student(String name,int age,double fens)
  25.         {
  26.                 this.name=name;
  27.                 this.age=age;
  28.                 this.fens=fens;
  29.         }
  30.         public int compareTo(Object obj)
  31.         {
  32.                 if(!(obj instanceof Student))
  33.                  throw new RuntimeException("不是一个类");
  34.                 Student s=(Student)obj;
  35.                 //System.out.println(this.fens+"...."s.fens);
  36.                 if(this.fens>s.fens)
  37.                         return 1;
  38.                 if(this.fens==s.fens)
  39.                 {
  40.                          int num=this.name.compareTo(s.name);
  41.                          return num;
  42.                 }
  43.                         return -1;
  44.         }
  45.         
  46.         
  47.         public String getName()
  48.         {
  49.                 return name;
  50.         }
  51.         
  52.         public int getAge()
  53.         {
  54.                 return age;
  55.         }
  56.         public double getFens()
  57.         {
  58.                 return fens;
  59.         }
  60.         
  61.         
  62. }
复制代码
StudentTreeSet.java:6: 错误: 找不到符号
                TreeSet ts=new TreeSet();
                ^
  符号:   类 TreeSet
  位置: 类 StudentTreeSet
StudentTreeSet.java:6: 错误: 找不到符号
                TreeSet ts=new TreeSet();
                               ^
  符号:   类 TreeSet
  位置: 类 StudentTreeSet
StudentTreeSet.java:12: 错误: 找不到符号
                Iterator it=ts.Iterator();
                ^
  符号:   类 Iterator
  位置: 类 StudentTreeSet
3 个错误
有同学知道这是错在哪里了吗?上午看这个题目的视频,不懂就照抄了下来,现在想加个属性进去运行下,结果就出现了这些错误,
求高人指点下。

评分

参与人数 1技术分 +1 收起 理由
古银平 + 1 神马都是浮云

查看全部评分

6 个回复

倒序浏览
  1. import java.util.*;

  2. class  StudentTreeSet
  3. {
  4.         public static void main(String[] args)
  5.         {
  6.                 TreeSet ts=new TreeSet();
  7.                 ts.add(new Student("zhangsan",19,85));
  8.                 ts.add(new Student("lisi",19,95));
  9.                 ts.add(new Student("wangwu",20,83));
  10.                 ts.add(new Student("tom",21,90));
  11.                 ts.add(new Student("davil",18,80));
  12.                 Iterator it=ts.iterator();//大小写错误
  13.                 while(it.hasNext())//是hasNext()
  14.                 {
  15.                         Student stu=(Student)it.next();
  16.                         System.out.println(stu.getName()+"  "+stu.getAge()+"  "+stu.getFens());
  17.                 }
  18.         }
  19. }


  20. class Student implements Comparable
  21. {
  22.         private String name;
  23.         private int age;
  24.         private double fens;
  25.         Student(String name,int age,double fens)
  26.         {
  27.                 this.name=name;
  28.                 this.age=age;
  29.                 this.fens=fens;
  30.         }
  31.         public int compareTo(Object obj)
  32.         {
  33.                 if(!(obj instanceof Student))
  34.                  throw new RuntimeException("不是一个类");
  35.                 Student s=(Student)obj;
  36.                 //System.out.println(this.fens+"...."s.fens);
  37.                 if(this.fens>s.fens)
  38.                         return 1;
  39.                 if(this.fens==s.fens)
  40.                 {
  41.                          int num=this.name.compareTo(s.name);
  42.                          return num;
  43.                 }
  44.                         return -1;
  45.         }
  46.         
  47.         
  48.         public String getName()
  49.         {
  50.                 return name;
  51.         }
  52.         
  53.         public int getAge()
  54.         {
  55.                 return age;
  56.         }
  57.         public double getFens()
  58.         {
  59.                 return fens;
  60.         }
  61.         
  62.         
  63. }
复制代码
回复 使用道具 举报
  1. import java.util.*;

  2. class  StudentTreeSet
  3. {
  4.         public static void main(String[] args)
  5.         {
  6.                 TreeSet ts=new TreeSet();
  7.                 ts.add(new Student("zhangsan",19,85));
  8.                 ts.add(new Student("lisi",19,95));
  9.                 ts.add(new Student("wangwu",20,83));
  10.                 ts.add(new Student("tom",21,90));
  11.                 ts.add(new Student("davil",18,80));
  12.                 Iterator it=ts.iterator();//大小写错误
  13.                 while(it.hasNext())//是hasNext()
  14.                 {
  15.                         Student stu=(Student)it.next();
  16.                         System.out.println(stu.getName()+"  "+stu.getAge()+"  "+stu.getFens());
  17.                 }
  18.         }
  19. }


  20. class Student implements Comparable
  21. {
  22.         private String name;
  23.         private int age;
  24.         private double fens;
  25.         Student(String name,int age,double fens)
  26.         {
  27.                 this.name=name;
  28.                 this.age=age;
  29.                 this.fens=fens;
  30.         }
  31.         public int compareTo(Object obj)
  32.         {
  33.                 if(!(obj instanceof Student))
  34.                  throw new RuntimeException("不是一个类");
  35.                 Student s=(Student)obj;
  36.                 //System.out.println(this.fens+"...."s.fens);
  37.                 if(this.fens>s.fens)
  38.                         return 1;
  39.                 if(this.fens==s.fens)
  40.                 {
  41.                          int num=this.name.compareTo(s.name);
  42.                          return num;
  43.                 }
  44.                         return -1;
  45.         }
  46.         
  47.         
  48.         public String getName()
  49.         {
  50.                 return name;
  51.         }
  52.         
  53.         public int getAge()
  54.         {
  55.                 return age;
  56.         }
  57.         public double getFens()
  58.         {
  59.                 return fens;
  60.         }
  61.         
  62.         
  63. }
复制代码
楼主你和我们开什么玩笑,几个输入错误而已!要记得导包!

评分

参与人数 1技术分 +1 收起 理由
古银平 + 1 赞一个!

查看全部评分

回复 使用道具 举报
奚华 发表于 2012-11-19 22:02
楼主你和我们开什么玩笑,几个输入错误而已!要记得导包!

谢了哥们,一直是在看视频,实践的少。
回复 使用道具 举报
呵呵,共同努力!!!黑马我们来了!!!
回复 使用道具 举报
你的这些错误都有一个特征就是你导入包了吗?,先导入包。在看接下来的错误
回复 使用道具 举报
你导入  import java.util.*;这个包就可以。编译就不会出现错误提示了。
回复 使用道具 举报
您需要登录后才可以回帖 登录 | 加入黑马