用JAVA编写一个程序实现简单的学生成绩管理,每个学生包括5门课程的成绩,从键盘输入学生信息。学生信息包括学号、姓名、五门课程成绩(语文、数学、外语、物理、化学),计算出每个学生的平均成绩,按照学生平均成绩排序(从高到低排序),输出显示。并输出每门课程所有学生的成绩单。
时间: 2023-12-16 12:24:58 浏览: 108
好的,以下是一个简单的Java程序实现学生成绩管理系统,包括学生信息输入、计算平均成绩、按平均成绩排序输出、每门课程成绩单输出等功能。
```java
import java.util.Arrays;
import java.util.Scanner;
public class StudentScoreManagement {
// 定义每个学生的成绩信息
static class Student {
String id; // 学号
String name; // 姓名
double[] scores; // 五门课程成绩
public Student(String id, String name, double[] scores) {
this.id = id;
this.name = name;
this.scores = scores;
}
// 计算平均成绩
public double getAverageScore() {
double sum = 0;
for (double score : scores) {
sum += score;
}
return sum / scores.length;
}
}
public static void main(String[] args) {
Scanner scanner = new Scanner(System.in);
System.out.print("请输入学生数量:");
int n = scanner.nextInt();
Student[] students = new Student[n];
for (int i = 0; i < n; i++) {
System.out.printf("请输入第%d个学生的信息:\n", i + 1);
System.out.print("学号:");
String id = scanner.next();
System.out.print("姓名:");
String name = scanner.next();
double[] scores = new double[5];
System.out.print("语文成绩:");
scores[0] = scanner.nextDouble();
System.out.print("数学成绩:");
scores[1] = scanner.nextDouble();
System.out.print("外语成绩:");
scores[2] = scanner.nextDouble();
System.out.print("物理成绩:");
scores[3] = scanner.nextDouble();
System.out.print("化学成绩:");
scores[4] = scanner.nextDouble();
students[i] = new Student(id, name, scores);
}
// 按平均成绩排序
Arrays.sort(students, (s1, s2) -> Double.compare(s2.getAverageScore(), s1.getAverageScore()));
// 输出学生信息
System.out.println("按平均成绩排序后的学生列表:");
for (Student student : students) {
System.out.printf("学号:%s,姓名:%s,平均成绩:%.2f\n", student.id, student.name, student.getAverageScore());
}
// 输出每门课程成绩单
System.out.println("每门课程成绩单:");
System.out.println("语文成绩单");
for (Student student : students) {
System.out.printf("%s\t%.2f\n", student.name, student.scores[0]);
}
System.out.println("数学成绩单");
for (Student student : students) {
System.out.printf("%s\t%.2f\n", student.name, student.scores[1]);
}
System.out.println("外语成绩单");
for (Student student : students) {
System.out.printf("%s\t%.2f\n", student.name, student.scores[2]);
}
System.out.println("物理成绩单");
for (Student student : students) {
System.out.printf("%s\t%.2f\n", student.name, student.scores[3]);
}
System.out.println("化学成绩单");
for (Student student : students) {
System.out.printf("%s\t%.2f\n", student.name, student.scores[4]);
}
}
}
```
希望能够对您有所帮助!
阅读全文