import java.util.*;
class Student
{
private String name;
private int age;
private double fen;
Student (String name,int age,double fen)
{
this.name=name;this.age=age;this.fen=fen;
wrint();
}
public void setName(String name)
{
this.name=name;
}
public void setAge(int age)
{
this.age=age;
}
public void setFen(double fen)
{
this.fen=fen;
}
public String getName()
{
return name;
}
public int getAge()
{
return age;
}
public double getFen()
{
return fen;
}
public void wrint()
{
//System.out.println("name="+this.name+", age="+this.age+", fen="+this.fen);
}
}
class Student1
{
public static void main(String[] args)
{
TreeSet ts=new TreeSet(new MyCompare());
ts.add(new Student("wangwu",20,78));
ts.add(new Student("zhangsan",20,98));
ts.add(new Student("lisi",20,80));
ts.add(new Student("zhaoliu",20,60));
ts.add(new Student("zhuqi",20,65 ));
Iterator it=ts.iterator();
while (it.hasNext())
{
Student stu=(Student)it.next();
System.out.println(stu.getName()+" ... "+stu.getAge()+"..."+stu.getFen());
}
}
}
class MyCompare implements Comparator
{
public int compare(Object o1,Object o2)
{
Student s1=(Student)o1;
Student s2=(Student)o2;
int= s1.getFen().compareTo(s2.getFen());//这里不是返回1.0.-1.的吗怎么double类型的不行了呢
if (num==0)
{
if (s1.getAge()>s2.getAge())
return 1;
if (s1.getAge()==s2.getAge())
return 0;
return -1;
}
return num;
}
}
代码出现错误,求指点
Noname1.java:73: 无法取消引用 double
return s1.getFen().compareTo(s2.getFen());
^
注意:Noname1.java 使用了未经检查或不安全的操作。
注意:要了解详细信息,请使用 -Xlint:unchecked 重新编译。
1 错误
|