学生成绩的录入排列
2013-12-02 16:28
190 查看
1. 学生类(学生编号、学生名、班级、成绩、年龄)
实现比较接口
输入5个学生的信息,
使用Arrays.sort()将这个5个学生按学生成绩从低到高排列
学生比较规则
:
1、成绩比较
|_成绩相等比较学号(学号越小就越排前面)
import java.util.Arrays;
public class Test {
public static void main(String[] args) {
Student []array= new Student[]{
new Student(1,"小王","二年级",56,5),
new Student(2,"小李","二年级",57,5),
new Student(3,"小张","二年级",76,5),
new Student(4,"小孙","二年级",47,5)
};
Arrays.sort(array);
for (int i = 0; i < array.length; i++) {
System.out.println(array[i]);
}
}
}
import java.util.Arrays;
public class Student implements Comparable {
public int id;
public String name;
public String grade;
public double score;
public int age;
public Student(int id, String name, String grade, double score, int age) {
super();
this.id = id;
this.name = name;
this.grade = grade;
this.score = score;
this.age = age;
}
@Override
public int compareTo(Object o) {
Student student=(Student)o;
if(this.score>student.score){
return 1;
}
else{ if(this.score
return -1;
}
else if(this.id
return 1;
}
else if(this.id
return -1;
}
return 0;
}
}
public String toString (){
String str=this.id+" "+this.name+" "+this.score+" "+this.grade+" "+this.age;
return str;
}
}
实现比较接口
输入5个学生的信息,
使用Arrays.sort()将这个5个学生按学生成绩从低到高排列
学生比较规则
:
1、成绩比较
|_成绩相等比较学号(学号越小就越排前面)
import java.util.Arrays;
public class Test {
public static void main(String[] args) {
Student []array= new Student[]{
new Student(1,"小王","二年级",56,5),
new Student(2,"小李","二年级",57,5),
new Student(3,"小张","二年级",76,5),
new Student(4,"小孙","二年级",47,5)
};
Arrays.sort(array);
for (int i = 0; i < array.length; i++) {
System.out.println(array[i]);
}
}
}
import java.util.Arrays;
public class Student implements Comparable {
public int id;
public String name;
public String grade;
public double score;
public int age;
public Student(int id, String name, String grade, double score, int age) {
super();
this.id = id;
this.name = name;
this.grade = grade;
this.score = score;
this.age = age;
}
@Override
public int compareTo(Object o) {
Student student=(Student)o;
if(this.score>student.score){
return 1;
}
else{ if(this.score
return -1;
}
else if(this.id
return 1;
}
else if(this.id
return -1;
}
return 0;
}
}
public String toString (){
String str=this.id+" "+this.name+" "+this.score+" "+this.grade+" "+this.age;
return str;
}
}
相关文章推荐
- 键盘录入多名学生的信息: 格式:姓名,数学成绩,语文成绩,英文成绩,按总分由高到低 将学生的信息进行排列到文件里
- 键盘录入多名学生的信息: 格式:姓名,数学成绩,语文成绩,英文成绩,按总分由高到低 将学生的信息进行排列到文件中
- Java:学生成绩录入(for语句)
- 学生成绩录入
- 学生成绩录入数据库练手题(转)
- 学生成绩录入系统设计与实现
- 按学生成绩进行升序排列
- 综合排序 学生信息输入并排序 键盘录入信息 (姓名,语文成绩,数学成绩,英语成绩),按总分高到低输出
- 用链表写的学生管理系统 成绩的录入与查询都已经是实现了
- 用字典实现学生信息的录入及按成绩排序输出
- 学生成绩录入系统设计与实现
- 按学生成绩进行升序排列
- 键盘录入5个学生信息(姓名,语文成绩,数学成绩,英语成绩),按照总分从高到低输出到控制台
- 录入学生成绩并写出到磁盘文件
- 从键盘输入10个学生的姓名和成绩,按字典序排列学生的姓名并输出(姓名和成绩对应关系保持不变)
- 作业6-学生成绩录入
- 作业6 :团队作业——学生成绩录入系统设计与实现(1)
- 按学生成绩进行升序排列
- 用链表写的学生管理系统 成绩的录入与查询都已经是实现了
- 输入学生个数,学生姓名和他们的成绩,然后按照学生成绩降序排列