|
|
|
@ -1,4 +1,6 @@ |
|
|
|
|
package me.lensfrex.manager.data; |
|
|
|
|
package me.lensfrex.manager.data.manager; |
|
|
|
|
|
|
|
|
|
import me.lensfrex.manager.data.Student; |
|
|
|
|
|
|
|
|
|
import java.util.ArrayList; |
|
|
|
|
import java.util.HashMap; |
|
|
|
@ -10,7 +12,7 @@ import java.util.Map; |
|
|
|
|
public class ManagerTool { |
|
|
|
|
private final ArrayList<Student> students; |
|
|
|
|
|
|
|
|
|
public ManagerTool(ArrayList<Student> studentData) { |
|
|
|
|
protected ManagerTool(ArrayList<Student> studentData) { |
|
|
|
|
this.students = studentData; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
@ -21,7 +23,7 @@ public class ManagerTool { |
|
|
|
|
* @param name 学生姓名 |
|
|
|
|
* @param score 学生成绩,map中key为科目名称,value为相应的成绩 |
|
|
|
|
*/ |
|
|
|
|
public void addStudent(long id, String name, Map<String, Integer> score) { |
|
|
|
|
protected void addStudent(long id, String name, Map<String, Integer> score) { |
|
|
|
|
Student student = new Student(id, name, score); |
|
|
|
|
students.add(student); |
|
|
|
|
} |
|
|
|
@ -31,7 +33,7 @@ public class ManagerTool { |
|
|
|
|
* |
|
|
|
|
* @param id 学生id,long格式 |
|
|
|
|
*/ |
|
|
|
|
public void removeStudent(long id) { |
|
|
|
|
protected void removeStudent(long id) { |
|
|
|
|
students.remove(getStudent(id)); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
@ -40,7 +42,7 @@ public class ManagerTool { |
|
|
|
|
* |
|
|
|
|
* @param name 学生姓名,long格式 |
|
|
|
|
*/ |
|
|
|
|
public void removeStudent(String name) { |
|
|
|
|
protected void removeStudent(String name) { |
|
|
|
|
students.remove(getStudent(name)); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
@ -50,7 +52,7 @@ public class ManagerTool { |
|
|
|
|
* @param name 学生姓名 |
|
|
|
|
* @return 学生的信息,若无该学生则返回null |
|
|
|
|
*/ |
|
|
|
|
public Student getStudent(String name) { |
|
|
|
|
protected Student getStudent(String name) { |
|
|
|
|
for (Student student : students) { |
|
|
|
|
if (student.getName().equals(name)) { |
|
|
|
|
return student; |
|
|
|
@ -65,7 +67,7 @@ public class ManagerTool { |
|
|
|
|
* @param id 学生学号 |
|
|
|
|
* @return 学生信息,若无该学生则返回null |
|
|
|
|
*/ |
|
|
|
|
public Student getStudent(long id) { |
|
|
|
|
protected Student getStudent(long id) { |
|
|
|
|
for (Student student : students) { |
|
|
|
|
if (student.getId() == id) { |
|
|
|
|
return student; |
|
|
|
@ -74,9 +76,9 @@ public class ManagerTool { |
|
|
|
|
return null; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
public static final int SORT_COMPARE_BY_NAME = 0; |
|
|
|
|
public static final int SORT_COMPARE_BY_ID = 1; |
|
|
|
|
public static final int SORT_COMPARE_BY_GENERAL_SCORE = 2; |
|
|
|
|
protected static final int SORT_COMPARE_BY_NAME = 0; |
|
|
|
|
protected static final int SORT_COMPARE_BY_ID = 1; |
|
|
|
|
protected static final int SORT_COMPARE_BY_GENERAL_SCORE = 2; |
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
* 对学生列表进行排序 |
|
|
|
@ -85,7 +87,7 @@ public class ManagerTool { |
|
|
|
|
* 可根据名字字典顺序(升序,0)、学生学号(升序,1)以及总成绩(降序,2)进行排序。 |
|
|
|
|
* @return 排序后的学生列表 |
|
|
|
|
*/ |
|
|
|
|
public ArrayList<Student> getSortedStudentList(int compareMethod) { |
|
|
|
|
protected ArrayList<Student> getSortedStudentList(int compareMethod) { |
|
|
|
|
switch (compareMethod) { |
|
|
|
|
case SORT_COMPARE_BY_NAME: |
|
|
|
|
students.sort(Student.compareByName); |
|
|
|
@ -108,7 +110,7 @@ public class ManagerTool { |
|
|
|
|
* @param subject 欲获取的科目信息 |
|
|
|
|
* @return 包含成绩信息的HashMap,key为学生姓名,value为该科成绩数据 |
|
|
|
|
*/ |
|
|
|
|
public HashMap<String, Integer> getSubjectScores(String subject) { |
|
|
|
|
protected HashMap<String, Integer> getSubjectScores(String subject) { |
|
|
|
|
HashMap<String, Integer> scores = new HashMap<>(); |
|
|
|
|
for (Student student : students) { |
|
|
|
|
scores.put(student.getName(), student.getScore().get(subject)); |
|
|
|
@ -121,7 +123,7 @@ public class ManagerTool { |
|
|
|
|
* |
|
|
|
|
* @return 包含全班所有同学成绩的HashMap,key为姓名,value为总成绩数据 |
|
|
|
|
*/ |
|
|
|
|
public HashMap<String, Integer> getAllStudentScores() { |
|
|
|
|
protected HashMap<String, Integer> getAllStudentScores() { |
|
|
|
|
HashMap<String, Integer> result = new HashMap<>(); |
|
|
|
|
|
|
|
|
|
int scoreSum = 0; |
|
|
|
@ -140,7 +142,7 @@ public class ManagerTool { |
|
|
|
|
* |
|
|
|
|
* @return 包含有排名信息的HashMap,key为姓名,value为相应的排名 |
|
|
|
|
*/ |
|
|
|
|
public HashMap<String, Integer> generateRanking() { |
|
|
|
|
protected HashMap<String, Integer> generateRanking() { |
|
|
|
|
HashMap<String, Integer> ranking = new HashMap<>(); |
|
|
|
|
this.getSortedStudentList(SORT_COMPARE_BY_GENERAL_SCORE); |
|
|
|
|
|
|
|
|
@ -156,7 +158,7 @@ public class ManagerTool { |
|
|
|
|
* |
|
|
|
|
* @return 包含所有科目名称的Arraylist,若无学生信息则返回null |
|
|
|
|
*/ |
|
|
|
|
public ArrayList<String> getAllSubjects() { |
|
|
|
|
protected ArrayList<String> getAllSubjects() { |
|
|
|
|
if (students.isEmpty()) { |
|
|
|
|
return null; |
|
|
|
|
} |
|
|
|
@ -168,7 +170,7 @@ public class ManagerTool { |
|
|
|
|
* |
|
|
|
|
* @return 学生总人数 |
|
|
|
|
*/ |
|
|
|
|
public int getStudentAmount() { |
|
|
|
|
protected int getStudentAmount() { |
|
|
|
|
return students.size(); |
|
|
|
|
} |
|
|
|
|
|