简单的学生宿舍管理系统java代码
时间: 2023-11-24 14:05:34 浏览: 58
基于java+jsp+mysql学生宿舍管理系统(简单的增删改查)
5星 · 资源好评率100%
以下是一个简单的学生宿舍管理系统的Java代码示例:
```
import java.util.Scanner;
public class DormitoryManagementSystem {
public static void main(String[] args) {
Scanner scanner = new Scanner(System.in);
int choice = 0;
while (choice != 4) {
System.out.println("Welcome to the Dormitory Management System!");
System.out.println("1. Add a student");
System.out.println("2. Remove a student");
System.out.println("3. View all students");
System.out.println("4. Quit");
System.out.print("Enter your choice: ");
choice = scanner.nextInt();
switch (choice) {
case 1:
addStudent();
break;
case 2:
removeStudent();
break;
case 3:
viewStudents();
break;
case 4:
System.out.println("Goodbye!");
break;
default:
System.out.println("Invalid choice. Please try again.");
break;
}
}
scanner.close();
}
private static void addStudent() {
Scanner scanner = new Scanner(System.in);
System.out.print("Enter the student's name: ");
String name = scanner.nextLine();
System.out.print("Enter the student's ID: ");
String id = scanner.nextLine();
System.out.print("Enter the student's room number: ");
int roomNumber = scanner.nextInt();
// TODO: Add the student to the database
System.out.println("Student added successfully!");
}
private static void removeStudent() {
Scanner scanner = new Scanner(System.in);
System.out.print("Enter the student's ID: ");
String id = scanner.nextLine();
// TODO: Remove the student from the database
System.out.println("Student removed successfully!");
}
private static void viewStudents() {
// TODO: Retrieve all students from the database and display them
}
}
```
上述代码实现了一个简单的学生宿舍管理系统,可以添加、删除和查看所有学生的信息。但是,需要注意的是,该代码示例仅用于演示目的,实际的学生宿舍管理系统需要更加完善和复杂的功能和设计。
阅读全文