|
|
|
|
@ -0,0 +1,112 @@
|
|
|
|
|
package com.studentmanagement.view;
|
|
|
|
|
|
|
|
|
|
import com.studentmanagement.model.Student;
|
|
|
|
|
import java.util.List;
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 学生控制台视图实现,使用命令行展示学生信息
|
|
|
|
|
* 实现了StudentView接口
|
|
|
|
|
*/
|
|
|
|
|
public class StudentConsoleView implements StudentView {
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
public void displayStudent(Student student) {
|
|
|
|
|
if (student == null) {
|
|
|
|
|
System.out.println("学生不存在");
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
System.out.println("============ 学生详情 ============");
|
|
|
|
|
System.out.println("ID: " + student.getId());
|
|
|
|
|
System.out.println("姓名: " + student.getName());
|
|
|
|
|
System.out.println("年龄: " + student.getAge());
|
|
|
|
|
System.out.println("课程: " + student.getCourse());
|
|
|
|
|
System.out.println("成绩: " + student.getGrade());
|
|
|
|
|
System.out.println("==================================");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
public void displayStudentList(List<Student> students) {
|
|
|
|
|
if (students == null || students.isEmpty()) {
|
|
|
|
|
System.out.println("没有找到学生信息");
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
System.out.println("============================================ 学生列表 ============================================");
|
|
|
|
|
System.out.printf("%5s %-10s %5s %-20s %10s\n", "ID", "姓名", "年龄", "课程", "成绩");
|
|
|
|
|
System.out.println("===============================================================================================");
|
|
|
|
|
|
|
|
|
|
for (Student student : students) {
|
|
|
|
|
System.out.printf("%5d %-10s %5d %-20s %10.2f\n",
|
|
|
|
|
student.getId(),
|
|
|
|
|
student.getName(),
|
|
|
|
|
student.getAge(),
|
|
|
|
|
student.getCourse(),
|
|
|
|
|
student.getGrade());
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
System.out.println("===============================================================================================");
|
|
|
|
|
System.out.println("共找到 " + students.size() + " 名学生");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
public void displaySuccessMessage(String message) {
|
|
|
|
|
System.out.println("✅ 成功: " + message);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
public void displayErrorMessage(String message) {
|
|
|
|
|
System.err.println("❌ 错误: " + message);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
public void displayStatistics(String message) {
|
|
|
|
|
System.out.println("📊 " + message);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 显示菜单选项
|
|
|
|
|
*/
|
|
|
|
|
public void displayMenu() {
|
|
|
|
|
System.out.println("\n=========================================");
|
|
|
|
|
System.out.println(" 学生管理系统");
|
|
|
|
|
System.out.println("=========================================");
|
|
|
|
|
System.out.println("1. 查看所有学生");
|
|
|
|
|
System.out.println("2. 根据ID查找学生");
|
|
|
|
|
System.out.println("3. 添加新学生");
|
|
|
|
|
System.out.println("4. 更新学生信息");
|
|
|
|
|
System.out.println("5. 删除学生");
|
|
|
|
|
System.out.println("6. 根据课程查找学生");
|
|
|
|
|
System.out.println("7. 查找成绩优秀的学生(>=90分)");
|
|
|
|
|
System.out.println("8. 查看课程平均成绩");
|
|
|
|
|
System.out.println("9. 查看学生平均年龄");
|
|
|
|
|
System.out.println(0 + ". 退出系统");
|
|
|
|
|
System.out.println("=========================================");
|
|
|
|
|
System.out.print("请选择操作 [0-9]: ");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 显示分隔线
|
|
|
|
|
*/
|
|
|
|
|
public void displaySeparator() {
|
|
|
|
|
System.out.println("\n-----------------------------------------");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 显示欢迎信息
|
|
|
|
|
*/
|
|
|
|
|
public void displayWelcome() {
|
|
|
|
|
System.out.println("\n=========================================");
|
|
|
|
|
System.out.println(" 欢迎使用学生管理系统");
|
|
|
|
|
System.out.println("=========================================");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 显示退出信息
|
|
|
|
|
*/
|
|
|
|
|
public void displayExit() {
|
|
|
|
|
System.out.println("\n=========================================");
|
|
|
|
|
System.out.println(" 感谢使用学生管理系统,再见!");
|
|
|
|
|
System.out.println("=========================================");
|
|
|
|
|
}
|
|
|
|
|
}
|