新增方法:

- 删除一个学生
- 列出所有科目的成绩信息
- 生成总的学生及科目成绩信息
main
lensfrex 3 years ago
parent 7b9dc8df43
commit e2e7646666
Signed by: lensfrex
GPG Key ID: 0F69A0A2FBEE98A0
  1. 9
      src/main/java/me/lensfrex/manager/data/manager/ManagerTool.java
  2. 67
      src/main/java/me/lensfrex/manager/data/manager/StudentManager.java

@ -1,6 +1,7 @@
package me.lensfrex.manager.data.manager; package me.lensfrex.manager.data.manager;
import me.lensfrex.manager.data.Student; import me.lensfrex.manager.data.Student;
import me.lensfrex.manager.utils.DataLoader;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.HashMap; import java.util.HashMap;
@ -12,8 +13,12 @@ import java.util.Map;
public class ManagerTool { public class ManagerTool {
private final ArrayList<Student> students; private final ArrayList<Student> students;
protected ManagerTool(ArrayList<Student> studentData) { protected ManagerTool() {
this.students = studentData; this.students = new DataLoader().load();
}
public ArrayList<Student> getStudentList() {
return students;
} }
/** /**

@ -9,8 +9,12 @@ import java.util.HashMap;
* 对Student类的操作的上层封装有较为多的操作 * 对Student类的操作的上层封装有较为多的操作
*/ */
public class StudentManager { public class StudentManager {
private final ArrayList<Student> students = new ArrayList<>(); private final ArrayList<Student> students;
private final ManagerTool managerTool = new ManagerTool(students); private final ManagerTool managerTool = new ManagerTool();
public StudentManager() {
this.students = managerTool.getStudentList();
}
/** /**
* 增添学生输入的字符串格式应为 [id] [name] ...[subjectName,score] * 增添学生输入的字符串格式应为 [id] [name] ...[subjectName,score]
@ -34,6 +38,23 @@ public class StudentManager {
managerTool.addStudent(id, name, score); managerTool.addStudent(id, name, score);
} }
/**
* 删除一个学生按ID
*
* @param id 学生idlong格式
*/
protected void removeStudent(long id) {
managerTool.removeStudent(id);
}
/**
* 删除一个学生按姓名
*
* @param name 学生姓名long格式
*/
protected void removeStudent(String name) {
managerTool.removeStudent(name);
}
// 要是Java能像go语言那样返回两个返回值就好了... // 要是Java能像go语言那样返回两个返回值就好了...
// 这样就能同时返回平均值和总值了... // 这样就能同时返回平均值和总值了...
@ -99,6 +120,7 @@ public class StudentManager {
/** /**
* 获取所有科目 * 获取所有科目
*
* @return 包含有科目名称的ArrayList * @return 包含有科目名称的ArrayList
*/ */
public ArrayList<String> getSubjects() { public ArrayList<String> getSubjects() {
@ -173,7 +195,7 @@ public class StudentManager {
*/ */
private String listScore(Student student) { private String listScore(Student student) {
StringBuilder stringBuilder = new StringBuilder(); StringBuilder stringBuilder = new StringBuilder();
ArrayList<String> subjects = managerTool.getAllSubjects(); ArrayList<String> subjects = getSubjects();
for (String subject : subjects) { for (String subject : subjects) {
stringBuilder stringBuilder
@ -183,4 +205,43 @@ public class StudentManager {
return stringBuilder.toString(); return stringBuilder.toString();
} }
/**
* 列出所有科目的成绩信息包括总分平均分
* @return 信息字符串
*/
public String listAllSubjectScore() {
StringBuilder stringBuilder = new StringBuilder();
ArrayList<String> 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();
}
} }

Loading…
Cancel
Save