.大学生班级事务管理系统 主要功能模块: (1)班级人员管理模块 (2)不同级别登录人员对班级事务的增删查改等操作模块 (3)班级留言板功能模板 用java代码实现
时间: 2024-01-10 22:01:58 浏览: 123
学生管理系统 实现登录、增、删、改、查等功能
下面是一个简单的Java代码实现,实现了班级人员管理、登录权限控制和班级留言板功能模块。具体的实现细节,可以根据具体需求进行修改和完善。
```
import java.util.ArrayList;
import java.util.Scanner;
// 定义一个班级人员类
class Student {
private String name;
private String id;
private String major;
private String phone;
public Student(String name, String id, String major, String phone) {
this.name = name;
this.id = id;
this.major = major;
this.phone = phone;
}
public String getName() {
return name;
}
public String getId() {
return id;
}
public String getMajor() {
return major;
}
public String getPhone() {
return phone;
}
@Override
public String toString() {
return "姓名:" + name + ",学号:" + id + ",专业:" + major + ",电话:" + phone;
}
}
// 定义一个班级留言板类
class MessageBoard {
private ArrayList<String> messages;
public MessageBoard() {
messages = new ArrayList<>();
}
public void addMessage(String message) {
messages.add(message);
}
public void printMessages() {
System.out.println("留言板:");
for (String message : messages) {
System.out.println(message);
}
}
}
// 定义一个班级管理系统类
public class ClassManagementSystem {
private ArrayList<Student> students;
private MessageBoard messageBoard;
public ClassManagementSystem() {
students = new ArrayList<>();
messageBoard = new MessageBoard();
}
public void addStudent(Student student) {
students.add(student);
}
public void removeStudent(Student student) {
students.remove(student);
}
public void printStudents() {
System.out.println("班级人员:");
for (Student student : students) {
System.out.println(student);
}
}
public void login(int level) {
Scanner scanner = new Scanner(System.in);
System.out.println("请输入用户名:");
String username = scanner.nextLine();
System.out.println("请输入密码:");
String password = scanner.nextLine();
if (level == 1 && username.equals("admin") && password.equals("123456")) {
System.out.println("管理员登录成功!");
// 管理员可以进行增删改操作
System.out.println("请选择操作:");
System.out.println("1. 增加人员");
System.out.println("2. 删除人员");
System.out.println("3. 修改人员信息");
int choice = scanner.nextInt();
scanner.nextLine();
if (choice == 1) {
System.out.println("请输入姓名:");
String name = scanner.nextLine();
System.out.println("请输入学号:");
String id = scanner.nextLine();
System.out.println("请输入专业:");
String major = scanner.nextLine();
System.out.println("请输入电话:");
String phone = scanner.nextLine();
Student student = new Student(name, id, major, phone);
addStudent(student);
System.out.println("人员添加成功!");
} else if (choice == 2) {
System.out.println("请输入要删除的学号:");
String id = scanner.nextLine();
for (Student student : students) {
if (student.getId().equals(id)) {
removeStudent(student);
System.out.println("人员删除成功!");
break;
}
}
} else if (choice == 3) {
System.out.println("请输入要修改的学号:");
String id = scanner.nextLine();
for (Student student : students) {
if (student.getId().equals(id)) {
System.out.println("请输入新的姓名(留空表示不修改):");
String name = scanner.nextLine();
System.out.println("请输入新的专业(留空表示不修改):");
String major = scanner.nextLine();
System.out.println("请输入新的电话(留空表示不修改):");
String phone = scanner.nextLine();
if (!name.isEmpty()) {
student = new Student(name, student.getId(), student.getMajor(), student.getPhone());
}
if (!major.isEmpty()) {
student = new Student(student.getName(), student.getId(), major, student.getPhone());
}
if (!phone.isEmpty()) {
student = new Student(student.getName(), student.getId(), student.getMajor(), phone);
}
System.out.println("人员修改成功!");
break;
}
}
} else {
System.out.println("无效操作!");
}
} else if (level == 2 && username.equals("user") && password.equals("123456")) {
System.out.println("普通用户登录成功!");
// 普通用户可以查看班级人员和留言板
System.out.println("请选择操作:");
System.out.println("1. 查看班级人员");
System.out.println("2. 查看留言板");
int choice = scanner.nextInt();
scanner.nextLine();
if (choice == 1) {
printStudents();
} else if (choice == 2) {
messageBoard.printMessages();
} else {
System.out.println("无效操作!");
}
} else {
System.out.println("用户名或密码错误!");
}
}
public void addMessage(String message) {
messageBoard.addMessage(message);
}
public static void main(String[] args) {
ClassManagementSystem system = new ClassManagementSystem();
system.addStudent(new Student("张三", "1001", "计算机科学与技术", "12345678901"));
system.addStudent(new Student("李四", "1002", "软件工程", "12345678902"));
system.addStudent(new Student("王五", "1003", "信息管理", "12345678903"));
Scanner scanner = new Scanner(System.in);
while (true) {
System.out.println("请选择登录级别:");
System.out.println("1. 管理员");
System.out.println("2. 普通用户");
int level = scanner.nextInt();
scanner.nextLine();
system.login(level);
}
}
}
```
阅读全文