package exam;

import java.util.Scanner; import java.sql.Connection; import java.sql.PreparedStatement; import java.sql.ResultSet; import java.sql.SQLException; import java.sql.*;

public class ExamManagementSystem {

public static void main(String[] args) {
    Scanner scanner = new Scanner(System.in);
    System.out.println("Choose your language:");
    System.out.println("1. Chinese");
    System.out.println("2. English");
    int langChoice = scanner.nextInt();

    switch (langChoice) {
        case 1:
            System.out.println("欢迎使用考试管理系统!");
            System.out.println("请选择您的身份:");
            System.out.println("1. 学生");
            System.out.println("2. 教师");
            System.out.println("3. 返回主页面");
            int choice = scanner.nextInt();

            switch (choice) {
                case 1:
                    while (true) {
                        System.out.println("请选择您要进行的操作:");
                        System.out.println("1. 学生注册");
                        System.out.println("2. 学生登录");
                        System.out.println("3. 返回主页面");
                        int studentChoice = scanner.nextInt();

                        switch (studentChoice) {
                            case 1:
                                studentRegistration();
                                break;
                            case 2:
                                studentLogin();
                                break;
                            case 3:
                                System.out.println("谢谢使用,再见!");
                                return;
                            default:
                                System.out.println("无效的选项!");
                                break;
                        }
                    }
                case 2:
                    System.out.println("请输入姓名:");
                    String teacherName = scanner.nextLine();
                    System.out.println("请输入密码:");
                    String teacherPassword = scanner.nextLine();
                    System.out.println("是否登录?");
                    System.out.println("1. 是");
                    System.out.println("2. 否");
                    System.out.println("3. 返回主页面");
                    int teacherLoginChoice = scanner.nextInt();

                    switch (teacherLoginChoice) {
                        case 1:
                            teacherLogin(teacherName, teacherPassword);
                            break;
                        case 2:
                            System.out.println("谢谢使用,再见!");
                            return;
                        case 3:
                            break;
                        default:
                            System.out.println("无效的选项!");
                            break;
                    }
                    break;
                case 3:
                    System.out.println("谢谢使用,再见!");
                    return;
                default:
                    System.out.println("无效的选项!");
                    break;
            }

            break;
        case 2:
            System.out.println("Welcome to Exam Management System!");
            System.out.println("Please choose your identity:");
            System.out.println("1. Student");
            System.out.println("2. Teacher");
            System.out.println("3. Return to Main Page");
            int Choice = scanner.nextInt();

            switch (Choice) {
                case 1:
                    while (true) {
                        System.out.println("Please choose your option:");
                        System.out.println("1. Student Registration");
                        System.out.println("2. Student Login");
                        System.out.println("3. Return to Main Page");
                        int studentChoice = scanner.nextInt();

                        switch (studentChoice) {
                            case 1:
                                studentRegistration();
                                break;
                            case 2:
                                studentLogin();
                                break;
                            case 3:
                                System.out.println("Thank you for using our system. Goodbye!");
                                return;
                            default:
                                System.out.println("Invalid option!");
                                break;
                        }
                    }
                case 2:
                    System.out.println("Please enter your name:");
                    String teacherName = scanner.nextLine();
                    System.out.println("Please enter your password:");
                    String teacherPassword = scanner.nextLine();
                    System.out.println("Do you want to login?");
                    System.out.println("1. Yes");
                    System.out.println("2. No");
                    System.out.println("3. Return to Main Page");
                    int teacherLoginChoice = scanner.nextInt();

                    switch (teacherLoginChoice) {
                        case 1:
                            teacherLogin(teacherName, teacherPassword);
                            break;
                        case 2:
                            System.out.println("Thank you for using our system. Goodbye!");
                            return;
                        case 3:
                            break;
                        default:
                            System.out.println("Invalid option!");
                            break;
                    }
                    break;
                case 3:
                    System.out.println("Thank you for using our system. Goodbye!");
                    return;
                default:
                    System.out.println("Invalid option!");
                    break;
            }

            break;
        default:
            System.out.println("Invalid option!");
            break;
    }
}

// 学生注册
public static void studentRegistration() {
    Scanner scanner = new Scanner(System.in);
    System.out.println("请输入学号:");
    int studentId = scanner.nextInt();
    System.out.println("请输入姓名:");
    scanner.nextLine();
    String name = scanner.nextLine();
    System.out.println("请输入密码:");
    String password = scanner.nextLine();
    System.out.println("请再次输入密码:");
    String confirmPassword = scanner.nextLine();

    if (password.equals(confirmPassword)) {
        // 将学生信息插入到数据库中
        try (Connection conn = DatabaseConnector.getConnection()) {
            String sql = "INSERT INTO students (student_id, name, password) VALUES (?, ?, ?)";
            PreparedStatement statement = conn.prepareStatement(sql);
            statement.setInt(1, studentId);
            statement.setString(2, name);
            statement.setString(3, password);
            statement.executeUpdate();
            System.out.println("注册成功!");
        } catch (SQLException e) {
            e.printStackTrace();
            System.out.println("注册失败,请重新尝试!");
        }
    } else {
        System.out.println("两次输入的密码不一致,请重新注册!");
    }
}
考试管理系统:学生和教师的双语在线考试平台

原文地址: https://www.cveoy.top/t/topic/f0xJ 著作权归作者所有。请勿转载和采集!

免费AI点我,无需注册和登录