Java实现一个学生成绩信息管理系统,实现对学生成绩信息的添加、删除、修改、查询、统计等操作。
时间: 2023-07-10 17:38:24 浏览: 137
好的,这是一个比较复杂的问题,需要进行详细的说明和讲解。首先,我们可以采用面向对象的思想,设计一个学生类和一个成绩类,学生类包含学生的基本信息,成绩类包含学生的各个科目的成绩。然后,我们可以采用数组或者集合等数据结构来存储学生和成绩信息。接下来,我们可以实现以下功能:
1. 添加学生信息:输入学生的基本信息和各个科目的成绩,将其存储在数组或集合中。
2. 删除学生信息:根据学生的学号或姓名等信息,从数组或集合中删除对应的学生信息。
3. 修改学生信息:根据学生的学号或姓名等信息,找到对应的学生信息,可以修改学生的基本信息和各个科目的成绩。
4. 查询学生信息:根据学生的学号或姓名等信息,查询对应的学生信息和各个科目的成绩。
5. 统计学生信息:统计所有学生的总成绩、平均成绩、最高分、最低分等信息。
下面是一个简单的实现代码,供您参考:
```java
import java.util.ArrayList;
import java.util.Scanner;
public class StudentScoreManagementSystem {
public static void main(String[] args) {
ArrayList<Student> students = new ArrayList<>();
Scanner scanner = new Scanner(System.in);
int choice = 0;
while (choice != 6) {
System.out.println("请选择操作:");
System.out.println("1.添加学生信息");
System.out.println("2.删除学生信息");
System.out.println("3.修改学生信息");
System.out.println("4.查询学生信息");
System.out.println("5.统计学生信息");
System.out.println("6.退出系统");
System.out.print("请选择操作:");
choice = scanner.nextInt();
switch (choice) {
case 1:
addStudent(students, scanner);
break;
case 2:
deleteStudent(students, scanner);
break;
case 3:
modifyStudent(students, scanner);
break;
case 4:
queryStudent(students, scanner);
break;
case 5:
statistics(students);
break;
case 6:
System.out.println("感谢使用学生成绩信息管理系统!");
break;
default:
System.out.println("输入有误,请重新输入!");
break;
}
}
}
private static void addStudent(ArrayList<Student> students, Scanner scanner) {
System.out.print("请输入学生的姓名:");
String name = scanner.next();
System.out.print("请输入学生的学号:");
String id = scanner.next();
System.out.print("请输入学生的性别:");
String gender = scanner.next();
System.out.print("请输入学生的年龄:");
int age = scanner.nextInt();
System.out.print("请输入学生的语文成绩:");
double chinese = scanner.nextDouble();
System.out.print("请输入学生的数学成绩:");
double math = scanner.nextDouble();
System.out.print("请输入学生的英语成绩:");
double english = scanner.nextDouble();
students.add(new Student(name, id, gender, age, chinese, math, english));
System.out.println("添加成功!");
}
private static void deleteStudent(ArrayList<Student> students, Scanner scanner) {
System.out.print("请输入要删除学生的学号或姓名:");
String keyword = scanner.next();
boolean flag = false;
for (int i = 0; i < students.size(); i++) {
Student student = students.get(i);
if (student.getId().equals(keyword) || student.getName().equals(keyword)) {
students.remove(i);
flag = true;
break;
}
}
if (flag) {
System.out.println("删除成功!");
} else {
System.out.println("未找到对应的学生信息,请重新输入!");
}
}
private static void modifyStudent(ArrayList<Student> students, Scanner scanner) {
System.out.print("请输入要修改学生的学号或姓名:");
String keyword = scanner.next();
boolean flag = false;
for (int i = 0; i < students.size(); i++) {
Student student = students.get(i);
if (student.getId().equals(keyword) || student.getName().equals(keyword)) {
System.out.print("请输入学生的姓名(原姓名:" + student.getName() + "):");
String name = scanner.next();
System.out.print("请输入学生的学号(原学号:" + student.getId() + "):");
String id = scanner.next();
System.out.print("请输入学生的性别(原性别:" + student.getGender() + "):");
String gender = scanner.next();
System.out.print("请输入学生的年龄(原年龄:" + student.getAge() + "):");
int age = scanner.nextInt();
System.out.print("请输入学生的语文成绩(原语文成绩:" + student.getChinese() + "):");
double chinese = scanner.nextDouble();
System.out.print("请输入学生的数学成绩(原数学成绩:" + student.getMath() + "):");
double math = scanner.nextDouble();
System.out.print("请输入学生的英语成绩(原英语成绩:" + student.getEnglish() + "):");
double english = scanner.nextDouble();
student.setName(name);
student.setId(id);
student.setGender(gender);
student.setAge(age);
student.setChinese(chinese);
student.setMath(math);
student.setEnglish(english);
flag = true;
break;
}
}
if (flag) {
System.out.println("修改成功!");
} else {
System.out.println("未找到对应的学生信息,请重新输入!");
}
}
private static void queryStudent(ArrayList<Student> students, Scanner scanner) {
System.out.print("请输入要查询学生的学号或姓名:");
String keyword = scanner.next();
boolean flag = false;
for (int i = 0; i < students.size(); i++) {
Student student = students.get(i);
if (student.getId().equals(keyword) || student.getName().equals(keyword)) {
System.out.println("姓名:" + student.getName());
System.out.println("学号:" + student.getId());
System.out.println("性别:" + student.getGender());
System.out.println("年龄:" + student.getAge());
System.out.println("语文成绩:" + student.getChinese());
System.out.println("数学成绩:" + student.getMath());
System.out.println("英语成绩:" + student.getEnglish());
flag = true;
break;
}
}
if (!flag) {
System.out.println("未找到对应的学生信息,请重新输入!");
}
}
private static void statistics(ArrayList<Student> students) {
int count = students.size();
double chineseSum = 0;
double mathSum = 0;
double englishSum = 0;
double totalSum = 0;
double chineseMax = 0;
double mathMax = 0;
double englishMax = 0;
double totalMax = 0;
double chineseMin = 100;
double mathMin = 100;
double englishMin = 100;
double totalMin = 300;
for (int i = 0; i < students.size(); i++) {
Student student = students.get(i);
chineseSum += student.getChinese();
mathSum += student.getMath();
englishSum += student.getEnglish();
totalSum += student.getTotal();
chineseMax = Math.max(chineseMax, student.getChinese());
mathMax = Math.max(mathMax, student.getMath());
englishMax = Math.max(englishMax, student.getEnglish());
totalMax = Math.max(totalMax, student.getTotal());
chineseMin = Math.min(chineseMin, student.getChinese());
mathMin = Math.min(mathMin, student.getMath());
englishMin = Math.min(englishMin, student.getEnglish());
totalMin = Math.min(totalMin, student.getTotal());
}
double chineseAvg = chineseSum / count;
double mathAvg = mathSum / count;
double englishAvg = englishSum / count;
double totalAvg = totalSum / count;
System.out.println("总人数:" + count);
System.out.println("语文总分:" + chineseSum + ",语文平均分:" + chineseAvg + ",语文最高分:" + chineseMax + ",语文最低分:" + chineseMin);
System.out.println("数学总分:" + mathSum + ",数学平均分:" + mathAvg + ",数学最高分:" + mathMax + ",数学最低分:" + mathMin);
System.out.println("英语总分:" + englishSum + ",英语平均分:" + englishAvg + ",英语最高分:" + englishMax + ",英语最低分:" + englishMin);
System.out.println("总分总分:" + totalSum + ",总分平均分:" + totalAvg + ",总分最高分:" + totalMax + ",总分最低分:" + totalMin);
}
}
class Student {
private String name;
private String id;
private String gender;
private int age;
private double chinese;
private double math;
private double english;
public Student(String name, String id, String gender, int age, double chinese, double math, double english) {
this.name = name;
this.id = id;
this.gender = gender;
this.age = age;
this.chinese = chinese;
this.math = math;
this.english = english;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public String getId() {
return id;
}
public void setId(String id) {
this.id = id;
}
public String getGender() {
return gender;
}
public void setGender(String gender) {
this.gender = gender;
}
public int getAge() {
return age;
}
public void setAge(int age) {
this.age = age;
}
public double getChinese() {
return chinese;
}
public void setChinese(double chinese) {
this.chinese = chinese;
}
public double getMath() {
return math;
}
public void setMath(double math) {
this.math = math;
}
public double getEnglish() {
return english;
}
public void setEnglish(double english) {
this.english = english;
}
public double getTotal() {
return chinese + math + english;
}
}
```
以上就是一个简单的学生成绩信息管理系统的实现,您可以根据自己的需求进行修改和完善。
阅读全文