用java编写一个成绩管理系统包括增删改查
时间: 2023-07-19 17:44:55 浏览: 92
好的,我可以为您提供一个简单的成绩管理系统的Java代码,包括增加、删除、修改和查询成绩的功能。以下是示例代码:
```
import java.util.ArrayList;
import java.util.Scanner;
public class ScoreManagementSystem {
static ArrayList<Student> studentList = new ArrayList<Student>();
static Scanner scanner = new Scanner(System.in);
public static void main(String[] args) {
boolean loop = true;
while (loop) {
System.out.println("请选择您要进行的操作:");
System.out.println("1. 添加学生");
System.out.println("2. 删除学生");
System.out.println("3. 修改学生信息");
System.out.println("4. 查询学生信息");
System.out.println("5. 退出系统");
int choice = scanner.nextInt();
switch (choice) {
case 1:
addStudent();
break;
case 2:
deleteStudent();
break;
case 3:
modifyStudent();
break;
case 4:
queryStudent();
break;
case 5:
loop = false;
break;
default:
System.out.println("输入有误,请重新输入!");
break;
}
}
}
public static void addStudent() {
System.out.println("请输入学生姓名:");
String name = scanner.next();
System.out.println("请输入学生学号:");
int number = scanner.nextInt();
System.out.println("请输入学生成绩:");
double score = scanner.nextDouble();
Student student = new Student(name, number, score);
studentList.add(student);
System.out.println("添加成功!");
}
public static void deleteStudent() {
System.out.println("请输入要删除学生的学号:");
int number = scanner.nextInt();
for (int i = 0; i < studentList.size(); i++) {
if (studentList.get(i).getNumber() == number) {
studentList.remove(i);
System.out.println("删除成功!");
return;
}
}
System.out.println("没有找到该学生!");
}
public static void modifyStudent() {
System.out.println("请输入要修改学生的学号:");
int number = scanner.nextInt();
for (int i = 0; i < studentList.size(); i++) {
if (studentList.get(i).getNumber() == number) {
System.out.println("请输入修改后的学生姓名:");
String name = scanner.next();
System.out.println("请输入修改后的学生成绩:");
double score = scanner.nextDouble();
studentList.get(i).setName(name);
studentList.get(i).setScore(score);
System.out.println("修改成功!");
return;
}
}
System.out.println("没有找到该学生!");
}
public static void queryStudent() {
System.out.println("请输入要查询学生的学号:");
int number = scanner.nextInt();
for (int i = 0; i < studentList.size(); i++) {
if (studentList.get(i).getNumber() == number) {
System.out.println(studentList.get(i));
return;
}
}
System.out.println("没有找到该学生!");
}
}
class Student {
private String name;
private int number;
private double score;
public Student(String name, int number, double score) {
this.name = name;
this.number = number;
this.score = score;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public int getNumber() {
return number;
}
public void setNumber(int number) {
this.number = number;
}
public double getScore() {
return score;
}
public void setScore(double score) {
this.score = score;
}
@Override
public String toString() {
return "学生姓名:" + name + ",学号:" + number + ",成绩:" + score;
}
}
```
这个简单的成绩管理系统包含了添加学生、删除学生、修改学生信息和查询学生信息的功能。您可以根据自己的需求对代码进行修改和扩展。
阅读全文