用java写一个学生成绩管理系统
时间: 2023-12-17 15:03:29 浏览: 60
好的,下面是一个简单的学生成绩管理系统的Java代码:
```java
import java.util.Scanner;
public class StudentGradeManagementSystem {
public static void main(String[] args) {
Scanner input = new Scanner(System.in);
int option = 0;
int num = 0;
String[] names = new String[100];
int[] mathScores = new int[100];
int[] englishScores = new int[100];
int[] totalScores = new int[100];
double[] averageScores = new double[100];
while (true) {
System.out.println("请选择操作:");
System.out.println("1. 添加学生信息");
System.out.println("2. 删除学生信息");
System.out.println("3. 修改学生信息");
System.out.println("4. 查询学生信息");
System.out.println("5. 退出程序");
option = input.nextInt();
switch (option) {
case 1:
System.out.print("请输入学生姓名:");
names[num] = input.next();
System.out.print("请输入数学成绩:");
mathScores[num] = input.nextInt();
System.out.print("请输入英语成绩:");
englishScores[num] = input.nextInt();
totalScores[num] = mathScores[num] + englishScores[num];
averageScores[num] = totalScores[num] / 2.0;
num++;
System.out.println("添加成功!");
break;
case 2:
System.out.print("请输入要删除的学生姓名:");
String name = input.next();
int index = -1;
for (int i = 0; i < num; i++) {
if (name.equals(names[i])) {
index = i;
break;
}
}
if (index == -1) {
System.out.println("没有找到该学生!");
} else {
for (int i = index; i < num - 1; i++) {
names[i] = names[i + 1];
mathScores[i] = mathScores[i + 1];
englishScores[i] = englishScores[i + 1];
totalScores[i] = totalScores[i + 1];
averageScores[i] = averageScores[i + 1];
}
num--;
System.out.println("删除成功!");
}
break;
case 3:
System.out.print("请输入要修改的学生姓名:");
name = input.next();
index = -1;
for (int i = 0; i < num; i++) {
if (name.equals(names[i])) {
index = i;
break;
}
}
if (index == -1) {
System.out.println("没有找到该学生!");
} else {
System.out.print("请输入新的数学成绩:");
mathScores[index] = input.nextInt();
System.out.print("请输入新的英语成绩:");
englishScores[index] = input.nextInt();
totalScores[index] = mathScores[index] + englishScores[index];
averageScores[index] = totalScores[index] / 2.0;
System.out.println("修改成功!");
}
break;
case 4:
System.out.println("学生姓名\t\t数学成绩\t\t英语成绩\t\t总分\t\t平均分");
for (int i = 0; i < num; i++) {
System.out.println(names[i] + "\t\t\t" + mathScores[i] + "\t\t\t" + englishScores[i] + "\t\t\t" + totalScores[i] + "\t\t\t" + averageScores[i]);
}
break;
case 5:
System.out.println("谢谢使用!");
System.exit(0);
default:
System.out.println("输入错误,请重新输入!");
break;
}
}
}
}
```
这个学生成绩管理系统可以实现添加、删除、修改、查询学生信息的功能。同时,它还可以计算学生的总分和平均分。你可以根据实际需要对代码进行修改和完善。
阅读全文