|
|
@ -16,6 +16,10 @@ public class StudentManager { |
|
|
|
this.students = managerTool.getStudentList(); |
|
|
|
this.students = managerTool.getStudentList(); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public boolean hasStudent() { |
|
|
|
|
|
|
|
return !students.isEmpty(); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
/** |
|
|
|
* 增添学生。输入的字符串格式应为 [id] [name] ...[subjectName,score] |
|
|
|
* 增添学生。输入的字符串格式应为 [id] [name] ...[subjectName,score] |
|
|
|
* 如: 23333333 Lag English,100 Math,99 History,98 |
|
|
|
* 如: 23333333 Lag English,100 Math,99 History,98 |
|
|
@ -24,10 +28,14 @@ public class StudentManager { |
|
|
|
*/ |
|
|
|
*/ |
|
|
|
public void addStudent(String input) { |
|
|
|
public void addStudent(String input) { |
|
|
|
String[] split = input.split(" "); |
|
|
|
String[] split = input.split(" "); |
|
|
|
|
|
|
|
try { |
|
|
|
long id = Long.parseLong(split[0]); |
|
|
|
long id = Long.parseLong(split[0]); |
|
|
|
String name = split[1]; |
|
|
|
String name = split[1]; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (managerTool.getStudent(id) != null && managerTool.getStudent(name) != null) { |
|
|
|
|
|
|
|
return; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
HashMap<String, Integer> score = new HashMap<>(); |
|
|
|
HashMap<String, Integer> score = new HashMap<>(); |
|
|
|
String[] scoreInput; |
|
|
|
String[] scoreInput; |
|
|
|
for (int i = 2; i < split.length; i++) { |
|
|
|
for (int i = 2; i < split.length; i++) { |
|
|
@ -36,6 +44,10 @@ public class StudentManager { |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
managerTool.addStudent(id, name, score); |
|
|
|
managerTool.addStudent(id, name, score); |
|
|
|
|
|
|
|
} catch (Exception e) { |
|
|
|
|
|
|
|
e.printStackTrace(); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
/** |
|
|
@ -43,7 +55,7 @@ public class StudentManager { |
|
|
|
* |
|
|
|
* |
|
|
|
* @param id 学生id,long格式 |
|
|
|
* @param id 学生id,long格式 |
|
|
|
*/ |
|
|
|
*/ |
|
|
|
protected void removeStudent(long id) { |
|
|
|
public void removeStudent(long id) { |
|
|
|
managerTool.removeStudent(id); |
|
|
|
managerTool.removeStudent(id); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
@ -52,7 +64,7 @@ public class StudentManager { |
|
|
|
* |
|
|
|
* |
|
|
|
* @param name 学生姓名,long格式 |
|
|
|
* @param name 学生姓名,long格式 |
|
|
|
*/ |
|
|
|
*/ |
|
|
|
protected void removeStudent(String name) { |
|
|
|
public void removeStudent(String name) { |
|
|
|
managerTool.removeStudent(name); |
|
|
|
managerTool.removeStudent(name); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
@ -96,7 +108,7 @@ public class StudentManager { |
|
|
|
HashMap<String, Integer> scores = new HashMap<>(); |
|
|
|
HashMap<String, Integer> scores = new HashMap<>(); |
|
|
|
|
|
|
|
|
|
|
|
for (String subject : subjects) { |
|
|
|
for (String subject : subjects) { |
|
|
|
scores.put(subject, getSubjectScore(subject)); |
|
|
|
scores.put(subject, this.getSubjectScore(subject)); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
return scores; |
|
|
|
return scores; |
|
|
@ -112,12 +124,22 @@ public class StudentManager { |
|
|
|
HashMap<String, Float> scores = new HashMap<>(); |
|
|
|
HashMap<String, Float> scores = new HashMap<>(); |
|
|
|
|
|
|
|
|
|
|
|
for (String subject : subjects) { |
|
|
|
for (String subject : subjects) { |
|
|
|
scores.put(subject, getSubjectAvgScore(subject)); |
|
|
|
scores.put(subject, this.getSubjectAvgScore(subject)); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
return scores; |
|
|
|
return scores; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
|
|
|
* 获取某学生总成绩 |
|
|
|
|
|
|
|
* |
|
|
|
|
|
|
|
* @param student 欲获取的学生 |
|
|
|
|
|
|
|
* @return 该学生所有科目总成绩 |
|
|
|
|
|
|
|
*/ |
|
|
|
|
|
|
|
public int getStudentGeneralScore(Student student) { |
|
|
|
|
|
|
|
return student.getGeneralScore(); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
/** |
|
|
|
* 获取所有科目 |
|
|
|
* 获取所有科目 |
|
|
|
* |
|
|
|
* |
|
|
@ -132,19 +154,21 @@ public class StudentManager { |
|
|
|
* |
|
|
|
* |
|
|
|
* @return 名次表字符串 |
|
|
|
* @return 名次表字符串 |
|
|
|
*/ |
|
|
|
*/ |
|
|
|
public String generateRankingTable() { |
|
|
|
public ArrayList<String> generateRankingTable() { |
|
|
|
StringBuilder stringBuilder = new StringBuilder("Ranking | Name | General Score\n"); |
|
|
|
ArrayList<String> rankingTable = new ArrayList<>(); |
|
|
|
ArrayList<Student> sortStudentList = managerTool.getSortedStudentList(ManagerTool.SORT_COMPARE_BY_GENERAL_SCORE); |
|
|
|
ArrayList<Student> sortStudentList = managerTool.getSortedStudentList(ManagerTool.SORT_COMPARE_BY_GENERAL_SCORE); |
|
|
|
|
|
|
|
|
|
|
|
for (int i = 0; i < sortStudentList.size(); i++) { |
|
|
|
for (int i = 0; i < sortStudentList.size(); i++) { |
|
|
|
|
|
|
|
StringBuilder stringBuilder = new StringBuilder(); |
|
|
|
stringBuilder |
|
|
|
stringBuilder |
|
|
|
.append(i + 1).append(" | ") |
|
|
|
.append(i + 1).append(" | ") |
|
|
|
.append(sortStudentList.get(i).getName()).append(" | ") |
|
|
|
.append(sortStudentList.get(i).getName()).append(" | ") |
|
|
|
.append(students.get(i).getGeneralScore()) |
|
|
|
.append(students.get(i).getGeneralScore()); |
|
|
|
.append('\n'); |
|
|
|
|
|
|
|
|
|
|
|
rankingTable.add(stringBuilder.toString()); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
return stringBuilder.toString(); |
|
|
|
return rankingTable; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
/** |
|
|
@ -152,19 +176,15 @@ public class StudentManager { |
|
|
|
* |
|
|
|
* |
|
|
|
* @return 成绩表字符串 |
|
|
|
* @return 成绩表字符串 |
|
|
|
*/ |
|
|
|
*/ |
|
|
|
public String generateScoreTableById() { |
|
|
|
public ArrayList<String> generateScoreTableById() { |
|
|
|
StringBuilder stringBuilder = new StringBuilder("ID | Name | General Score | Subject1: score Subject2: score ...\n"); |
|
|
|
ArrayList<String> scoreTable = new ArrayList<>(); |
|
|
|
ArrayList<Student> sortStudentList = managerTool.getSortedStudentList(ManagerTool.SORT_COMPARE_BY_ID); |
|
|
|
ArrayList<Student> sortStudentList = managerTool.getSortedStudentList(ManagerTool.SORT_COMPARE_BY_ID); |
|
|
|
|
|
|
|
|
|
|
|
for (Student student : sortStudentList) { |
|
|
|
for (Student student : sortStudentList) { |
|
|
|
stringBuilder |
|
|
|
scoreTable.add(this.getStudentInfo(student)); |
|
|
|
.append(student.getId()).append(" | ") |
|
|
|
|
|
|
|
.append(student.getName()).append(" | ") |
|
|
|
|
|
|
|
.append(student.getGeneralScore()).append(" | ") |
|
|
|
|
|
|
|
.append(listScore(student)).append('\n'); |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
return stringBuilder.toString(); |
|
|
|
return scoreTable; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
/** |
|
|
@ -172,17 +192,30 @@ public class StudentManager { |
|
|
|
* |
|
|
|
* |
|
|
|
* @return 成绩表字符串 |
|
|
|
* @return 成绩表字符串 |
|
|
|
*/ |
|
|
|
*/ |
|
|
|
public String generateScoreTableByName() { |
|
|
|
public ArrayList<String> generateScoreTableByName() { |
|
|
|
StringBuilder stringBuilder = new StringBuilder("Name | Id | General Score | Subject1: score Subject2: score ...\n"); |
|
|
|
ArrayList<String> scoreTable = new ArrayList<>(); |
|
|
|
ArrayList<Student> sortStudentList = managerTool.getSortedStudentList(ManagerTool.SORT_COMPARE_BY_NAME); |
|
|
|
ArrayList<Student> sortStudentList = managerTool.getSortedStudentList(ManagerTool.SORT_COMPARE_BY_NAME); |
|
|
|
|
|
|
|
|
|
|
|
for (Student student : sortStudentList) { |
|
|
|
for (Student student : sortStudentList) { |
|
|
|
|
|
|
|
scoreTable.add(this.getStudentInfo(student)); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
return scoreTable; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
|
|
|
* 获取学生信息条目 |
|
|
|
|
|
|
|
* |
|
|
|
|
|
|
|
* @param student 欲获取学生 |
|
|
|
|
|
|
|
* @return 学生信息 |
|
|
|
|
|
|
|
*/ |
|
|
|
|
|
|
|
public String getStudentInfo(Student student) { |
|
|
|
|
|
|
|
StringBuilder stringBuilder = new StringBuilder(); |
|
|
|
stringBuilder |
|
|
|
stringBuilder |
|
|
|
.append(student.getName()).append(" | ") |
|
|
|
|
|
|
|
.append(student.getId()).append(" | ") |
|
|
|
.append(student.getId()).append(" | ") |
|
|
|
.append(student.getGeneralScore()).append(" | ") |
|
|
|
.append(student.getName()).append(" | ") |
|
|
|
.append(listScore(student)).append('\n'); |
|
|
|
.append(this.getStudentGeneralScore(student)).append(" | ") |
|
|
|
} |
|
|
|
.append(listScore(student)); |
|
|
|
|
|
|
|
|
|
|
|
return stringBuilder.toString(); |
|
|
|
return stringBuilder.toString(); |
|
|
|
} |
|
|
|
} |
|
|
@ -200,48 +233,83 @@ public class StudentManager { |
|
|
|
for (String subject : subjects) { |
|
|
|
for (String subject : subjects) { |
|
|
|
stringBuilder |
|
|
|
stringBuilder |
|
|
|
.append(subject).append(": ") |
|
|
|
.append(subject).append(": ") |
|
|
|
.append(student.getScore().get(subject)).append(' '); |
|
|
|
.append(student.getScore().get(subject)).append(" "); |
|
|
|
} |
|
|
|
} |
|
|
|
return stringBuilder.toString(); |
|
|
|
return stringBuilder.toString(); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
/** |
|
|
|
* 列出所有科目的成绩信息,包括总分、平均分 |
|
|
|
* 列出所有科目的成绩信息,包括总分、平均分 |
|
|
|
|
|
|
|
* |
|
|
|
* @return 信息字符串 |
|
|
|
* @return 信息字符串 |
|
|
|
*/ |
|
|
|
*/ |
|
|
|
public String listAllSubjectScore() { |
|
|
|
public ArrayList<String> generateAllSubjectInfo() { |
|
|
|
StringBuilder stringBuilder = new StringBuilder(); |
|
|
|
ArrayList<String> subjects = this.getSubjects(); |
|
|
|
ArrayList<String> subjects = getSubjects(); |
|
|
|
ArrayList<String> record = new ArrayList<>(); |
|
|
|
|
|
|
|
|
|
|
|
for (String subject : subjects) { |
|
|
|
for (String subject : subjects) { |
|
|
|
|
|
|
|
StringBuilder stringBuilder = new StringBuilder(); |
|
|
|
stringBuilder |
|
|
|
stringBuilder |
|
|
|
.append(subject).append(" | General Score: ") |
|
|
|
.append(subject).append(" | General Score: ") |
|
|
|
.append(this.getSubjectScore(subject)).append(" | Avg Score: ") |
|
|
|
.append(this.getSubjectScore(subject)).append(" | Avg Score: ") |
|
|
|
.append(this.getSubjectAvgScore(subject)).append('\n'); |
|
|
|
.append(this.getSubjectAvgScore(subject)); |
|
|
|
|
|
|
|
record.add(stringBuilder.toString()); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
return stringBuilder.toString(); |
|
|
|
return record; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
/** |
|
|
|
* 生成总的学生及科目成绩信息 |
|
|
|
* 生成总的学生及科目成绩信息 |
|
|
|
|
|
|
|
* |
|
|
|
* @return 信息字符串 |
|
|
|
* @return 信息字符串 |
|
|
|
*/ |
|
|
|
*/ |
|
|
|
public String generateAllInformation() { |
|
|
|
public String generateAllInformation() { |
|
|
|
StringBuilder stringBuilder = new StringBuilder(); |
|
|
|
StringBuilder stringBuilder = new StringBuilder(); |
|
|
|
stringBuilder |
|
|
|
stringBuilder |
|
|
|
.append("------------------------------------") |
|
|
|
.append("------------------------------------\n") |
|
|
|
.append(" All Student Information ") |
|
|
|
.append(" All Student Information \n") |
|
|
|
.append("------------------------------------").append('\n') |
|
|
|
.append("------------------------------------\n"); |
|
|
|
.append(this.generateScoreTableByName()).append('\n') |
|
|
|
|
|
|
|
.append("------------------------------------") |
|
|
|
ArrayList<String> studentTable = this.generateScoreTableByName(); |
|
|
|
.append(" All Subject Information ") |
|
|
|
for (String record : studentTable) { |
|
|
|
.append("------------------------------------").append('\n') |
|
|
|
stringBuilder.append(record).append('\n'); |
|
|
|
.append(this.listAllSubjectScore()); |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
stringBuilder |
|
|
|
|
|
|
|
.append("------------------------------------\n") |
|
|
|
|
|
|
|
.append(" All Subject Information \n") |
|
|
|
|
|
|
|
.append("------------------------------------\n"); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
ArrayList<String> subjectTable = this.generateAllSubjectInfo(); |
|
|
|
|
|
|
|
for (String record : subjectTable) { |
|
|
|
|
|
|
|
stringBuilder.append(record).append('\n'); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
return stringBuilder.toString(); |
|
|
|
return stringBuilder.toString(); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
} |
|
|
|
public ArrayList<Student> getStudents() { |
|
|
|
|
|
|
|
return students; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
|
|
|
* 通过名字获取学生 |
|
|
|
|
|
|
|
* |
|
|
|
|
|
|
|
* @param name 学生姓名 |
|
|
|
|
|
|
|
* @return 学生类 |
|
|
|
|
|
|
|
*/ |
|
|
|
|
|
|
|
public Student getStudent(String name) { |
|
|
|
|
|
|
|
return managerTool.getStudent(name); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
|
|
|
* 通过学号获取学生 |
|
|
|
|
|
|
|
* |
|
|
|
|
|
|
|
* @param id 学号 |
|
|
|
|
|
|
|
* @return 学生类 |
|
|
|
|
|
|
|
*/ |
|
|
|
|
|
|
|
public Student getStudent(long id) { |
|
|
|
|
|
|
|
return managerTool.getStudent(id); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |