完成科目成绩层次分析
新增中文帮助信息...
其他小细节过段时间再小修小改
main 0.0.1-pre
lensfrex 3 years ago
parent a5ba4eb17e
commit 4ccb974d59
Signed by: lensfrex
GPG Key ID: 0F69A0A2FBEE98A0
  1. 4
      readme.md
  2. 7
      src/main/java/me/lensfrex/manager/Main.java
  3. 20
      src/main/java/me/lensfrex/manager/Worker.java
  4. 4
      src/main/java/me/lensfrex/manager/data/manager/ManagerTool.java
  5. 74
      src/main/java/me/lensfrex/manager/data/manager/StudentManager.java
  6. 20
      src/main/resources/me.lensfrex.manager/cnHelpMessage.txt
  7. 5
      src/main/resources/me.lensfrex.manager/helpMessage.txt

@ -1,6 +1,6 @@
# StudentManager-S # SManager-S
嗯,正如你所见,这项目叫做StudentManager-S 就是StudentManager-S啦!
“-S”不是指“Super”,而是"Simple" ( ̄﹏ ̄;) “-S”不是指“Super”,而是"Simple" ( ̄﹏ ̄;)

@ -25,6 +25,7 @@ public class Main {
switch (command) { switch (command) {
case "null": case "null":
case "0": case "0":
System.out.println("See you later!");
return -1; return -1;
case "1": case "1":
System.out.println(Worker.studentInformationExample); System.out.println(Worker.studentInformationExample);
@ -81,8 +82,7 @@ public class Main {
} }
break; break;
case "10": case "10":
System.out.println("Not support yet :)"); worker.printScoreAnalysis();
System.out.println("It will come out soon.");
break; break;
case "11": case "11":
worker.listRecord(); worker.listRecord();
@ -90,6 +90,9 @@ public class Main {
case "12": case "12":
worker.printHelp(); worker.printHelp();
break; break;
case "13":
worker.printCnHelp();
break;
default: default:
System.out.println("- Don't recognize... Please enter again. (Enter 12 to show help again)"); System.out.println("- Don't recognize... Please enter again. (Enter 12 to show help again)");
break; break;

@ -11,6 +11,7 @@ import java.util.ArrayList;
public class Worker { public class Worker {
public static final String helpMessage = IOUtil.inputStreamToString(Main.class.getResourceAsStream("/me.lensfrex.manager/helpMessage.txt"), StandardCharsets.UTF_8); public static final String helpMessage = IOUtil.inputStreamToString(Main.class.getResourceAsStream("/me.lensfrex.manager/helpMessage.txt"), StandardCharsets.UTF_8);
public static final String cnHelpMessage = IOUtil.inputStreamToString(Main.class.getResourceAsStream("/me.lensfrex.manager/cnHelpMessage.txt"), StandardCharsets.UTF_8);
public static final String studentInformationExample = IOUtil.inputStreamToString(Main.class.getResourceAsStream("/me.lensfrex.manager/studentInformationExample.txt"), StandardCharsets.UTF_8); public static final String studentInformationExample = IOUtil.inputStreamToString(Main.class.getResourceAsStream("/me.lensfrex.manager/studentInformationExample.txt"), StandardCharsets.UTF_8);
private final StudentManager studentManager = new StudentManager(); private final StudentManager studentManager = new StudentManager();
@ -29,6 +30,10 @@ public class Worker {
System.out.println(helpMessage); System.out.println(helpMessage);
} }
public void printCnHelp() {
System.out.println(cnHelpMessage);
}
/** /**
* 根据用户输入添加学生 * 根据用户输入添加学生
* *
@ -153,4 +158,19 @@ public class Worker {
public String searchByName(String name) { public String searchByName(String name) {
return studentManager.getStudentInfo(studentManager.getStudent(name)); return studentManager.getStudentInfo(studentManager.getStudent(name));
} }
/**
* 输出成绩分析
*/
public void printScoreAnalysis() {
System.out.println("-----------------------------------------------------------------------------");
System.out.println("Subject:\n\tLevel A: levelAmount/percent | Level B: levelAmount/percent ...");
System.out.println("-----------------------------------------------------------------------------");
ArrayList<String> table = studentManager.generateSubjectAnalysis();
for (String record : table) {
System.out.println(record);
}
}
} }

@ -178,11 +178,11 @@ public class ManagerTool {
/** /**
* 获取所有科目名称若无学生信息则返回null * 获取所有科目名称若无学生信息则返回null
* *
* @return 包含所有科目名称的Arraylist若无学生信息则返回null * @return 包含所有科目名称的Arraylist若无学生信息则返回空的ArrayList
*/ */
protected ArrayList<String> getAllSubjects() { protected ArrayList<String> getAllSubjects() {
if (students.isEmpty()) { if (students.isEmpty()) {
return null; return new ArrayList<>();
} }
return new ArrayList<>(students.get(0).getScore().keySet()); return new ArrayList<>(students.get(0).getScore().keySet());
} }

@ -313,15 +313,83 @@ public class StudentManager {
return managerTool.getStudent(id); return managerTool.getStudent(id);
} }
/**
public HashMap<String, Integer[]> generateSubjectAnalysis(String subject) { * 获取某科目成绩分析HashMap
*
* @param subject 欲分析的科目
* @return 成绩等级人数
*/
private int[] getSubjectAnalysis(String subject) {
ArrayList<Integer> scores = new ArrayList<>(managerTool.getSubjectScores(subject).values()); ArrayList<Integer> scores = new ArrayList<>(managerTool.getSubjectScores(subject).values());
int[] scoreAnalysis = new int[5]; int[] scoreAnalysis = new int[5];
HashMap<String, Integer[]> analysis = new HashMap<>();
for (int score : scores) { for (int score : scores) {
scoreAnalysis[getScoreLevel(score)]++;
}
return scoreAnalysis;
}
/**
* 获取所有成绩分析HashMap
*
* @return 成绩等级人数
*/
public HashMap<String, int[]> getAllSubjectAnalysis() {
ArrayList<String> subjects = managerTool.getAllSubjects();
HashMap<String, int[]> analysis = new HashMap<>();
for (String subject : subjects) {
analysis.put(subject, this.getSubjectAnalysis(subject));
}
return analysis;
}
/**
* 生成每科成绩层次分析(按百分制)的ArrayList
* @return 包含成绩层次分析记录的ArrayList每个层次等级数据为人数/百分比
*/
public ArrayList<String> generateSubjectAnalysis() {
HashMap<String, int[]> analysis = getAllSubjectAnalysis();
ArrayList<String> subjects = new ArrayList<>(analysis.keySet());
ArrayList<String> records = new ArrayList<>();
int studentAmount = managerTool.getStudentAmount();
for (String subject : subjects) {
int[] scoreLevelInfo = analysis.get(subject);
StringBuilder stringBuilder = new StringBuilder().append(subject).append(":\n\t");
stringBuilder
.append(String.format("Level A: %d/%.2f", scoreLevelInfo[SCORE_LEVEL_A], (float) scoreLevelInfo[SCORE_LEVEL_A] / studentAmount)).append(" | ")
.append(String.format("Level B: %d/%.2f", scoreLevelInfo[SCORE_LEVEL_B], (float) scoreLevelInfo[SCORE_LEVEL_B] / studentAmount)).append(" | ")
.append(String.format("Level C: %d/%.2f", scoreLevelInfo[SCORE_LEVEL_C], (float) scoreLevelInfo[SCORE_LEVEL_C] / studentAmount)).append(" | ")
.append(String.format("Level D: %d/%.2f", scoreLevelInfo[SCORE_LEVEL_D], (float) scoreLevelInfo[SCORE_LEVEL_D] / studentAmount)).append(" | ")
.append(String.format("Level E: %d/%.2f", scoreLevelInfo[SCORE_LEVEL_E], (float) scoreLevelInfo[SCORE_LEVEL_E] / studentAmount));
records.add(stringBuilder.toString());
}
return records;
}
private int getScoreLevel(int score) {
if (score >= 90) {
return SCORE_LEVEL_A;
} else if (score >= 80) {
return SCORE_LEVEL_B;
} else if (score >= 70) {
return SCORE_LEVEL_C;
} else if (score >= 60) {
return SCORE_LEVEL_D;
} else {
return SCORE_LEVEL_E;
} }
} }
public static final int SCORE_LEVEL_A = 0;
public static final int SCORE_LEVEL_B = 1;
public static final int SCORE_LEVEL_C = 2;
public static final int SCORE_LEVEL_D = 3;
public static final int SCORE_LEVEL_E = 4;
} }

@ -0,0 +1,20 @@
----------------------------------------------------------------
欢迎来到 SManager-S
----------------------------------------------------------------
您想做什么:
1. 添加学生
2. 删除学生(按姓名或学号)
3. 输出每门课程的总分和平均分
4. 输出每个学生的总分
5. 输出按每个学生的总分(降序)
6. 输出学生信息(按学号升序)
7. 输出学生信息(按姓名升序)
8. 按学号搜索学生
9. 按姓名搜索学生
10. 每门课程的统计分析
11. 列出所有记录信息(学生及每个科目)
12. 输出帮助信息(是英文哦/English)
13. 中文帮助信息 ← _ ←
0. 退出
----------------------------------------------------------------
做出抉择吧!

@ -1,5 +1,5 @@
---------------------------------------------------------------- ----------------------------------------------------------------
Welcome to StudentManager-S Welcome to SManager-S
---------------------------------------------------------------- ----------------------------------------------------------------
Do you want to: Do you want to:
1. Input record 1. Input record
@ -11,9 +11,10 @@ Do you want to:
7. Sort in ascending order by name 7. Sort in ascending order by name
8. Search by number 8. Search by number
9. Search by name 9. Search by name
10. Statistic analysis for every course (not featured yet) 10. Statistic analysis for every course
11. List record 11. List record
12. Show help again 12. Show help again
13. “我 们 需 要 中 文” ← _ ←
0. Exit 0. Exit
---------------------------------------------------------------- ----------------------------------------------------------------
Please enter your choice: Please enter your choice:

Loading…
Cancel
Save