diff --git a/src/main/java/me/lensfrex/manager/data/manager/ManagerTool.java b/src/main/java/me/lensfrex/manager/data/manager/ManagerTool.java index 7e65ad6..64678ae 100644 --- a/src/main/java/me/lensfrex/manager/data/manager/ManagerTool.java +++ b/src/main/java/me/lensfrex/manager/data/manager/ManagerTool.java @@ -1,6 +1,7 @@ package me.lensfrex.manager.data.manager; import me.lensfrex.manager.data.Student; +import me.lensfrex.manager.utils.DataLoader; import java.util.ArrayList; import java.util.HashMap; @@ -12,8 +13,12 @@ import java.util.Map; public class ManagerTool { private final ArrayList students; - protected ManagerTool(ArrayList studentData) { - this.students = studentData; + protected ManagerTool() { + this.students = new DataLoader().load(); + } + + public ArrayList getStudentList() { + return students; } /** diff --git a/src/main/java/me/lensfrex/manager/data/manager/StudentManager.java b/src/main/java/me/lensfrex/manager/data/manager/StudentManager.java index 35c47b9..b71d860 100644 --- a/src/main/java/me/lensfrex/manager/data/manager/StudentManager.java +++ b/src/main/java/me/lensfrex/manager/data/manager/StudentManager.java @@ -9,8 +9,12 @@ import java.util.HashMap; * 对Student类的操作的上层封装,有较为多的操作 */ public class StudentManager { - private final ArrayList students = new ArrayList<>(); - private final ManagerTool managerTool = new ManagerTool(students); + private final ArrayList students; + private final ManagerTool managerTool = new ManagerTool(); + + public StudentManager() { + this.students = managerTool.getStudentList(); + } /** * 增添学生。输入的字符串格式应为 [id] [name] ...[subjectName,score] @@ -34,6 +38,23 @@ public class StudentManager { managerTool.addStudent(id, name, score); } + /** + * 删除一个学生(按ID) + * + * @param id 学生id,long格式 + */ + protected void removeStudent(long id) { + managerTool.removeStudent(id); + } + + /** + * 删除一个学生(按姓名) + * + * @param name 学生姓名,long格式 + */ + protected void removeStudent(String name) { + managerTool.removeStudent(name); + } // 要是Java能像go语言那样返回两个返回值就好了... // 这样就能同时返回平均值和总值了... @@ -98,7 +119,8 @@ public class StudentManager { } /** - * 获取所有科目 + * 获取所有科目 + * * @return 包含有科目名称的ArrayList */ public ArrayList getSubjects() { @@ -173,7 +195,7 @@ public class StudentManager { */ private String listScore(Student student) { StringBuilder stringBuilder = new StringBuilder(); - ArrayList subjects = managerTool.getAllSubjects(); + ArrayList subjects = getSubjects(); for (String subject : subjects) { stringBuilder @@ -183,4 +205,43 @@ public class StudentManager { return stringBuilder.toString(); } + /** + * 列出所有科目的成绩信息,包括总分、平均分 + * @return 信息字符串 + */ + public String listAllSubjectScore() { + StringBuilder stringBuilder = new StringBuilder(); + ArrayList subjects = getSubjects(); + + for (String subject : subjects) { + stringBuilder + .append(subject).append(" | General Score: ") + .append(this.getSubjectScore(subject)).append(" | Avg Score: ") + .append(this.getSubjectAvgScore(subject)).append('\n'); + } + + return stringBuilder.toString(); + } + + /** + * 生成总的学生及科目成绩信息 + * @return 信息字符串 + */ + public String generateAllInformation() { + StringBuilder stringBuilder = new StringBuilder(); + stringBuilder + .append("------------------------------------") + .append(" All Student Information ") + .append("------------------------------------").append('\n') + .append(this.generateScoreTableByName()).append('\n') + .append("------------------------------------") + .append(" All Subject Information ") + .append("------------------------------------").append('\n') + .append(this.listAllSubjectScore()); + + return stringBuilder.toString(); + } + } + +