编写Java程序,用于管理班级学生的各科(语、数、外)成绩:用户通过注册成为管理员,管理员可通过登录界面成功登录后,进入学生成绩管理界面,可对学生相关信息进行插入、查询等操作
时间: 2024-01-12 13:04:10 浏览: 17
以下是一个简单的班级学生成绩管理系统的Java程序,实现了管理员注册、登录,学生成绩的插入、查询等操作:
```java
import java.util.*;
// 学生类
class Student {
public String name; // 姓名
public int chineseScore; // 语文成绩
public int mathScore; // 数学成绩
public int englishScore; // 英语成绩
public Student(String name, int chineseScore, int mathScore, int englishScore) {
this.name = name;
this.chineseScore = chineseScore;
this.mathScore = mathScore;
this.englishScore = englishScore;
}
}
// 班级类,用于管理学生信息
class Classroom {
private ArrayList<Student> students = new ArrayList<Student>(); // 学生列表
// 添加学生
public void addStudent(Student student) {
students.add(student);
}
// 查询学生成绩
public Student queryStudent(String name) {
for (Student student : students) {
if (student.name.equals(name)) {
return student;
}
}
return null;
}
// 获取学生列表
public ArrayList<Student> getStudents() {
return students;
}
}
// 管理员类
class Admin {
private String username; // 用户名
private String password; // 密码
public Admin(String username, String password) {
this.username = username;
this.password = password;
}
// 验证用户名和密码是否正确
public boolean login(String username, String password) {
return this.username.equals(username) && this.password.equals(password);
}
}
// 主程序
class Main {
public static void main(String[] args) {
Scanner scanner = new Scanner(System.in);
// 注册管理员
System.out.print("请输入管理员用户名:");
String username = scanner.nextLine();
System.out.print("请输入管理员密码:");
String password = scanner.nextLine();
Admin admin = new Admin(username, password);
// 登录
System.out.print("请输入用户名:");
String loginUsername = scanner.nextLine();
System.out.print("请输入密码:");
String loginPassword = scanner.nextLine();
if (!admin.login(loginUsername, loginPassword)) {
System.out.println("用户名或密码错误,登录失败!");
return;
}
// 初始化班级学生信息
Classroom classroom = new Classroom();
classroom.addStudent(new Student("张三", 90, 85, 95));
classroom.addStudent(new Student("李四", 80, 75, 85));
classroom.addStudent(new Student("王五", 70, 80, 90));
// 学生成绩管理
while (true) {
System.out.println("请选择操作:");
System.out.println("1. 查询学生成绩");
System.out.println("2. 添加学生信息");
System.out.println("3. 查看学生列表");
System.out.println("4. 退出");
System.out.print("请输入操作编号:");
int choice = scanner.nextInt();
scanner.nextLine(); // 读取换行符
switch (choice) {
case 1:
System.out.print("请输入学生姓名:");
String name = scanner.nextLine();
Student student = classroom.queryStudent(name);
if (student == null) {
System.out.println("未找到该学生!");
} else {
System.out.println("姓名:" + student.name);
System.out.println("语文成绩:" + student.chineseScore);
System.out.println("数学成绩:" + student.mathScore);
System.out.println("英语成绩:" + student.englishScore);
}
break;
case 2:
System.out.print("请输入学生姓名:");
String newName = scanner.nextLine();
System.out.print("请输入语文成绩:");
int chineseScore = scanner.nextInt();
System.out.print("请输入数学成绩:");
int mathScore = scanner.nextInt();
System.out.print("请输入英语成绩:");
int englishScore = scanner.nextInt();
scanner.nextLine(); // 读取换行符
classroom.addStudent(new Student(newName, chineseScore, mathScore, englishScore));
System.out.println("添加成功!");
break;
case 3:
ArrayList<Student> students = classroom.getStudents();
for (Student s : students) {
System.out.println("姓名:" + s.name);
System.out.println("语文成绩:" + s.chineseScore);
System.out.println("数学成绩:" + s.mathScore);
System.out.println("英语成绩:" + s.englishScore);
System.out.println("-------------------------");
}
break;
case 4:
System.out.println("谢谢使用!");
return;
default:
System.out.println("输入有误,请重新输入!");
break;
}
}
}
}
```
这个程序实现了管理员的注册、登录,班级学生信息的初始化,学生成绩的插入、查询等操作。运行程序后,管理员首先需要进行注册,然后输入用户名和密码登录,进入学生成绩管理界面,可以选择查询学生成绩、添加学生信息、查看学生列表等操作。
相关推荐
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)
![rar](https://img-home.csdnimg.cn/images/20210720083606.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)