package exam;

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

public class ExamManagementSystem {

public static void main(String[] args) {
    Scanner scanner = new Scanner(System.in);
    System.out.println('选择语言:');
    System.out.println('1. 中文');
    System.out.println('2. English');
    int langChoice = scanner.nextInt();
    
    switch (langChoice) {
        case 1:
            System.out.println('欢迎使用考试管理系统!');
            while (true) {
                System.out.println('请选择您要进行的操作:');
                System.out.println('1. 学生注册');
                System.out.println('2. 学生登录');
                System.out.println('3. 退出系统');
                int choice = scanner.nextInt();

                switch (choice) {
                    case 1:
                        studentRegistration();
                        break;
                    case 2:
                        studentLogin();
                        break;
                    case 3:
                        System.out.println('谢谢使用,再见!');
                        System.exit(0); // 退出系统
                    default:
                        System.out.println('无效的选项!');
                        break;
                }
            }

        case 2:
            System.out.println('Welcome to Exam Management System!');
            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. Exit System');
                int Choice = scanner.nextInt();

                switch (Choice) {
                    case 1:
                        studentRegistration();
                        break;
                    case 2:
                        studentLogin();
                        break;
                    case 3:
                        System.out.println('Thank you for using our system. Goodbye!');
                        System.exit(0); // 退出系统
                    default:
                        System.out.println('Invalid option!');
                        break;
                }
            }

        default:
            System.out.println('无效的选项!');
            break;
    }
}

// 学生注册
public static void studentRegistration() {
    Scanner scanner = new Scanner(System.in);
    System.out.println('请输入学号:');
    int studentId = scanner.nextInt();
    scanner.nextLine(); // 读取换行符
    System.out.println('请输入姓名:');
    String name = scanner.nextLine();
    System.out.println('请输入密码:');
    String password = scanner.nextLine();
    
    // 将学生信息插入到数据库中
    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('注册成功!');
        
        // 询问是否继续注册或登录
        System.out.println('请选择您要进行的操作:');
        System.out.println('1. 继续注册');
        System.out.println('2. 学生登录');
        int choice = scanner.nextInt();

        switch (choice) {
            case 1:
                studentRegistration();
                break;
            case 2:
                studentLogin();
                break;
            default:
                System.out.println('无效的选项!');
                break;
        }
    } catch (SQLException e) {
        e.printStackTrace();
        System.out.println('注册失败,请重新尝试!');
    }
}

// 学生登录
public static void studentLogin() {
    Scanner scanner = new Scanner(System.in);
    System.out.println('请输入学号:');
    int studentId = scanner.nextInt();
    scanner.nextLine(); // 读取换行符
    System.out.println('请输入密码:');
    String password = scanner.nextLine();
    
    // 查询数据库验证学生登录信息
    try (Connection conn = DatabaseConnector.getConnection()) {
        String sql = 'SELECT * FROM students WHERE student_id = ? AND password = ?';
        PreparedStatement statement = conn.prepareStatement(sql);
        statement.setInt(1, studentId);
        statement.setString(2, password);
        ResultSet result = statement.executeQuery();
        if (result.next()) {
            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:
                    chooseCourse();
                    break;
                case 2:
                    // 查看成绩页面逻辑
                    break;
                case 3:
                    System.out.println('谢谢使用,再见!');
                    break;
                default:
                    System.out.println('无效的选项!');
                    break;
            }

            // 可以开始考试等操作
        } else {
            System.out.println('学号或密码错误,请重新登录!');
        }
    } catch (SQLException e) {
        e.printStackTrace();
        System.out.println('登录失败,请重新尝试!');
    }
}

// 选择课程页面
public static void chooseCourse() {
    // 从数据库读取课程信息,并显示给学生选择
    
    // 选择后进入考试页面
}

// 学生开始考试页面
public static void studentStartExam() {
    // 从数据库读取题目,并逐题显示给学生答题
    
    // 学生答题完成后计算得分,并保存到数据库
}

// 教师查看学生考试结果页面
public static void teacherViewResults() {
    // 从数据库查询学生的考试成绩,并显示给教师
    
    // 教师可按课程查看期末考试总结报告
}

}

在线考试管理系统:安全高效的考试平台

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

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