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();

        while (true) {
            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:
                            studentRegistration(langChoice);
                            break;
                        case 2:
                            studentLogin(langChoice);
                            break;
                        case 3:
                            System.out.println('谢谢使用,再见!');
                            System.exit(0); // 退出系统
                        default:
                            System.out.println('无效的选项!');
                            break;
                    }
                    break;

                case 2:
                    System.out.println('Welcome to Exam Management System!');
                    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(langChoice);
                            break;
                        case 2:
                            studentLogin(langChoice);
                            break;
                        case 3:
                            System.out.println('Thank you for using our system. Goodbye!');
                            System.exit(0); // 退出系统
                        default:
                            System.out.println('Invalid option!');
                            break;
                    }
                    break;

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

    // 学生注册
    public static void studentRegistration(int langChoice) {
        Scanner scanner = new Scanner(System.in);
        switch (langChoice) {
            case 1:
                System.out.println('请输入学号:');
                break;
            case 2:
                System.out.println('Please enter your student ID:');
                break;
        }
        int studentId = scanner.nextInt();
        scanner.nextLine(); // 读取换行符
        switch (langChoice) {
            case 1:
                System.out.println('请输入姓名:');
                break;
            case 2:
                System.out.println('Please enter your name:');
                break;
        }
        String name = scanner.nextLine();
        switch (langChoice) {
            case 1:
                System.out.println('请输入密码:');
                break;
            case 2:
                System.out.println('Please enter your password:');
                break;
        }
        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();
            switch (langChoice) {
                case 1:
                    System.out.println('注册成功!');
                    System.out.println('请选择您要进行的操作:');
                    System.out.println('1. 继续注册');
                    System.out.println('2. 学生登录');
                    break;
                case 2:
                    System.out.println('Registration successful!');
                    System.out.println('Please choose your option:');
                    System.out.println('1. Continue registration');
                    System.out.println('2. Student Login');
                    break;
            }

            int choice = scanner.nextInt();

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

    // 学生登录
    public static void studentLogin(int langChoice) {
        Scanner scanner = new Scanner(System.in);
        switch (langChoice) {
            case 1:
                System.out.println('请输入学号:');
                break;
            case 2:
                System.out.println('Please enter your student ID:');
                break;
        }
        int studentId = scanner.nextInt();
        scanner.nextLine(); // 读取换行符
        switch (langChoice) {
            case 1:
                System.out.println('请输入密码:');
                break;
            case 2:
                System.out.println('Please enter your password:');
                break;
        }
        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()) {
                switch (langChoice) {
                    case 1:
                        System.out.println('登录成功!');
                        System.out.println('请选择您要进行的操作:');
                        System.out.println('1. 选择课程');
                        System.out.println('2. 查看成绩');
                        System.out.println('3. 退出登录');
                        break;
                    case 2:
                        System.out.println('Login successful!');
                        System.out.println('Please choose your option:');
                        System.out.println('1. Choose course');
                        System.out.println('2. View results');
                        System.out.println('3. Logout');
                        break;
                }

                int choice = scanner.nextInt();

                switch (choice) {
                    case 1:
                        chooseCourse(langChoice);
                        break;
                    case 2:
                        // 查看成绩页面逻辑
                        break;
                    case 3:
                        switch (langChoice) {
                            case 1:
                                System.out.println('谢谢使用,再见!');
                                break;
                            case 2:
                                System.out.println('Thank you for using our system. Goodbye!');
                                break;
                        }
                        break;
                    default:
                        switch (langChoice) {
                            case 1:
                                System.out.println('无效的选项!');
                                break;
                            case 2:
                                System.out.println('Invalid option!');
                                break;
                        }
                        break;
                }

                // 可以开始考试等操作
            } else {
                switch (langChoice) {
                    case 1:
                        System.out.println('学号或密码错误,请重新登录!');
                        break;
                    case 2:
                        System.out.println('Invalid student ID or password. Please try again!');
                        break;
                }
            }
        } catch (SQLException e) {
            e.printStackTrace();
            switch (langChoice) {
                case 1:
                    System.out.println('登录失败,请重新尝试!');
                    break;
                case 2:
                    System.out.println('Login failed. Please try again!');
                    break;
            }
        }
    }

    // 选择课程页面
    public static void chooseCourse(int langChoice) {
        // 从数据库读取课程信息,并显示给学生选择

        // 选择后进入考试页面
    }

    // 学生开始考试页面
    public static void studentStartExam(int langChoice) {
        // 从数据库读取题目,并逐题显示给学生答题

        // 学生答题完成后计算得分,并保存到数据库
    }

    // 教师查看学生考试结果页面
    public static void teacherViewResults(int langChoice) {
        // 从数据库查询学生的考试成绩,并显示给教师

        // 教师可按课程查看期末考试总结报告
    }
}
多语言在线考试管理系统 - Java实现

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

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