这段代码为什么跑不起来?哪里有错误??万分感谢了。
public class Student
{
public static void main(String[] args)
{
List<studentclass> list = new ArrayList<studentclass>();
studentclass s1 = new studentclass();
studentclass s2 = new studentclass();
studentclass s3 = new studentclass();
s1.set("张三", 1, "男");
s1.set(90.5);
s2.set("李四", 2, "女");
s2.set(180.0);
s3.set("王五", 3, "男");
s3.set(68.0);
//排序
list.add(s1);
list.add(s2);
list.add(s3);
Collections.sort(list, new mysort());
for (studentclass s : list)
{
System.out.println(s.toString());
}
}
}
class studentclass
{
String name;
int code;
String sexy;
double mark;
public void set(String name,int code,String sexy)
{
this.name=name;
this.code=code;
this.sexy=sexy;
}
public void set(double mark)
{
this.mark=mark;
}
public String getname()
{
return name;
}
public int getcode()
{
return code;
}
public String getsexy()
{
return sexy;
}
public double getmark()
{
return mark;
}
public String toString()
{
String infor="姓名:"+name+" "+"学号:"+code+" "+"性别:"+sexy+" "+"成绩:"+mark;
return infor;
}
}
class mysort implements Comparator<studentclass>
{
public int compare(studentclass o1, studentclass o2)
{
//通过对应字段
return String.valueOf(o1.getmark()).compareTo(String.valueOf(o2.getmark()));
}
}
|