Compare commits
2 Commits
| Author | SHA1 | Date |
|---|---|---|
|
|
bdc23a816e | 3 weeks ago |
|
|
8a346b9ca8 | 3 weeks ago |
18 changed files with 0 additions and 1317 deletions
@ -1,36 +0,0 @@ |
|||||
# Build outputs |
|
||||
target/ |
|
||||
*.class |
|
||||
|
|
||||
# IDE |
|
||||
.idea/ |
|
||||
*.iml |
|
||||
.vscode/ |
|
||||
|
|
||||
# Logs |
|
||||
*.log |
|
||||
|
|
||||
# OS |
|
||||
.DS_Store |
|
||||
Thumbs.db |
|
||||
|
|
||||
# Database |
|
||||
*.db |
|
||||
*.db-journal |
|
||||
|
|
||||
# Temp files |
|
||||
*.xml |
|
||||
*.ps1 |
|
||||
report.txt |
|
||||
Untitled-*.java |
|
||||
*.tmp |
|
||||
*.temp |
|
||||
|
|
||||
# Maven |
|
||||
pom.xml.tag |
|
||||
pom.xml.releaseBackup |
|
||||
pom.xml.versionsBackup |
|
||||
pom.xml.next |
|
||||
release.properties |
|
||||
dependency-reduced-pom.xml |
|
||||
build.log |
|
||||
@ -1,2 +0,0 @@ |
|||||
# java |
|
||||
|
|
||||
Binary file not shown.
@ -1,50 +0,0 @@ |
|||||
package com.example.shape; |
|
||||
|
|
||||
/** |
|
||||
* 圆形类 |
|
||||
* 继承自Shape抽象类,实现getArea()方法 |
|
||||
*/ |
|
||||
public class Circle extends Shape { |
|
||||
private double radius; |
|
||||
|
|
||||
/** |
|
||||
* 构造方法 |
|
||||
* @param radius 圆的半径 |
|
||||
*/ |
|
||||
public Circle(double radius) { |
|
||||
this.radius = radius; |
|
||||
} |
|
||||
|
|
||||
/** |
|
||||
* 计算圆形面积 |
|
||||
* @return 圆形的面积 |
|
||||
*/ |
|
||||
@Override |
|
||||
public double getArea() { |
|
||||
return Math.PI * radius * radius; |
|
||||
} |
|
||||
|
|
||||
/** |
|
||||
* 获取圆的半径 |
|
||||
* @return 圆的半径 |
|
||||
*/ |
|
||||
public double getRadius() { |
|
||||
return radius; |
|
||||
} |
|
||||
|
|
||||
/** |
|
||||
* 设置圆的半径 |
|
||||
* @param radius 圆的半径 |
|
||||
*/ |
|
||||
public void setRadius(double radius) { |
|
||||
this.radius = radius; |
|
||||
} |
|
||||
|
|
||||
/** |
|
||||
* 绘制圆形 |
|
||||
*/ |
|
||||
@Override |
|
||||
public void draw() { |
|
||||
System.out.println("绘制一个半径为 " + radius + " 的圆形"); |
|
||||
} |
|
||||
} |
|
||||
@ -1,69 +0,0 @@ |
|||||
package com.example.shape; |
|
||||
|
|
||||
/** |
|
||||
* 矩形类 |
|
||||
* 继承自Shape抽象类,实现getArea()方法 |
|
||||
*/ |
|
||||
public class Rectangle extends Shape { |
|
||||
private double width; |
|
||||
private double height; |
|
||||
|
|
||||
/** |
|
||||
* 构造方法 |
|
||||
* @param width 矩形的宽度 |
|
||||
* @param height 矩形的高度 |
|
||||
*/ |
|
||||
public Rectangle(double width, double height) { |
|
||||
this.width = width; |
|
||||
this.height = height; |
|
||||
} |
|
||||
|
|
||||
/** |
|
||||
* 计算矩形面积 |
|
||||
* @return 矩形的面积 |
|
||||
*/ |
|
||||
@Override |
|
||||
public double getArea() { |
|
||||
return width * height; |
|
||||
} |
|
||||
|
|
||||
/** |
|
||||
* 获取矩形的宽度 |
|
||||
* @return 矩形的宽度 |
|
||||
*/ |
|
||||
public double getWidth() { |
|
||||
return width; |
|
||||
} |
|
||||
|
|
||||
/** |
|
||||
* 设置矩形的宽度 |
|
||||
* @param width 矩形的宽度 |
|
||||
*/ |
|
||||
public void setWidth(double width) { |
|
||||
this.width = width; |
|
||||
} |
|
||||
|
|
||||
/** |
|
||||
* 获取矩形的高度 |
|
||||
* @return 矩形的高度 |
|
||||
*/ |
|
||||
public double getHeight() { |
|
||||
return height; |
|
||||
} |
|
||||
|
|
||||
/** |
|
||||
* 设置矩形的高度 |
|
||||
* @param height 矩形的高度 |
|
||||
*/ |
|
||||
public void setHeight(double height) { |
|
||||
this.height = height; |
|
||||
} |
|
||||
|
|
||||
/** |
|
||||
* 绘制矩形 |
|
||||
*/ |
|
||||
@Override |
|
||||
public void draw() { |
|
||||
System.out.println("绘制一个宽为 " + width + ",高为 " + height + " 的矩形"); |
|
||||
} |
|
||||
} |
|
||||
@ -1,19 +0,0 @@ |
|||||
package com.example.shape; |
|
||||
|
|
||||
/** |
|
||||
* 图形抽象类 |
|
||||
* 包含抽象方法getArea(),用于计算图形面积 |
|
||||
* 包含抽象方法draw(),用于绘制图形 |
|
||||
*/ |
|
||||
public abstract class Shape { |
|
||||
/** |
|
||||
* 计算图形面积 |
|
||||
* @return 图形的面积 |
|
||||
*/ |
|
||||
public abstract double getArea(); |
|
||||
|
|
||||
/** |
|
||||
* 绘制图形 |
|
||||
*/ |
|
||||
public abstract void draw(); |
|
||||
} |
|
||||
@ -1,26 +0,0 @@ |
|||||
package com.example.shape; |
|
||||
|
|
||||
/** |
|
||||
* 图形面积计算器测试类 |
|
||||
*/ |
|
||||
public class ShapeCalculatorTest { |
|
||||
public static void main(String[] args) { |
|
||||
// 创建圆形对象,半径为5
|
|
||||
Circle circle = new Circle(5); |
|
||||
System.out.println("圆形的半径: " + circle.getRadius()); |
|
||||
ShapeUtil.printArea(circle); |
|
||||
ShapeUtil.ranShape(circle); |
|
||||
|
|
||||
// 创建矩形对象,宽为4,高为6
|
|
||||
Rectangle rectangle = new Rectangle(4, 6); |
|
||||
System.out.println("矩形的宽: " + rectangle.getWidth() + ", 高: " + rectangle.getHeight()); |
|
||||
ShapeUtil.printArea(rectangle); |
|
||||
ShapeUtil.ranShape(rectangle); |
|
||||
|
|
||||
// 创建三角形对象,底为8,高为3
|
|
||||
Triangle triangle = new Triangle(8, 3); |
|
||||
System.out.println("三角形的底: " + triangle.getBase() + ", 高: " + triangle.getHeight()); |
|
||||
ShapeUtil.printArea(triangle); |
|
||||
ShapeUtil.ranShape(triangle); |
|
||||
} |
|
||||
} |
|
||||
@ -1,24 +0,0 @@ |
|||||
package com.example.shape; |
|
||||
|
|
||||
/** |
|
||||
* 图形工具类 |
|
||||
* 提供打印图形面积的方法和绘制图形的方法 |
|
||||
*/ |
|
||||
public class ShapeUtil { |
|
||||
/** |
|
||||
* 打印图形的面积 |
|
||||
* @param shape 图形对象 |
|
||||
*/ |
|
||||
public static void printArea(Shape shape) { |
|
||||
double area = shape.getArea(); |
|
||||
System.out.println("图形的面积为: " + area); |
|
||||
} |
|
||||
|
|
||||
/** |
|
||||
* 绘制图形 |
|
||||
* @param s 图形对象 |
|
||||
*/ |
|
||||
public static void ranShape(Shape s) { |
|
||||
s.draw(); |
|
||||
} |
|
||||
} |
|
||||
@ -1,69 +0,0 @@ |
|||||
package com.example.shape; |
|
||||
|
|
||||
/** |
|
||||
* 三角形类 |
|
||||
* 继承自Shape抽象类,实现getArea()方法 |
|
||||
*/ |
|
||||
public class Triangle extends Shape { |
|
||||
private double base; |
|
||||
private double height; |
|
||||
|
|
||||
/** |
|
||||
* 构造方法 |
|
||||
* @param base 三角形的底 |
|
||||
* @param height 三角形的高 |
|
||||
*/ |
|
||||
public Triangle(double base, double height) { |
|
||||
this.base = base; |
|
||||
this.height = height; |
|
||||
} |
|
||||
|
|
||||
/** |
|
||||
* 计算三角形面积 |
|
||||
* @return 三角形的面积 |
|
||||
*/ |
|
||||
@Override |
|
||||
public double getArea() { |
|
||||
return base * height / 2; |
|
||||
} |
|
||||
|
|
||||
/** |
|
||||
* 获取三角形的底 |
|
||||
* @return 三角形的底 |
|
||||
*/ |
|
||||
public double getBase() { |
|
||||
return base; |
|
||||
} |
|
||||
|
|
||||
/** |
|
||||
* 设置三角形的底 |
|
||||
* @param base 三角形的底 |
|
||||
*/ |
|
||||
public void setBase(double base) { |
|
||||
this.base = base; |
|
||||
} |
|
||||
|
|
||||
/** |
|
||||
* 获取三角形的高 |
|
||||
* @return 三角形的高 |
|
||||
*/ |
|
||||
public double getHeight() { |
|
||||
return height; |
|
||||
} |
|
||||
|
|
||||
/** |
|
||||
* 设置三角形的高 |
|
||||
* @param height 三角形的高 |
|
||||
*/ |
|
||||
public void setHeight(double height) { |
|
||||
this.height = height; |
|
||||
} |
|
||||
|
|
||||
/** |
|
||||
* 绘制三角形 |
|
||||
*/ |
|
||||
@Override |
|
||||
public void draw() { |
|
||||
System.out.println("绘制一个底为 " + base + ",高为 " + height + " 的三角形"); |
|
||||
} |
|
||||
} |
|
||||
@ -1,5 +0,0 @@ |
|||||
public class HelloWorld { |
|
||||
public static void main(String[] args) { |
|
||||
System.out.println("Hello, World!"); |
|
||||
} |
|
||||
} |
|
||||
@ -1,74 +0,0 @@ |
|||||
import java.util.Scanner; |
|
||||
|
|
||||
/** |
|
||||
* 温度转换器程序(Java版本) |
|
||||
* 支持摄氏度(C)与华氏度(F)之间互转 |
|
||||
* |
|
||||
* 对应Python原始程序的功能移植 |
|
||||
*/ |
|
||||
public class TemperatureConverter { |
|
||||
|
|
||||
/** |
|
||||
* 将摄氏度转换为华氏度 |
|
||||
* |
|
||||
* @param c 摄氏温度(浮点数) |
|
||||
* @return 对应的华氏温度(浮点数) |
|
||||
*/ |
|
||||
public static double celsiusToFahrenheit(double c) { |
|
||||
return c * 9.0 / 5.0 + 32.0; |
|
||||
} |
|
||||
|
|
||||
/** |
|
||||
* 将华氏度转换为摄氏度 |
|
||||
* |
|
||||
* @param f 华氏温度(浮点数) |
|
||||
* @return 对应的摄氏温度(浮点数) |
|
||||
*/ |
|
||||
public static double fahrenheitToCelsius(double f) { |
|
||||
return (f - 32.0) * 5.0 / 9.0; |
|
||||
} |
|
||||
|
|
||||
public static void main(String[] args) { |
|
||||
Scanner scanner = new Scanner(System.in); |
|
||||
|
|
||||
// 提示用户输入,格式示例:“36.6 C”或“97 F”
|
|
||||
System.out.print("请输入要转换的温度与单位(例如 36.6 C 或 97 F):"); |
|
||||
String input = scanner.nextLine().trim(); |
|
||||
|
|
||||
// 检查输入是否为空
|
|
||||
if (input.isEmpty()) { |
|
||||
System.out.println("输入为空,程序退出。"); |
|
||||
scanner.close(); |
|
||||
return; |
|
||||
} |
|
||||
|
|
||||
// 按空格分割输入
|
|
||||
String[] parts = input.split("\\s+"); |
|
||||
|
|
||||
try { |
|
||||
// 允许用户输入两个部分:数值与单位
|
|
||||
double value = Double.parseDouble(parts[0]); |
|
||||
String unit = (parts.length > 1) ? parts[1].toUpperCase() : "C"; |
|
||||
|
|
||||
// 判断单位并进行相应转换
|
|
||||
if (unit.startsWith("C")) { |
|
||||
// 从摄氏度转换为华氏度
|
|
||||
double f = celsiusToFahrenheit(value); |
|
||||
System.out.printf("%.2f °C = %.2f °F%n", value, f); |
|
||||
} else if (unit.startsWith("F")) { |
|
||||
// 从华氏度转换为摄氏度
|
|
||||
double c = fahrenheitToCelsius(value); |
|
||||
System.out.printf("%.2f °F = %.2f °C%n", value, c); |
|
||||
} else { |
|
||||
System.out.println("未知单位,请使用 C 或 F。"); |
|
||||
} |
|
||||
|
|
||||
} catch (NumberFormatException e) { |
|
||||
System.out.println("输入解析失败,请按示例输入数值与单位,例如:36.6 C"); |
|
||||
} catch (ArrayIndexOutOfBoundsException e) { |
|
||||
System.out.println("输入格式错误,请按示例输入数值与单位,例如:36.6 C"); |
|
||||
} finally { |
|
||||
scanner.close(); |
|
||||
} |
|
||||
} |
|
||||
} |
|
||||
@ -1,8 +0,0 @@ |
|||||
package com.example.datacollect.command; |
|
||||
|
|
||||
import com.example.datacollect.repository.ArticleRepository; |
|
||||
|
|
||||
public interface Command { |
|
||||
String getName(); |
|
||||
void execute(String[] args, ArticleRepository repository); |
|
||||
} |
|
||||
@ -1,127 +0,0 @@ |
|||||
package com.example.entity; |
|
||||
|
|
||||
import java.time.LocalDateTime; |
|
||||
|
|
||||
/** |
|
||||
* 课程实体类 |
|
||||
* 不依赖Spring Boot,使用普通Java类实现 |
|
||||
*/ |
|
||||
public class Course { |
|
||||
private Long id; |
|
||||
private String courseCode; |
|
||||
private String courseName; |
|
||||
private Double credit; |
|
||||
private String teacher; |
|
||||
private String department; |
|
||||
private Integer capacity; |
|
||||
private Integer enrolled; |
|
||||
private String classTime; |
|
||||
private String classRoom; |
|
||||
private String courseType; |
|
||||
private String semester; |
|
||||
private LocalDateTime createTime; |
|
||||
|
|
||||
public Long getId() { |
|
||||
return id; |
|
||||
} |
|
||||
|
|
||||
public void setId(Long id) { |
|
||||
this.id = id; |
|
||||
} |
|
||||
|
|
||||
public String getCourseCode() { |
|
||||
return courseCode; |
|
||||
} |
|
||||
|
|
||||
public void setCourseCode(String courseCode) { |
|
||||
this.courseCode = courseCode; |
|
||||
} |
|
||||
|
|
||||
public String getCourseName() { |
|
||||
return courseName; |
|
||||
} |
|
||||
|
|
||||
public void setCourseName(String courseName) { |
|
||||
this.courseName = courseName; |
|
||||
} |
|
||||
|
|
||||
public Double getCredit() { |
|
||||
return credit; |
|
||||
} |
|
||||
|
|
||||
public void setCredit(Double credit) { |
|
||||
this.credit = credit; |
|
||||
} |
|
||||
|
|
||||
public String getTeacher() { |
|
||||
return teacher; |
|
||||
} |
|
||||
|
|
||||
public void setTeacher(String teacher) { |
|
||||
this.teacher = teacher; |
|
||||
} |
|
||||
|
|
||||
public String getDepartment() { |
|
||||
return department; |
|
||||
} |
|
||||
|
|
||||
public void setDepartment(String department) { |
|
||||
this.department = department; |
|
||||
} |
|
||||
|
|
||||
public Integer getCapacity() { |
|
||||
return capacity; |
|
||||
} |
|
||||
|
|
||||
public void setCapacity(Integer capacity) { |
|
||||
this.capacity = capacity; |
|
||||
} |
|
||||
|
|
||||
public Integer getEnrolled() { |
|
||||
return enrolled; |
|
||||
} |
|
||||
|
|
||||
public void setEnrolled(Integer enrolled) { |
|
||||
this.enrolled = enrolled; |
|
||||
} |
|
||||
|
|
||||
public String getClassTime() { |
|
||||
return classTime; |
|
||||
} |
|
||||
|
|
||||
public void setClassTime(String classTime) { |
|
||||
this.classTime = classTime; |
|
||||
} |
|
||||
|
|
||||
public String getClassRoom() { |
|
||||
return classRoom; |
|
||||
} |
|
||||
|
|
||||
public void setClassRoom(String classRoom) { |
|
||||
this.classRoom = classRoom; |
|
||||
} |
|
||||
|
|
||||
public String getCourseType() { |
|
||||
return courseType; |
|
||||
} |
|
||||
|
|
||||
public void setCourseType(String courseType) { |
|
||||
this.courseType = courseType; |
|
||||
} |
|
||||
|
|
||||
public String getSemester() { |
|
||||
return semester; |
|
||||
} |
|
||||
|
|
||||
public void setSemester(String semester) { |
|
||||
this.semester = semester; |
|
||||
} |
|
||||
|
|
||||
public LocalDateTime getCreateTime() { |
|
||||
return createTime; |
|
||||
} |
|
||||
|
|
||||
public void setCreateTime(LocalDateTime createTime) { |
|
||||
this.createTime = createTime; |
|
||||
} |
|
||||
} |
|
||||
@ -1,261 +0,0 @@ |
|||||
package com.example; |
|
||||
|
|
||||
import com.example.entity.Course; |
|
||||
|
|
||||
import java.util.List; |
|
||||
import java.util.Map; |
|
||||
import java.util.HashMap; |
|
||||
import java.util.ArrayList; |
|
||||
import java.util.stream.Collectors; |
|
||||
|
|
||||
/** |
|
||||
* 课程分析类 |
|
||||
* 不依赖Spring Boot,使用普通Java类实现 |
|
||||
*/ |
|
||||
public class CourseAnalysis { |
|
||||
|
|
||||
// 无参构造方法
|
|
||||
public CourseAnalysis() { |
|
||||
} |
|
||||
|
|
||||
// 获取课程类型分布
|
|
||||
public Map<String, Integer> getCourseTypeDistribution() { |
|
||||
return DatabaseUtil.getCourseTypeDistribution(); |
|
||||
} |
|
||||
|
|
||||
// 获取院系课程分布
|
|
||||
public Map<String, Integer> getDepartmentDistribution() { |
|
||||
return DatabaseUtil.getDepartmentDistribution(); |
|
||||
} |
|
||||
|
|
||||
// 获取学分分布
|
|
||||
public Map<Double, Integer> getCreditDistribution() { |
|
||||
Map<Double, Integer> distribution = new HashMap<>(); |
|
||||
List<Course> courses = DatabaseUtil.getAllCourses(); |
|
||||
|
|
||||
for (Course course : courses) { |
|
||||
double credit = course.getCredit(); |
|
||||
distribution.put(credit, distribution.getOrDefault(credit, 0) + 1); |
|
||||
} |
|
||||
|
|
||||
return distribution; |
|
||||
} |
|
||||
|
|
||||
// 获取热门课程
|
|
||||
public List<Map<String, Object>> getTopCourses() { |
|
||||
return DatabaseUtil.getTopCourses(); |
|
||||
} |
|
||||
|
|
||||
// 获取课程容量使用率
|
|
||||
public List<Map<String, Object>> getCourseUsageRate() { |
|
||||
List<Map<String, Object>> usageRates = new ArrayList<>(); |
|
||||
List<Course> courses = DatabaseUtil.getAllCourses(); |
|
||||
|
|
||||
for (Course course : courses) { |
|
||||
Map<String, Object> usageRate = new HashMap<>(); |
|
||||
usageRate.put("courseName", course.getCourseName()); |
|
||||
usageRate.put("capacity", course.getCapacity()); |
|
||||
usageRate.put("enrolled", course.getEnrolled()); |
|
||||
double rate = course.getCapacity() > 0 ? (double) course.getEnrolled() / course.getCapacity() * 100 : 0; |
|
||||
usageRate.put("usageRate", rate); |
|
||||
usageRates.add(usageRate); |
|
||||
} |
|
||||
|
|
||||
// 按使用率排序
|
|
||||
usageRates.sort((a, b) -> Double.compare((Double) b.get("usageRate"), (Double) a.get("usageRate"))); |
|
||||
|
|
||||
return usageRates; |
|
||||
} |
|
||||
|
|
||||
// 获取整体统计信息
|
|
||||
public Map<String, Object> getOverallStatistics() { |
|
||||
Map<String, Object> statistics = new HashMap<>(); |
|
||||
try { |
|
||||
List<Course> allCourses = DatabaseUtil.getAllCourses(); |
|
||||
|
|
||||
// 总课程数
|
|
||||
statistics.put("totalCourses", allCourses.size()); |
|
||||
|
|
||||
// 总学分
|
|
||||
double totalCredits = allCourses.stream() |
|
||||
.mapToDouble(Course::getCredit) |
|
||||
.sum(); |
|
||||
statistics.put("totalCredits", totalCredits); |
|
||||
|
|
||||
// 平均学分
|
|
||||
double avgCredit = allCourses.isEmpty() ? 0 : totalCredits / allCourses.size(); |
|
||||
statistics.put("averageCredit", avgCredit); |
|
||||
|
|
||||
// 总容量
|
|
||||
int totalCapacity = allCourses.stream() |
|
||||
.mapToInt(Course::getCapacity) |
|
||||
.sum(); |
|
||||
statistics.put("totalCapacity", totalCapacity); |
|
||||
|
|
||||
// 总已选人数
|
|
||||
int totalEnrolled = allCourses.stream() |
|
||||
.mapToInt(Course::getEnrolled) |
|
||||
.sum(); |
|
||||
statistics.put("totalEnrolled", totalEnrolled); |
|
||||
|
|
||||
// 总体使用率
|
|
||||
double overallUsageRate = totalCapacity > 0 ? (double) totalEnrolled / totalCapacity * 100 : 0; |
|
||||
statistics.put("overallUsageRate", overallUsageRate); |
|
||||
|
|
||||
// 课程类型数量
|
|
||||
long requiredCourses = allCourses.stream() |
|
||||
.filter(course -> "必修课".equals(course.getCourseType())) |
|
||||
.count(); |
|
||||
statistics.put("requiredCourses", requiredCourses); |
|
||||
|
|
||||
long electiveCourses = allCourses.stream() |
|
||||
.filter(course -> "选修课".equals(course.getCourseType())) |
|
||||
.count(); |
|
||||
statistics.put("electiveCourses", electiveCourses); |
|
||||
|
|
||||
// 院系数量
|
|
||||
long departmentCount = allCourses.stream() |
|
||||
.map(Course::getDepartment) |
|
||||
.distinct() |
|
||||
.count(); |
|
||||
statistics.put("departmentCount", departmentCount); |
|
||||
} catch (Exception e) { |
|
||||
System.err.println("获取整体统计信息失败:" + e.getMessage()); |
|
||||
// 返回默认值
|
|
||||
statistics.put("totalCourses", 0); |
|
||||
statistics.put("totalCredits", 0.0); |
|
||||
statistics.put("averageCredit", 0.0); |
|
||||
statistics.put("totalCapacity", 0); |
|
||||
statistics.put("totalEnrolled", 0); |
|
||||
statistics.put("overallUsageRate", 0.0); |
|
||||
statistics.put("requiredCourses", 0); |
|
||||
statistics.put("electiveCourses", 0); |
|
||||
statistics.put("departmentCount", 0); |
|
||||
} |
|
||||
return statistics; |
|
||||
} |
|
||||
|
|
||||
// 获取按院系分组的课程统计
|
|
||||
public Map<String, Map<String, Object>> getDepartmentStatistics() { |
|
||||
Map<String, Map<String, Object>> deptStats = new HashMap<>(); |
|
||||
try { |
|
||||
List<Course> allCourses = DatabaseUtil.getAllCourses(); |
|
||||
|
|
||||
// 按院系分组
|
|
||||
Map<String, List<Course>> coursesByDept = allCourses.stream() |
|
||||
.collect(Collectors.groupingBy(Course::getDepartment)); |
|
||||
|
|
||||
for (Map.Entry<String, List<Course>> entry : coursesByDept.entrySet()) { |
|
||||
String department = entry.getKey(); |
|
||||
List<Course> deptCourses = entry.getValue(); |
|
||||
|
|
||||
Map<String, Object> stats = new HashMap<>(); |
|
||||
stats.put("courseCount", deptCourses.size()); |
|
||||
|
|
||||
double deptCredits = deptCourses.stream() |
|
||||
.mapToDouble(Course::getCredit) |
|
||||
.sum(); |
|
||||
stats.put("totalCredits", deptCredits); |
|
||||
|
|
||||
int deptCapacity = deptCourses.stream() |
|
||||
.mapToInt(Course::getCapacity) |
|
||||
.sum(); |
|
||||
stats.put("totalCapacity", deptCapacity); |
|
||||
|
|
||||
int deptEnrolled = deptCourses.stream() |
|
||||
.mapToInt(Course::getEnrolled) |
|
||||
.sum(); |
|
||||
stats.put("totalEnrolled", deptEnrolled); |
|
||||
|
|
||||
double deptUsageRate = deptCapacity > 0 ? (double) deptEnrolled / deptCapacity * 100 : 0; |
|
||||
stats.put("usageRate", deptUsageRate); |
|
||||
|
|
||||
deptStats.put(department, stats); |
|
||||
} |
|
||||
} catch (Exception e) { |
|
||||
System.err.println("获取院系统计信息失败:" + e.getMessage()); |
|
||||
} |
|
||||
return deptStats; |
|
||||
} |
|
||||
|
|
||||
// 获取教师课程统计
|
|
||||
public Map<String, Map<String, Object>> getTeacherStatistics() { |
|
||||
Map<String, Map<String, Object>> teacherStats = new HashMap<>(); |
|
||||
try { |
|
||||
List<Course> allCourses = DatabaseUtil.getAllCourses(); |
|
||||
|
|
||||
// 按教师分组
|
|
||||
Map<String, List<Course>> coursesByTeacher = allCourses.stream() |
|
||||
.collect(Collectors.groupingBy(Course::getTeacher)); |
|
||||
|
|
||||
for (Map.Entry<String, List<Course>> entry : coursesByTeacher.entrySet()) { |
|
||||
String teacher = entry.getKey(); |
|
||||
List<Course> teacherCourses = entry.getValue(); |
|
||||
|
|
||||
Map<String, Object> stats = new HashMap<>(); |
|
||||
stats.put("courseCount", teacherCourses.size()); |
|
||||
|
|
||||
double totalCredits = teacherCourses.stream() |
|
||||
.mapToDouble(Course::getCredit) |
|
||||
.sum(); |
|
||||
stats.put("totalCredits", totalCredits); |
|
||||
|
|
||||
int totalEnrolled = teacherCourses.stream() |
|
||||
.mapToInt(Course::getEnrolled) |
|
||||
.sum(); |
|
||||
stats.put("totalEnrolled", totalEnrolled); |
|
||||
|
|
||||
teacherStats.put(teacher, stats); |
|
||||
} |
|
||||
} catch (Exception e) { |
|
||||
System.err.println("获取教师统计信息失败:" + e.getMessage()); |
|
||||
} |
|
||||
return teacherStats; |
|
||||
} |
|
||||
|
|
||||
// 获取课程容量利用率分析
|
|
||||
public Map<String, Object> getCapacityAnalysis() { |
|
||||
Map<String, Object> analysis = new HashMap<>(); |
|
||||
try { |
|
||||
List<Course> allCourses = DatabaseUtil.getAllCourses(); |
|
||||
|
|
||||
int totalCapacity = allCourses.stream() |
|
||||
.mapToInt(Course::getCapacity) |
|
||||
.sum(); |
|
||||
|
|
||||
int totalEnrolled = allCourses.stream() |
|
||||
.mapToInt(Course::getEnrolled) |
|
||||
.sum(); |
|
||||
|
|
||||
int availableCapacity = totalCapacity - totalEnrolled; |
|
||||
|
|
||||
// 计算不同使用率区间的课程数量
|
|
||||
long highUsage = allCourses.stream() |
|
||||
.filter(course -> course.getCapacity() > 0 && |
|
||||
(double) course.getEnrolled() / course.getCapacity() >= 0.9) |
|
||||
.count(); |
|
||||
|
|
||||
long mediumUsage = allCourses.stream() |
|
||||
.filter(course -> course.getCapacity() > 0 && |
|
||||
(double) course.getEnrolled() / course.getCapacity() >= 0.5 && |
|
||||
(double) course.getEnrolled() / course.getCapacity() < 0.9) |
|
||||
.count(); |
|
||||
|
|
||||
long lowUsage = allCourses.stream() |
|
||||
.filter(course -> course.getCapacity() > 0 && |
|
||||
(double) course.getEnrolled() / course.getCapacity() < 0.5) |
|
||||
.count(); |
|
||||
|
|
||||
analysis.put("totalCapacity", totalCapacity); |
|
||||
analysis.put("totalEnrolled", totalEnrolled); |
|
||||
analysis.put("availableCapacity", availableCapacity); |
|
||||
analysis.put("highUsageCourses", highUsage); |
|
||||
analysis.put("mediumUsageCourses", mediumUsage); |
|
||||
analysis.put("lowUsageCourses", lowUsage); |
|
||||
|
|
||||
} catch (Exception e) { |
|
||||
System.err.println("获取容量分析失败:" + e.getMessage()); |
|
||||
} |
|
||||
return analysis; |
|
||||
} |
|
||||
} |
|
||||
@ -1,136 +0,0 @@ |
|||||
package com.example; |
|
||||
|
|
||||
import com.example.entity.Course; |
|
||||
|
|
||||
/** |
|
||||
* 测试类,用于验证湖大选课系统功能 |
|
||||
*/ |
|
||||
public class CourseSystemTest { |
|
||||
|
|
||||
public static void main(String[] args) { |
|
||||
// 初始化数据库
|
|
||||
DatabaseUtil.initDatabase(); |
|
||||
|
|
||||
// 清空现有数据
|
|
||||
DatabaseUtil.clearCourses(); |
|
||||
|
|
||||
// 添加测试数据
|
|
||||
addTestData(); |
|
||||
|
|
||||
// 创建CourseAnalysis实例
|
|
||||
CourseAnalysis analysis = new CourseAnalysis(); |
|
||||
|
|
||||
// 测试整体统计信息
|
|
||||
System.out.println("===== 测试整体统计信息 ====="); |
|
||||
System.out.println(analysis.getOverallStatistics()); |
|
||||
|
|
||||
// 测试课程类型分布
|
|
||||
System.out.println("\n===== 测试课程类型分布 ====="); |
|
||||
System.out.println(analysis.getCourseTypeDistribution()); |
|
||||
|
|
||||
// 测试院系统计
|
|
||||
System.out.println("\n===== 测试院系统计 ====="); |
|
||||
System.out.println(analysis.getDepartmentDistribution()); |
|
||||
|
|
||||
// 测试学分分布
|
|
||||
System.out.println("\n===== 测试学分分布 ====="); |
|
||||
System.out.println(analysis.getCreditDistribution()); |
|
||||
|
|
||||
// 测试热门课程
|
|
||||
System.out.println("\n===== 测试热门课程 ====="); |
|
||||
System.out.println(analysis.getTopCourses()); |
|
||||
|
|
||||
// 测试课程容量使用率
|
|
||||
System.out.println("\n===== 测试课程容量使用率 ====="); |
|
||||
System.out.println(analysis.getCourseUsageRate()); |
|
||||
|
|
||||
// 测试按院系分组的统计
|
|
||||
System.out.println("\n===== 测试按院系分组的统计 ====="); |
|
||||
System.out.println(analysis.getDepartmentStatistics()); |
|
||||
|
|
||||
// 测试教师课程统计
|
|
||||
System.out.println("\n===== 测试教师课程统计 ====="); |
|
||||
System.out.println(analysis.getTeacherStatistics()); |
|
||||
|
|
||||
// 测试课程容量利用率分析
|
|
||||
System.out.println("\n===== 测试课程容量利用率分析 ====="); |
|
||||
System.out.println(analysis.getCapacityAnalysis()); |
|
||||
|
|
||||
System.out.println("\n===== 测试完成 ====="); |
|
||||
} |
|
||||
|
|
||||
// 添加测试数据
|
|
||||
private static void addTestData() { |
|
||||
Course course1 = new Course(); |
|
||||
course1.setCourseCode("CS101"); |
|
||||
course1.setCourseName("计算机科学导论"); |
|
||||
course1.setCredit(3.0); |
|
||||
course1.setTeacher("张教授"); |
|
||||
course1.setDepartment("计算机学院"); |
|
||||
course1.setCapacity(100); |
|
||||
course1.setEnrolled(95); |
|
||||
course1.setClassTime("周一 8:00-10:00"); |
|
||||
course1.setClassRoom("A101"); |
|
||||
course1.setCourseType("必修课"); |
|
||||
course1.setSemester("2024春季"); |
|
||||
DatabaseUtil.saveCourse(course1); |
|
||||
|
|
||||
Course course2 = new Course(); |
|
||||
course2.setCourseCode("CS102"); |
|
||||
course2.setCourseName("数据结构"); |
|
||||
course2.setCredit(4.0); |
|
||||
course2.setTeacher("李教授"); |
|
||||
course2.setDepartment("计算机学院"); |
|
||||
course2.setCapacity(80); |
|
||||
course2.setEnrolled(75); |
|
||||
course2.setClassTime("周二 10:00-12:00"); |
|
||||
course2.setClassRoom("A102"); |
|
||||
course2.setCourseType("必修课"); |
|
||||
course2.setSemester("2024春季"); |
|
||||
DatabaseUtil.saveCourse(course2); |
|
||||
|
|
||||
Course course3 = new Course(); |
|
||||
course3.setCourseCode("MATH101"); |
|
||||
course3.setCourseName("高等数学"); |
|
||||
course3.setCredit(5.0); |
|
||||
course3.setTeacher("王教授"); |
|
||||
course3.setDepartment("数学学院"); |
|
||||
course3.setCapacity(120); |
|
||||
course3.setEnrolled(110); |
|
||||
course3.setClassTime("周三 8:00-10:00"); |
|
||||
course3.setClassRoom("B101"); |
|
||||
course3.setCourseType("必修课"); |
|
||||
course3.setSemester("2024春季"); |
|
||||
DatabaseUtil.saveCourse(course3); |
|
||||
|
|
||||
Course course4 = new Course(); |
|
||||
course4.setCourseCode("ENG101"); |
|
||||
course4.setCourseName("大学英语"); |
|
||||
course4.setCredit(2.0); |
|
||||
course4.setTeacher("刘教授"); |
|
||||
course4.setDepartment("外国语学院"); |
|
||||
course4.setCapacity(150); |
|
||||
course4.setEnrolled(120); |
|
||||
course4.setClassTime("周四 14:00-16:00"); |
|
||||
course4.setClassRoom("C101"); |
|
||||
course4.setCourseType("选修课"); |
|
||||
course4.setSemester("2024春季"); |
|
||||
DatabaseUtil.saveCourse(course4); |
|
||||
|
|
||||
Course course5 = new Course(); |
|
||||
course5.setCourseCode("PHYS101"); |
|
||||
course5.setCourseName("大学物理"); |
|
||||
course5.setCredit(4.0); |
|
||||
course5.setTeacher("陈教授"); |
|
||||
course5.setDepartment("物理学院"); |
|
||||
course5.setCapacity(90); |
|
||||
course5.setEnrolled(85); |
|
||||
course5.setClassTime("周五 10:00-12:00"); |
|
||||
course5.setClassRoom("D101"); |
|
||||
course5.setCourseType("必修课"); |
|
||||
course5.setSemester("2024春季"); |
|
||||
DatabaseUtil.saveCourse(course5); |
|
||||
|
|
||||
System.out.println("测试数据添加完成,共添加 5 门课程"); |
|
||||
} |
|
||||
} |
|
||||
@ -1,195 +0,0 @@ |
|||||
package com.example; |
|
||||
|
|
||||
import com.example.entity.Course; |
|
||||
|
|
||||
import java.sql.*; |
|
||||
import java.util.ArrayList; |
|
||||
import java.util.List; |
|
||||
import java.util.Map; |
|
||||
import java.util.HashMap; |
|
||||
|
|
||||
/** |
|
||||
* 数据库工具类 |
|
||||
* 提供数据库操作相关方法 |
|
||||
*/ |
|
||||
public class DatabaseUtil { |
|
||||
// 数据库URL
|
|
||||
private static final String DB_URL = "jdbc:sqlite:course.db"; |
|
||||
|
|
||||
// 静态初始化块,加载SQLite驱动
|
|
||||
static { |
|
||||
try { |
|
||||
Class.forName("org.sqlite.JDBC"); |
|
||||
System.out.println("SQLite驱动加载成功"); |
|
||||
} catch (ClassNotFoundException e) { |
|
||||
System.err.println("SQLite驱动加载失败: " + e.getMessage()); |
|
||||
} |
|
||||
} |
|
||||
|
|
||||
// 初始化数据库
|
|
||||
public static void initDatabase() { |
|
||||
try (Connection conn = DriverManager.getConnection(DB_URL); |
|
||||
Statement stmt = conn.createStatement()) { |
|
||||
|
|
||||
// 创建courses表
|
|
||||
String createTableSQL = "CREATE TABLE IF NOT EXISTS courses (" + |
|
||||
"id INTEGER PRIMARY KEY AUTOINCREMENT," + |
|
||||
"course_code TEXT," + |
|
||||
"course_name TEXT," + |
|
||||
"credit REAL," + |
|
||||
"teacher TEXT," + |
|
||||
"department TEXT," + |
|
||||
"capacity INTEGER," + |
|
||||
"enrolled INTEGER," + |
|
||||
"class_time TEXT," + |
|
||||
"class_room TEXT," + |
|
||||
"course_type TEXT," + |
|
||||
"semester TEXT," + |
|
||||
"create_time TIMESTAMP DEFAULT CURRENT_TIMESTAMP" + |
|
||||
")"; |
|
||||
stmt.executeUpdate(createTableSQL); |
|
||||
|
|
||||
System.out.println("数据库初始化成功"); |
|
||||
} catch (SQLException e) { |
|
||||
System.err.println("数据库初始化失败: " + e.getMessage()); |
|
||||
} |
|
||||
} |
|
||||
|
|
||||
// 获取所有课程
|
|
||||
public static List<Course> getAllCourses() { |
|
||||
List<Course> courses = new ArrayList<>(); |
|
||||
String sql = "SELECT * FROM courses"; |
|
||||
|
|
||||
try (Connection conn = DriverManager.getConnection(DB_URL); |
|
||||
Statement stmt = conn.createStatement(); |
|
||||
ResultSet rs = stmt.executeQuery(sql)) { |
|
||||
|
|
||||
while (rs.next()) { |
|
||||
Course course = new Course(); |
|
||||
course.setId(rs.getLong("id")); |
|
||||
course.setCourseCode(rs.getString("course_code")); |
|
||||
course.setCourseName(rs.getString("course_name")); |
|
||||
course.setCredit(rs.getDouble("credit")); |
|
||||
course.setTeacher(rs.getString("teacher")); |
|
||||
course.setDepartment(rs.getString("department")); |
|
||||
course.setCapacity(rs.getInt("capacity")); |
|
||||
course.setEnrolled(rs.getInt("enrolled")); |
|
||||
course.setClassTime(rs.getString("class_time")); |
|
||||
course.setClassRoom(rs.getString("class_room")); |
|
||||
course.setCourseType(rs.getString("course_type")); |
|
||||
course.setSemester(rs.getString("semester")); |
|
||||
courses.add(course); |
|
||||
} |
|
||||
} catch (SQLException e) { |
|
||||
System.err.println("获取课程列表失败: " + e.getMessage()); |
|
||||
} |
|
||||
|
|
||||
return courses; |
|
||||
} |
|
||||
|
|
||||
// 获取课程类型分布
|
|
||||
public static Map<String, Integer> getCourseTypeDistribution() { |
|
||||
Map<String, Integer> distribution = new HashMap<>(); |
|
||||
String sql = "SELECT course_type, COUNT(*) as count FROM courses GROUP BY course_type"; |
|
||||
|
|
||||
try (Connection conn = DriverManager.getConnection(DB_URL); |
|
||||
Statement stmt = conn.createStatement(); |
|
||||
ResultSet rs = stmt.executeQuery(sql)) { |
|
||||
|
|
||||
while (rs.next()) { |
|
||||
String type = rs.getString("course_type"); |
|
||||
int count = rs.getInt("count"); |
|
||||
distribution.put(type, count); |
|
||||
} |
|
||||
} catch (SQLException e) { |
|
||||
System.err.println("获取课程类型分布失败: " + e.getMessage()); |
|
||||
} |
|
||||
|
|
||||
return distribution; |
|
||||
} |
|
||||
|
|
||||
// 获取院系分布
|
|
||||
public static Map<String, Integer> getDepartmentDistribution() { |
|
||||
Map<String, Integer> distribution = new HashMap<>(); |
|
||||
String sql = "SELECT department, COUNT(*) as count FROM courses GROUP BY department"; |
|
||||
|
|
||||
try (Connection conn = DriverManager.getConnection(DB_URL); |
|
||||
Statement stmt = conn.createStatement(); |
|
||||
ResultSet rs = stmt.executeQuery(sql)) { |
|
||||
|
|
||||
while (rs.next()) { |
|
||||
String department = rs.getString("department"); |
|
||||
int count = rs.getInt("count"); |
|
||||
distribution.put(department, count); |
|
||||
} |
|
||||
} catch (SQLException e) { |
|
||||
System.err.println("获取院系分布失败: " + e.getMessage()); |
|
||||
} |
|
||||
|
|
||||
return distribution; |
|
||||
} |
|
||||
|
|
||||
// 获取热门课程
|
|
||||
public static List<Map<String, Object>> getTopCourses() { |
|
||||
List<Map<String, Object>> topCourses = new ArrayList<>(); |
|
||||
String sql = "SELECT course_name, teacher, department, capacity, enrolled FROM courses ORDER BY enrolled DESC LIMIT 10"; |
|
||||
|
|
||||
try (Connection conn = DriverManager.getConnection(DB_URL); |
|
||||
Statement stmt = conn.createStatement(); |
|
||||
ResultSet rs = stmt.executeQuery(sql)) { |
|
||||
|
|
||||
while (rs.next()) { |
|
||||
Map<String, Object> course = new HashMap<>(); |
|
||||
course.put("courseName", rs.getString("course_name")); |
|
||||
course.put("teacher", rs.getString("teacher")); |
|
||||
course.put("department", rs.getString("department")); |
|
||||
course.put("capacity", rs.getInt("capacity")); |
|
||||
course.put("enrolled", rs.getInt("enrolled")); |
|
||||
topCourses.add(course); |
|
||||
} |
|
||||
} catch (SQLException e) { |
|
||||
System.err.println("获取热门课程失败: " + e.getMessage()); |
|
||||
} |
|
||||
|
|
||||
return topCourses; |
|
||||
} |
|
||||
|
|
||||
// 保存课程
|
|
||||
public static void saveCourse(Course course) { |
|
||||
String sql = "INSERT INTO courses (course_code, course_name, credit, teacher, department, capacity, enrolled, class_time, class_room, course_type, semester) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)"; |
|
||||
|
|
||||
try (Connection conn = DriverManager.getConnection(DB_URL); |
|
||||
PreparedStatement pstmt = conn.prepareStatement(sql)) { |
|
||||
|
|
||||
pstmt.setString(1, course.getCourseCode()); |
|
||||
pstmt.setString(2, course.getCourseName()); |
|
||||
pstmt.setDouble(3, course.getCredit()); |
|
||||
pstmt.setString(4, course.getTeacher()); |
|
||||
pstmt.setString(5, course.getDepartment()); |
|
||||
pstmt.setInt(6, course.getCapacity()); |
|
||||
pstmt.setInt(7, course.getEnrolled()); |
|
||||
pstmt.setString(8, course.getClassTime()); |
|
||||
pstmt.setString(9, course.getClassRoom()); |
|
||||
pstmt.setString(10, course.getCourseType()); |
|
||||
pstmt.setString(11, course.getSemester()); |
|
||||
|
|
||||
pstmt.executeUpdate(); |
|
||||
} catch (SQLException e) { |
|
||||
System.err.println("保存课程失败: " + e.getMessage()); |
|
||||
} |
|
||||
} |
|
||||
|
|
||||
// 清空课程数据
|
|
||||
public static void clearCourses() { |
|
||||
String sql = "DELETE FROM courses"; |
|
||||
|
|
||||
try (Connection conn = DriverManager.getConnection(DB_URL); |
|
||||
Statement stmt = conn.createStatement()) { |
|
||||
|
|
||||
stmt.executeUpdate(sql); |
|
||||
System.out.println("课程数据清空成功"); |
|
||||
} catch (SQLException e) { |
|
||||
System.err.println("清空课程数据失败: " + e.getMessage()); |
|
||||
} |
|
||||
} |
|
||||
} |
|
||||
@ -1,127 +0,0 @@ |
|||||
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); |
|
||||
} |
|
||||
} |
|
||||
} |
|
||||
@ -1,89 +0,0 @@ |
|||||
package com.example; |
|
||||
|
|
||||
/** |
|
||||
* 泛型Pair类,用于存储两个不同类型的值 |
|
||||
* @param <K> 键的类型 |
|
||||
* @param <V> 值的类型 |
|
||||
*/ |
|
||||
public class Pair<K, V> { |
|
||||
private K key; |
|
||||
private V value; |
|
||||
|
|
||||
/** |
|
||||
* 构造方法 |
|
||||
* @param key 键 |
|
||||
* @param value 值 |
|
||||
*/ |
|
||||
public Pair(K key, V value) { |
|
||||
this.key = key; |
|
||||
this.value = value; |
|
||||
} |
|
||||
|
|
||||
/** |
|
||||
* 获取键 |
|
||||
* @return 键 |
|
||||
*/ |
|
||||
public K getKey() { |
|
||||
return key; |
|
||||
} |
|
||||
|
|
||||
/** |
|
||||
* 设置键 |
|
||||
* @param key 键 |
|
||||
*/ |
|
||||
public void setKey(K key) { |
|
||||
this.key = key; |
|
||||
} |
|
||||
|
|
||||
/** |
|
||||
* 获取值 |
|
||||
* @return 值 |
|
||||
*/ |
|
||||
public V getValue() { |
|
||||
return value; |
|
||||
} |
|
||||
|
|
||||
/** |
|
||||
* 设置值 |
|
||||
* @param value 值 |
|
||||
*/ |
|
||||
public void setValue(V value) { |
|
||||
this.value = value; |
|
||||
} |
|
||||
|
|
||||
@Override |
|
||||
public String toString() { |
|
||||
return "Pair{" + |
|
||||
"key=" + key + |
|
||||
", value=" + value + |
|
||||
'}'; |
|
||||
} |
|
||||
|
|
||||
@Override |
|
||||
public boolean equals(Object o) { |
|
||||
if (this == o) return true; |
|
||||
if (o == null || getClass() != o.getClass()) return false; |
|
||||
Pair<?, ?> pair = (Pair<?, ?>) o; |
|
||||
if (key != null ? !key.equals(pair.key) : pair.key != null) return false; |
|
||||
return value != null ? value.equals(pair.value) : pair.value == null; |
|
||||
} |
|
||||
|
|
||||
@Override |
|
||||
public int hashCode() { |
|
||||
int result = key != null ? key.hashCode() : 0; |
|
||||
result = 31 * result + (value != null ? value.hashCode() : 0); |
|
||||
return result; |
|
||||
} |
|
||||
|
|
||||
/** |
|
||||
* 静态工厂方法,创建Pair实例 |
|
||||
* @param key 键 |
|
||||
* @param value 值 |
|
||||
* @param <K> 键的类型 |
|
||||
* @param <V> 值的类型 |
|
||||
* @return Pair实例 |
|
||||
*/ |
|
||||
public static <K, V> Pair<K, V> of(K key, V value) { |
|
||||
return new Pair<>(key, value); |
|
||||
} |
|
||||
} |
|
||||
Loading…
Reference in new issue