国网入围电缆厂物资库:用Java编写学生录入信息的程序

来源:百度文库 编辑:查人人中国名人网 时间:2024/04/29 22:07:09

这里有一个类
实现学生学号,数学,语文,英语成绩录入
并且计算平均成绩,按照平均成绩高低输出信息
你可以改改!
//实现简单的学生信息输入输出和初步的成绩排序
public class Student {
private int id; //学号
private int mathScore; //数学成绩
private int chinScore; //语文成绩
private int foreScore; //外语成绩

public Student() {
id = 0;
mathScore = 0;
chinScore = 0;
foreScore = 0;
}

public Student(int newId, int newMathScore, int newChinSvore,
int newForeScore) {
id = newId;
mathScore = newMathScore;
chinScore = newChinSvore;
foreScore = newForeScore;
}

public double getAverageScore() { //求平均成绩
double averageScore = ((double) mathScore + chinScore + foreScore) / 3;
return averageScore;
}

public void output(Student student) { //输出对象的内容
System.out.println(" " + student.id + " " + student.mathScore +
" " + student.chinScore + " "
+ student.foreScore + " " +
student.getAverageScore());
}

public int max(Student a[], int n) { //Student类对象数组的前n项中的成绩最大值的索引
int position = 0;
for (int i = 1; i < n; i++) {
if (a[i].getAverageScore() > a[position].getAverageScore()) { //比较平均成绩
position = i;
}
}
return position;
}

public void selectSort(Student a[]) { //Student类对象数组的选择排序
for (int n = a.length; n > 1; n--) {
int i = max(a, n);
Student temp = a[i];
a[i] = a[n - 1];
a[n - 1] = temp;
}
}
}