|
|
@ -3,10 +3,12 @@ package me.lensfrex.manager.data; |
|
|
|
import java.util.ArrayList; |
|
|
|
import java.util.ArrayList; |
|
|
|
import java.util.HashMap; |
|
|
|
import java.util.HashMap; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
|
|
|
* 对Student类的操作的上层封装,有较为多的操作 |
|
|
|
|
|
|
|
*/ |
|
|
|
public class StudentManager { |
|
|
|
public class StudentManager { |
|
|
|
private final ArrayList<Student> students = new ArrayList<>(); |
|
|
|
private final ArrayList<Student> students = new ArrayList<>(); |
|
|
|
private final ManagerTool managerTool = new ManagerTool(students); |
|
|
|
private final ManagerTool managerTool = new ManagerTool(students); |
|
|
|
private ArrayList<String> subjects = new ArrayList<>(); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
/** |
|
|
|
* 增添学生。输入的字符串格式应为 [id] [name] ...[subjectName,score] |
|
|
|
* 增添学生。输入的字符串格式应为 [id] [name] ...[subjectName,score] |
|
|
@ -77,7 +79,7 @@ public class StudentManager { |
|
|
|
return scores; |
|
|
|
return scores; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
/**- |
|
|
|
* 获取每门科目的平均成绩 |
|
|
|
* 获取每门科目的平均成绩 |
|
|
|
* |
|
|
|
* |
|
|
|
* @return 包含每门课总成绩的HashMap,key为科目名称,value为该科目的平均成绩 |
|
|
|
* @return 包含每门课总成绩的HashMap,key为科目名称,value为该科目的平均成绩 |
|
|
@ -92,4 +94,80 @@ public class StudentManager { |
|
|
|
|
|
|
|
|
|
|
|
return scores; |
|
|
|
return scores; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
|
|
|
* 按学生总分由高到低生成名次表 |
|
|
|
|
|
|
|
* |
|
|
|
|
|
|
|
* @return 名次表字符串 |
|
|
|
|
|
|
|
*/ |
|
|
|
|
|
|
|
public String generateRankingTable() { |
|
|
|
|
|
|
|
StringBuilder stringBuilder = new StringBuilder("Ranking | Name | General Score\n"); |
|
|
|
|
|
|
|
ArrayList<Student> sortStudentList = managerTool.getSortedStudentList(ManagerTool.SORT_COMPARE_BY_GENERAL_SCORE); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
for (int i = 0; i < sortStudentList.size(); i++) { |
|
|
|
|
|
|
|
stringBuilder |
|
|
|
|
|
|
|
.append(i + 1).append(" | ") |
|
|
|
|
|
|
|
.append(sortStudentList.get(i).getName()).append(" | ") |
|
|
|
|
|
|
|
.append(students.get(i).getGeneralScore()) |
|
|
|
|
|
|
|
.append('\n'); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
return stringBuilder.toString(); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
|
|
|
* 按学生学号由小到大生成成绩表 |
|
|
|
|
|
|
|
* |
|
|
|
|
|
|
|
* @return 成绩表字符串 |
|
|
|
|
|
|
|
*/ |
|
|
|
|
|
|
|
public String generateScoreTableById() { |
|
|
|
|
|
|
|
StringBuilder stringBuilder = new StringBuilder("ID | Name | General Score | Subject1: score Subject2: score ...\n"); |
|
|
|
|
|
|
|
ArrayList<Student> sortStudentList = managerTool.getSortedStudentList(ManagerTool.SORT_COMPARE_BY_GENERAL_SCORE); |
|
|
|
|
|
|
|
ArrayList<String> subjects = managerTool.getAllSubjects(); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
for (Student student : sortStudentList) { |
|
|
|
|
|
|
|
stringBuilder |
|
|
|
|
|
|
|
.append(student.getId()).append(" | ") |
|
|
|
|
|
|
|
.append(student.getName()).append(" | ") |
|
|
|
|
|
|
|
.append(student.getGeneralScore()).append(" | "); |
|
|
|
|
|
|
|
for (String subject : subjects) { |
|
|
|
|
|
|
|
stringBuilder |
|
|
|
|
|
|
|
.append(subject).append(": ") |
|
|
|
|
|
|
|
.append(student.getScore().get(subject)).append(' '); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
stringBuilder.append('\n'); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
return stringBuilder.toString(); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
|
|
|
* 按学生学号由小到大生成成绩表 |
|
|
|
|
|
|
|
* |
|
|
|
|
|
|
|
* @return 成绩表字符串 |
|
|
|
|
|
|
|
*/ |
|
|
|
|
|
|
|
public String generateScoreTableByName() { |
|
|
|
|
|
|
|
StringBuilder stringBuilder = new StringBuilder("Name | Id | General Score | Subject1/score Subject2: score ...\n"); |
|
|
|
|
|
|
|
ArrayList<Student> sortStudentList = managerTool.getSortedStudentList(ManagerTool.SORT_COMPARE_BY_GENERAL_SCORE); |
|
|
|
|
|
|
|
ArrayList<String> subjects = managerTool.getAllSubjects(); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
for (Student student : sortStudentList) { |
|
|
|
|
|
|
|
stringBuilder |
|
|
|
|
|
|
|
.append(student.getName()).append(" | ") |
|
|
|
|
|
|
|
.append(student.getId()).append(" | ") |
|
|
|
|
|
|
|
.append(student.getGeneralScore()).append(" | "); |
|
|
|
|
|
|
|
for (String subject : subjects) { |
|
|
|
|
|
|
|
stringBuilder |
|
|
|
|
|
|
|
.append(subject).append(": ") |
|
|
|
|
|
|
|
.append(student.getScore().get(subject)).append(' '); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
stringBuilder.append('\n'); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
return stringBuilder.toString(); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|