You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 

127 lines
6.3 KiB

package com.example;
import java.util.List;
import java.util.Map;
import java.util.Scanner;
/**
* 湖大选课系统主应用类
* 不依赖Spring Boot,使用普通Java类实现
*/
public class HnuCourseSystem {
public static void main(String[] args) {
// 初始化数据库
DatabaseUtil.initDatabase();
// 创建CourseAnalysis实例
CourseAnalysis analysis = new CourseAnalysis();
// 显示菜单
try (Scanner scanner = new Scanner(System.in)) {
int choice;
do {
System.out.println("===== 湖大选课系统 =====");
System.out.println("1. 查看整体统计信息");
System.out.println("2. 查看课程类型分布");
System.out.println("3. 查看院系统计");
System.out.println("4. 查看学分分布");
System.out.println("5. 查看热门课程");
System.out.println("6. 查看课程容量使用率");
System.out.println("7. 查看按院系分组的统计");
System.out.println("0. 退出系统");
System.out.print("请选择操作: ");
choice = scanner.nextInt();
scanner.nextLine(); // 消费换行符
switch (choice) {
case 1 -> {
// 查看整体统计信息
System.out.println("\n整体统计信息:");
Map<String, Object> overallStats = analysis.getOverallStatistics();
for (Map.Entry<String, Object> entry : overallStats.entrySet()) {
System.out.println(entry.getKey() + ": " + entry.getValue());
}
}
case 2 -> {
// 查看课程类型分布
System.out.println("\n课程类型分布:");
Map<String, Integer> typeDistribution = analysis.getCourseTypeDistribution();
for (Map.Entry<String, Integer> entry : typeDistribution.entrySet()) {
System.out.println(entry.getKey() + ": " + entry.getValue());
}
}
case 3 -> {
// 查看院系统计
System.out.println("\n院系统计:");
Map<String, Integer> deptDistribution = analysis.getDepartmentDistribution();
for (Map.Entry<String, Integer> entry : deptDistribution.entrySet()) {
System.out.println(entry.getKey() + ": " + entry.getValue());
}
}
case 4 -> {
// 查看学分分布
System.out.println("\n学分分布:");
Map<Double, Integer> creditDistribution = analysis.getCreditDistribution();
for (Map.Entry<Double, Integer> entry : creditDistribution.entrySet()) {
System.out.println(entry.getKey() + "学分: " + entry.getValue() + "门");
}
}
case 5 -> {
// 查看热门课程
System.out.println("\n热门课程:");
List<Map<String, Object>> topCourses = analysis.getTopCourses();
for (int i = 0; i < topCourses.size(); i++) {
Map<String, Object> course = topCourses.get(i);
System.out.println((i + 1) + ". " + course.get("courseName") + " - " + course.get("teacher"));
System.out.println(" 院系: " + course.get("department") + ", 容量: " + course.get("capacity") + ", 已选: " + course.get("enrolled"));
}
}
case 6 -> {
// 查看课程容量使用率
System.out.println("\n课程容量使用率:");
List<Map<String, Object>> usageRates = analysis.getCourseUsageRate();
for (int i = 0; i < Math.min(10, usageRates.size()); i++) {
Map<String, Object> usage = usageRates.get(i);
System.out.println((i + 1) + ". " + usage.get("courseName"));
System.out.println(" 容量: " + usage.get("capacity") + ", 已选: " + usage.get("enrolled") + ", 使用率: " + String.format("%.2f%%", usage.get("usageRate")));
}
}
case 7 -> {
// 查看按院系分组的统计
System.out.println("\n按院系分组的统计:");
Map<String, Map<String, Object>> deptStats = analysis.getDepartmentStatistics();
for (Map.Entry<String, Map<String, Object>> entry : deptStats.entrySet()) {
String department = entry.getKey();
Map<String, Object> stats = entry.getValue();
System.out.println("院系: " + department);
System.out.println(" 课程数量: " + stats.get("courseCount"));
System.out.println(" 总学分: " + stats.get("totalCredits"));
System.out.println(" 总容量: " + stats.get("totalCapacity"));
System.out.println(" 总已选人数: " + stats.get("totalEnrolled"));
System.out.println(" 使用率: " + String.format("%.2f%%", stats.get("usageRate")));
}
}
case 0 -> System.out.println("退出系统...");
default -> System.out.println("无效选择,请重新输入");
}
if (choice != 0) {
System.out.println("\n按Enter键继续...");
scanner.nextLine();
}
} while (choice != 0);
}
}
}