⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 coursemanager.java

📁 学生课程管理系统 基于java的源代码 供教学使用
💻 JAVA
字号:
package manager;

import java.io.*;

import data.*;

import util.*;



public class CourseManager {
	// 五门课程
	private Course[] courses = new Course[Constant.MAX_TEACHER_COUNT];

	// 初始化五门课程
	public CourseManager() {
		courses[0] = new Course("语文", "王老师");
		courses[1] = new Course("数学", "刘老师");
		courses[2] = new Course("物理", "唐老师");
		courses[3] = new Course("化学", "杨老师");
		courses[4] = new Course("英语", "孙老师");
	}

	// 获取输入的函数
	private String readInput() throws IOException {
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		String str = br.readLine();
		return str;
	}

	// 菜单头显示
	private void showMenuHead(String head) {
		System.out.println("*******************************************");
		System.out.println("                 " + head + "               ");
		System.out.println("*******************************************");

	}

	// 显示课程信息
	private void showCourses() {
		System.out.println("----------------------------------------------");
		System.out.println("课程编号    课程名称    授课老师    已选人数");
		System.out.println("----------------------------------------------");
		for (int i = 0; i < courses.length; i++) {
			System.out.print(" " + (i + 1) + "         ");
			courses[i].show();
			System.out
					.println("----------------------------------------------");
		}
	}

	// 显示主菜单
	private void showMainMenu() {
		showMenuHead("学生选课系统");
		System.out.println("       1-------------------帮助");
		System.out.println("       2-------------------查看课程信息");
		System.out.println("       3-------------------选修课程");
		System.out.println("       4-------------------查看课程详细信息");
		System.out.println("       5-------------------查询学生信息");
		System.out.println("       6-------------------系统退出");
	}

	// 完成查看帮助功能,即菜单一
	private void showMenu1() {
		System.out.println();
		showMenuHead("帮助信息");
		System.out.println();
		System.out.println("    有五门课程,每门课程都有一位老师授课,每门");
		System.out.println("课程最多可以有10个学生选修,管理员可以对选修某");
		System.out.println("一门课程的学生进行管理,包括添加和删除选修指定");
		System.out.println("课程的学生,管理员可以查看每一门课程的选修情况");
		System.out.println("和每个学生的详细信息。");
		System.out.println();
		System.out.println("返回主界面请选择 y:");
		// returnFlag是返回上级菜单标志
		String returnFlag = "";
		while (!returnFlag.equals("y")) {
			try {
				returnFlag = readInput();
			} catch (Exception e) {
				System.out.println("Eight catch.");
			}
			if (returnFlag.equals("y")) {
				continue;
			}
			System.out.println("对不起,您的输入不对,返回主界面请选择 y:");
		}
	}

	// 完成查看课程信息功能,即菜单2
	private void showMenu2() {
		System.out.println();
		showMenuHead("课程信息");
		showCourses();
		System.out.println();
		System.out.println("返回主界面请选择 y:");
		// returnFlag是返回上级菜单标志
		String returnFlag = "";
		while (!returnFlag.equals("y")) {
			try {
				returnFlag = readInput();
			} catch (Exception e) {
				System.out.println("Eight catch.");
			}
			if (returnFlag.equals("y")) {
				continue;
			}
			System.out.println("对不起,您的输入不对,返回主界面请选择 y:");
		}
	}

	// 完成添加学生到课程功能
	private void showMenu3() {
		String continueFlag = "y";
		while (continueFlag.equals("y")) {
			String studentName = null;// 学生姓名
			String studentGender = "";// 学生性别
			int studentAge = 0;// 学生年龄

			int courseNumber = 0;// 要加入的课程序号

			showMenuHead("选修课程");
			// 读取用户输入的学生姓名
			System.out.println("请输入你的姓名:");
			try {
				studentName = readInput();
			} catch (Exception e) {
				System.out.println("First catch.");
			}
			// 读取用户输入的学生性别
			System.out.println("请输入你的性别:");
			while (!studentGender.equals("男") && !studentGender.equals("女")) {
				try {
					studentGender = readInput();
				} catch (Exception e) {
					System.out.println("Secend catch.");
				}
				if (!studentGender.equals("男") && !studentGender.equals("女")) {
					System.out.println("对不起,您的输入不对,请重新输入性别(男或女)");
				}
			}
			// 读取用户输入的年龄
			System.out.println("请输入你的年龄:");
			while (studentAge < 13 || studentAge > 100) {
				try {
					studentAge = Integer.parseInt(readInput());
				} catch (NumberFormatException e) {
					System.out.println("对不起,您输入的格式不对,请输入数字,请重新输入你的年龄:");
					continue;
				} catch (Exception e) {
					System.out.println("Third catch.");
				}
				if (studentAge < 13 || studentAge > 100) {
					System.out.println("对不起,暂时不接受13岁以下和100岁以上的学生,请重新输入你的年龄:");
				}
			}

			showCourses();

			// 读取用户输入的课程编号
			System.out.println("请选择你要选修的课程编号: ");
			while (courseNumber < 1 || courseNumber > 5) {
				try {
					courseNumber = Integer.parseInt(readInput());
				} catch (NumberFormatException e) {
					System.out.println("对不起,您输入的格式不对,请输入数字,请重新选择你要选修的课程编号:");
					continue;
				} catch (Exception e) {
					System.out.println("Fourth catch.");
				}
				if (courseNumber < 1 || courseNumber > 5) {
					System.out
							.println("对不起,暂时只有5门课,请在1--5之间选择,请重新选择你要选修的课程编号: ");
				}
			}
			// 增加学生
			try {
				courses[courseNumber - 1].addStudent(studentName,
						studentGender, studentAge);
			} catch (Exception e) {
				System.out.println("Fifth catch");
			}
			System.out.println("是否继续添加(选择y继续,选择n返回一级主界面):");
			try {
				continueFlag = readInput();
			} catch (Exception e) {
				System.out.println("Sixth catch.");
			}
			while (!continueFlag.equals("y") && !continueFlag.equals("n")) {
				System.out.println("对不起,您的输入不对,是否继续添加(选择y继续,选择n返回一级主界面):");
				try {
					continueFlag = readInput();
				} catch (Exception e) {
					System.out.println("Eight catch.");
				}
			}
			if (continueFlag.equals("n")) {
				break;
			}
		}
	}

	// 完成查看具体课程详细包含哪些学生的功能
	private void showMenu4() {
		showMenuHead("查看课程选修信息");
		showCourses();
		String continueFlag = "y";

		while (continueFlag.equals("y")) {
			System.out.println("请输入要详细查询课程的序号:");
			int courseNumber = -1;
			while (courseNumber < 1 || courseNumber > 5) {
				try {
					courseNumber = Integer.parseInt(readInput());
				} catch (NumberFormatException e) {
					System.out.println("对不起,您输入的格式不对,请输入数字,请重新输入要详细查询课程的序号:");
				} catch (Exception e) {
					System.out.println("Eight catch.");
				}
				if (courseNumber < 1 || courseNumber > 5) {
					System.out
							.println("对不起,暂时只有5门课,请在1--5之间选择,请重新输入要详细查询课程的序号:");
				}
			}

			System.out.println("查询结果:");
			// 查询具体课程的详细信息
			courses[courseNumber - 1].showDetail();

			System.out.println();
			System.out.println("是否继续查询(选择y继续,选择n返回一级主界面):");
			try {
				continueFlag = readInput();
			} catch (IOException e) {
				System.out.println("Eight catch.");
			}
			while (!continueFlag.equals("y") && !continueFlag.equals("n")) {
				System.out.println("对不起,您的输入不对,是否继续添加(选择y继续,选择n返回一级主界面):");
				try {
					continueFlag = readInput();
				} catch (IOException e) {
					System.out.println("Eight catch.");
				}
			}
			if (continueFlag.equals("n")) {
				return;
			}
		}

	}

	// 完成查询具体学生信息功能
	private void showMenu5() {
		String studentName = null;
		showMenuHead("查询学生信息");
		String continueFlag = "y";

		while (continueFlag.equals("y")) {
			System.out.println("请输入要查询学生的姓名:");
			try {
				studentName = readInput();
			} catch (IOException e) {
				System.out.println("Eight catch.");
			}
			System.out.println("查询结果:");
			for (int i = 0; i < courses.length; i++) {
				System.out.println(courses[i].showStudent(studentName));
			}
			System.out.println();

			System.out.println("是否继续查询(选择y继续,选择n返回一级主界面):");
			try {
				continueFlag = readInput();
			} catch (Exception e) {
				System.out.println("Eight catch.");
			}
			while (!continueFlag.equals("y") && !continueFlag.equals("n")) {
				System.out.println("对不起,您的输入不对,是否继续查询(选择y继续,选择n返回一级主界面):");
				try {
					continueFlag = readInput();
				} catch (Exception e) {
					System.out.println("Eight catch.");
				}
			}
			if (continueFlag.equals("n")) {
				return;
			}
		}
	}

	// 退出信息
	public void showMenu6() {
		System.out.println();
		System.out.println("再见!");
	}

	// 系统运行
	public void start() {
		while (true) {
			showMainMenu();
			System.out.println("请输入: ");

			int menuNumber = 0;
			try {
				menuNumber = Integer.parseInt(readInput());
			} catch (NumberFormatException e) {
				System.out.println("对不起,您输入的格式不对,请输入数字.");
				System.out.println();
				continue;
			} catch (Exception e) {
				System.out.println("Seventh catch.");
			}
			if (menuNumber < 1 || menuNumber > 6) {
				System.out.println("对不起,只有6项菜单,请在1--6之间选择.");
				System.out.println();
				continue;
			}
			switch (menuNumber) {
			case 1:
				showMenu1();
				break;
			case 2:
				showMenu2();
				break;
			case 3:
				showMenu3();
				break;
			case 4:
				showMenu4();
				break;
			case 5:
				showMenu5();
				break;
			case 6:
				showMenu6();
				return;
			}
		}
	}
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -