From 049ee30434981f7eaec7149b8758a8940aa55792 Mon Sep 17 00:00:00 2001 From: zyx <1029606625@qq.com> Date: Fri, 4 Nov 2022 20:03:19 +0800 Subject: [PATCH] =?UTF-8?q?2022/11/04=2020:00=20=E4=B8=8A=E4=BC=A0?= =?UTF-8?q?=E7=AC=AC9=E6=AC=A1=E4=BD=9C=E4=B8=9A=E9=A2=981?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .idea/.gitignore | 8 ++ .idea/compiler.xml | 14 ++ .idea/encodings.xml | 7 + .idea/jarRepositories.xml | 20 +++ .idea/misc.xml | 14 ++ .idea/vcs.xml | 6 + pom.xml | 40 ++++++ src/main/java/cn/czyx007/week10/Driver.java | 38 ++++++ .../java/cn/czyx007/week10/bean/Student.java | 39 ++++++ .../java/cn/czyx007/week10/bean/User.java | 24 ++++ .../cn/czyx007/week10/service/MainMenu.java | 110 +++++++++++++++ .../cn/czyx007/week10/service/UserLogin.java | 104 +++++++++++++++ .../cn/czyx007/week10/utils/ExcelUtil.java | 125 ++++++++++++++++++ .../cn/czyx007/week10/utils/JsonUtil.java | 101 ++++++++++++++ .../cn/czyx007/week10/utils/StudentUtil.java | 104 +++++++++++++++ .../java/cn/czyx007/week10/utils/TxtUtil.java | 87 ++++++++++++ src/main/resources/score.json | 30 +++++ src/main/resources/score.txt | 5 + src/main/resources/score.xls | Bin 0 -> 13824 bytes src/main/resources/student.json | 58 ++++++++ src/main/resources/student.txt | 9 ++ src/main/resources/student.xls | Bin 0 -> 27136 bytes src/main/resources/users.csv | 2 + .../cn/czyx007/week10/test/ExcelUtilTest.java | 25 ++++ .../cn/czyx007/week10/test/JsonUtilTest.java | 25 ++++ .../czyx007/week10/test/StudentUtilTest.java | 43 ++++++ .../cn/czyx007/week10/test/TxtUtilTest.java | 25 ++++ .../cn/czyx007/week10/test/UserLoginTest.java | 35 +++++ 28 files changed, 1098 insertions(+) create mode 100644 .idea/.gitignore create mode 100644 .idea/compiler.xml create mode 100644 .idea/encodings.xml create mode 100644 .idea/jarRepositories.xml create mode 100644 .idea/misc.xml create mode 100644 .idea/vcs.xml create mode 100644 pom.xml create mode 100644 src/main/java/cn/czyx007/week10/Driver.java create mode 100644 src/main/java/cn/czyx007/week10/bean/Student.java create mode 100644 src/main/java/cn/czyx007/week10/bean/User.java create mode 100644 src/main/java/cn/czyx007/week10/service/MainMenu.java create mode 100644 src/main/java/cn/czyx007/week10/service/UserLogin.java create mode 100644 src/main/java/cn/czyx007/week10/utils/ExcelUtil.java create mode 100644 src/main/java/cn/czyx007/week10/utils/JsonUtil.java create mode 100644 src/main/java/cn/czyx007/week10/utils/StudentUtil.java create mode 100644 src/main/java/cn/czyx007/week10/utils/TxtUtil.java create mode 100644 src/main/resources/score.json create mode 100644 src/main/resources/score.txt create mode 100644 src/main/resources/score.xls create mode 100644 src/main/resources/student.json create mode 100644 src/main/resources/student.txt create mode 100644 src/main/resources/student.xls create mode 100644 src/main/resources/users.csv create mode 100644 src/test/java/cn/czyx007/week10/test/ExcelUtilTest.java create mode 100644 src/test/java/cn/czyx007/week10/test/JsonUtilTest.java create mode 100644 src/test/java/cn/czyx007/week10/test/StudentUtilTest.java create mode 100644 src/test/java/cn/czyx007/week10/test/TxtUtilTest.java create mode 100644 src/test/java/cn/czyx007/week10/test/UserLoginTest.java diff --git a/.idea/.gitignore b/.idea/.gitignore new file mode 100644 index 0000000..35410ca --- /dev/null +++ b/.idea/.gitignore @@ -0,0 +1,8 @@ +# 默认忽略的文件 +/shelf/ +/workspace.xml +# 基于编辑器的 HTTP 客户端请求 +/httpRequests/ +# Datasource local storage ignored files +/dataSources/ +/dataSources.local.xml diff --git a/.idea/compiler.xml b/.idea/compiler.xml new file mode 100644 index 0000000..deb9b5b --- /dev/null +++ b/.idea/compiler.xml @@ -0,0 +1,14 @@ + + + + + + + + + + + + + + \ No newline at end of file diff --git a/.idea/encodings.xml b/.idea/encodings.xml new file mode 100644 index 0000000..aa00ffa --- /dev/null +++ b/.idea/encodings.xml @@ -0,0 +1,7 @@ + + + + + + + \ No newline at end of file diff --git a/.idea/jarRepositories.xml b/.idea/jarRepositories.xml new file mode 100644 index 0000000..abb532a --- /dev/null +++ b/.idea/jarRepositories.xml @@ -0,0 +1,20 @@ + + + + + + + + + + + \ No newline at end of file diff --git a/.idea/misc.xml b/.idea/misc.xml new file mode 100644 index 0000000..132404b --- /dev/null +++ b/.idea/misc.xml @@ -0,0 +1,14 @@ + + + + + + + + + + \ No newline at end of file diff --git a/.idea/vcs.xml b/.idea/vcs.xml new file mode 100644 index 0000000..94a25f7 --- /dev/null +++ b/.idea/vcs.xml @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file diff --git a/pom.xml b/pom.xml new file mode 100644 index 0000000..8f6e8b3 --- /dev/null +++ b/pom.xml @@ -0,0 +1,40 @@ + + + 4.0.0 + + cn.czyx007.week10 + week10-work1 + 1.0-SNAPSHOT + + + 8 + 8 + UTF-8 + + + + + net.sourceforge.jexcelapi + jxl + 2.6.12 + + + com.google.code.gson + gson + 2.10 + + + org.projectlombok + lombok + 1.18.20 + + + junit + junit + 4.13.2 + test + + + \ No newline at end of file diff --git a/src/main/java/cn/czyx007/week10/Driver.java b/src/main/java/cn/czyx007/week10/Driver.java new file mode 100644 index 0000000..bec1bb1 --- /dev/null +++ b/src/main/java/cn/czyx007/week10/Driver.java @@ -0,0 +1,38 @@ +package cn.czyx007.week10; + +import cn.czyx007.week10.bean.User; +import cn.czyx007.week10.service.MainMenu; +import cn.czyx007.week10.service.UserLogin; + +import java.util.Scanner; + +/** + * @author : 张宇轩 + * @createTime : 2022/11/3 + */ +public class Driver { + public static void main(String[] args) { + Scanner scanner = new Scanner(System.in); + + int cnt = 0; + User user = null; + while (cnt < 3) { + System.out.print("请输入用户名:"); + String username = scanner.nextLine(); + System.out.print("请输入密码:"); + String password = scanner.nextLine(); + user = new User(username, password); + if (UserLogin.login(user)) { + break; + } else { + System.out.println("您输入的用户名或密码不正确"); + } + cnt++; + } + if (cnt == 3){ + System.out.println("尝试超限!程序已退出"); + return; + } + MainMenu.menu(user); + } +} diff --git a/src/main/java/cn/czyx007/week10/bean/Student.java b/src/main/java/cn/czyx007/week10/bean/Student.java new file mode 100644 index 0000000..9caedbe --- /dev/null +++ b/src/main/java/cn/czyx007/week10/bean/Student.java @@ -0,0 +1,39 @@ +package cn.czyx007.week10.bean; + +import lombok.AllArgsConstructor; +import lombok.Data; +import lombok.NoArgsConstructor; + +/** + * @author : 张宇轩 + * @createTime : 2022/11/3 + */ +@NoArgsConstructor +@AllArgsConstructor +@Data +public class Student { + /** + * 学号 + */ + private String id; + + /** + * 姓名 + */ + private String name; + + /** + * 性别 + */ + private String gender; + + /** + * 课程名称 + */ + private String lessonName; + + /** + * 成绩 + */ + private Double score; +} diff --git a/src/main/java/cn/czyx007/week10/bean/User.java b/src/main/java/cn/czyx007/week10/bean/User.java new file mode 100644 index 0000000..163fdab --- /dev/null +++ b/src/main/java/cn/czyx007/week10/bean/User.java @@ -0,0 +1,24 @@ +package cn.czyx007.week10.bean; + +import lombok.AllArgsConstructor; +import lombok.Data; +import lombok.NoArgsConstructor; + +/** + * @author : 张宇轩 + * @createTime : 2022/11/3 + */ +@NoArgsConstructor +@AllArgsConstructor +@Data +public class User { + /** + * 用户名 + */ + private String username; + + /** + * 密码 + */ + private String password; +} diff --git a/src/main/java/cn/czyx007/week10/service/MainMenu.java b/src/main/java/cn/czyx007/week10/service/MainMenu.java new file mode 100644 index 0000000..c4ad68b --- /dev/null +++ b/src/main/java/cn/czyx007/week10/service/MainMenu.java @@ -0,0 +1,110 @@ +package cn.czyx007.week10.service; + +import cn.czyx007.week10.bean.Student; +import cn.czyx007.week10.bean.User; +import cn.czyx007.week10.utils.ExcelUtil; +import cn.czyx007.week10.utils.JsonUtil; +import cn.czyx007.week10.utils.StudentUtil; +import cn.czyx007.week10.utils.TxtUtil; + +import java.util.List; +import java.util.Scanner; + +/** + * @author : 张宇轩 + * @createTime : 2022/11/3 + */ +public class MainMenu { + /** + * 主菜单界面和业务逻辑控制 + * @param user 已成功登录的用户 + */ + public static void menu(User user){ + int opt; + List students = null; + Scanner scanner = new Scanner(System.in); + while (true){ + System.out.println("=====学生成绩管理系统=======\n" + + "1.从excel文件中加载数据\n" + + "2.从文本文件中加载数据\n" + + "3.从json文件中加载数据\n" + + "4.键盘输入数据\n" + + "5.成绩查询\n" + + "6.输出到excel文件\n" + + "7.输出到纯文本文件\n" + + "8.输出到json文件\n" + + "9.修改密码\n" + + "10.退出\n" + + "请输入选项:>>>"); + do { + opt = checkInput(1, 10); + } while (opt == -1); + + switch (opt){ + case 1://1.从excel文件中加载数据 + students = ExcelUtil.loadDataFromExcel(); + break; + case 2://2.从文本文件中加载数据 + students = TxtUtil.loadDataFromTxt(); + break; + case 3://3.从json文件中加载数据 + students = JsonUtil.loadDataFromJson(); + break; + case 4://4.键盘输入数据 + students = StudentUtil.inputDataFromKeyBoard(); + break; + case 5://5.成绩查询 + System.out.println("请输入待查询学生的学号:"); + String id = new Scanner(System.in).nextLine(); + StudentUtil.selectAllScoreById(id, students); + break; + case 6://6.输出到excel文件 + ExcelUtil.exportDataToExcel(students); + break; + case 7://7.输出到纯文本文件 + TxtUtil.exportDataToTxt(students); + break; + case 8://8.输出到json文件 + JsonUtil.exportDataToJson(students); + break; + case 9://9.修改密码 + UserLogin.changePassword(user); + break; + case 10://10.退出 + while (true) { + System.out.println("确认退出系统吗?(Y/N):"); + String option = scanner.nextLine(); + if ("Y".equalsIgnoreCase(option)) { + System.exit(0); + } else if ("N".equalsIgnoreCase(option)) { + break; + } else { + System.out.println("输入错误!请重新输入!"); + } + } + } + System.out.println(); + } + } + + /** + * 检查菜单选项输入合法性 + * @param low 选项下界 + * @param high 选项上界 + * @return 合法选项值 + */ + public static int checkInput(int low, int high) { + Scanner scanner = new Scanner(System.in); + if (scanner.hasNextInt()) { + int opt = scanner.nextInt(); + if (opt >= low && opt <= high) { + return opt; + } + System.out.println("输入超限,请输入" + low + "-" + high + "的数字"); + } else { + System.out.println("输入数据类型错误,请输入" + low + "-" + high + "的数字"); + scanner.next(); + } + return -1; + } +} diff --git a/src/main/java/cn/czyx007/week10/service/UserLogin.java b/src/main/java/cn/czyx007/week10/service/UserLogin.java new file mode 100644 index 0000000..ccb45e4 --- /dev/null +++ b/src/main/java/cn/czyx007/week10/service/UserLogin.java @@ -0,0 +1,104 @@ +package cn.czyx007.week10.service; + +import cn.czyx007.week10.bean.User; + +import java.io.*; +import java.util.ArrayList; +import java.util.List; +import java.util.Scanner; + +/** + * @author : 张宇轩 + * @createTime : 2022/11/3 + */ +public class UserLogin { + /** + * 登录 + * @param user 待登录的User对象,属性为输入的用户名和密码 + * @return true:登录成功 false: 登录失败 + */ + public static boolean login(User user){ + try(BufferedReader br = new BufferedReader(new FileReader("src/main/resources/users.csv"))) { + String aLine; + while ((aLine=br.readLine()) != null){ + String[] nameAndPwd = aLine.split(" "); + if(nameAndPwd[0].equals(user.getUsername()) && nameAndPwd[1].equals(user.getPassword())){ + return true; + } + } + } catch (Exception e){ + e.printStackTrace(); + } + return false; + } + + /** + * 验证输入的 原密码 是否正确 + * @param user 待验证密码的User对象 + * @param oldPassword 输入的原密码 + * @return true:输入的原密码正确 false:输入的原密码错误 + */ + public static boolean checkPassword(User user, String oldPassword){ + return user.getPassword().equals(oldPassword); + } + + /** + * 修改密码并写回到users.csv文件中 + * @param user 待修改密码的User对象 + */ + public static void changePassword(User user){ + Scanner scanner = new Scanner(System.in); + System.out.println("请输入原密码:"); + String oldPassword = scanner.nextLine(); + if (!UserLogin.checkPassword(user, oldPassword)) { + System.out.println("密码输入错误!"); + } else { + System.out.println("请输入新密码:"); + String newPassword = scanner.nextLine(); + user.setPassword(newPassword); + + updateUserDataFile(user); + System.out.println("密码已修改!"); + } + try { + System.out.print("按任意键返回主菜单"); + System.in.read(); + } catch (IOException e) { + e.printStackTrace(); + } + } + + /** + * 更新用户数据文件users.csv中的某用户的密码 + * @param user 待更新密码的User对象 + */ + public static void updateUserDataFile(User user){ + //读取原有用户数据 + List users = new ArrayList<>(); + try(BufferedReader br = new BufferedReader(new FileReader("src/main/resources/users.csv"))) { + String aLine; + while ((aLine= br.readLine()) != null){ + String[] nameAndPwd = aLine.split(" "); + users.add(new User(nameAndPwd[0], nameAndPwd[1])); + } + } catch (Exception e){ + e.printStackTrace(); + } + + //修改指定用户密码 + for (User usr : users) { + if(usr.getUsername().equals(user.getUsername())){ + usr.setPassword(user.getPassword()); + } + } + + //将修改后的数据写回到文件中 + try(BufferedWriter bw = new BufferedWriter(new FileWriter("src/main/resources/users.csv"))) { + for (User usr : users) { + bw.write(usr.getUsername() + " " + usr.getPassword() + "\n"); + } + } catch (Exception e){ + e.printStackTrace(); + } + } +} diff --git a/src/main/java/cn/czyx007/week10/utils/ExcelUtil.java b/src/main/java/cn/czyx007/week10/utils/ExcelUtil.java new file mode 100644 index 0000000..e802251 --- /dev/null +++ b/src/main/java/cn/czyx007/week10/utils/ExcelUtil.java @@ -0,0 +1,125 @@ +package cn.czyx007.week10.utils; + +import cn.czyx007.week10.bean.Student; +import jxl.Sheet; +import jxl.Workbook; +import jxl.write.Label; +import jxl.write.WritableSheet; +import jxl.write.WritableWorkbook; + +import java.io.File; +import java.util.ArrayList; +import java.util.HashMap; +import java.util.List; +import java.util.Map; + +/** + * @author : 张宇轩 + * @createTime : 2022/11/3 + */ +public class ExcelUtil { + /** + * 从excel文件中加载数据 + * @return 所有不重复的学生数据的List集合 + */ + public static List loadDataFromExcel() { + List students = new ArrayList<>(); + + Map> studentMap = new HashMap<>(); + Workbook wb = null; + try { + wb = Workbook.getWorkbook(new File("src/main/resources/student.xls")); + Sheet sheet = wb.getSheet(0); + + int cnt = 0; + int rows = sheet.getRows(); + for (int i = 1; i < rows; i++) { + String id = sheet.getCell(0,i).getContents(); + String name = sheet.getCell(1,i).getContents(); + String gender = sheet.getCell(2,i).getContents(); + String lessonName = sheet.getCell(3,i).getContents(); + Double score = Double.parseDouble(sheet.getCell(4,i).getContents()); + + if(StudentUtil.checkIfStudentScoreDuplicate(studentMap, id, lessonName)){ + students.add(new Student(id, name, gender, lessonName, score)); + cnt++; + } + } + + System.out.println("成功导入 " + cnt + " 条学生数据"); + System.out.print("按任意键返回主菜单"); + System.in.read(); + } catch (Exception e) { + System.out.println("数据导入失败!"); + e.printStackTrace(); + }finally { + if (wb != null){ + try { + wb.close(); + }catch (Exception e){ + e.printStackTrace(); + } + } + } + return students; + } + + /** + * 导出学生成绩信息到excel文件中 + * @param students 待导出成绩信息的学生数据的List集合 + */ + public static void exportDataToExcel(List students) { + WritableWorkbook wb = null; + try { + wb = Workbook.createWorkbook(new File("src/main/resources/score.xls")); + WritableSheet ws = wb.createSheet("学生成绩", 0); + + ws.addCell(new Label(0,0,"学号")); + ws.addCell(new Label(1,0,"姓名")); + ws.addCell(new Label(2,0,"性别")); + ws.addCell(new Label(3,0,"总分")); + ws.addCell(new Label(4,0,"平均分")); + + int studentCnt = 0; + Map isWritten = new HashMap<>(); + for (int i = 0; i < students.size(); i++) { + if(isWritten.containsKey(students.get(i).getId())){ + continue; + } + + ws.addCell(new Label(0,studentCnt+1,students.get(i).getId())); + ws.addCell(new Label(1,studentCnt+1,students.get(i).getName())); + ws.addCell(new Label(2,studentCnt+1,students.get(i).getGender())); + + int lessonCnt=0; + double allScore=0; + for (Student stu : students) { + if(stu.getId().equals(students.get(i).getId())){ + lessonCnt++; + allScore += stu.getScore(); + } + } + ws.addCell(new Label(3, studentCnt+1, Double.toString(allScore))); + ws.addCell(new Label(4, studentCnt+1, Double.toString(allScore/lessonCnt))); + studentCnt++; + + isWritten.put(students.get(i).getId(), true); + } + wb.write(); + System.out.println("成功导出 " + studentCnt + " 条学生成绩信息到 excel 文件中"); + System.out.print("按任意键返回主菜单"); + System.in.read(); + } catch (Exception e) { + System.out.println("数据导出失败!"); + e.printStackTrace(); + } finally { + if (wb != null) { + try { + wb.close(); + } catch (Exception e) { + e.printStackTrace(); + } + } + } + } +} diff --git a/src/main/java/cn/czyx007/week10/utils/JsonUtil.java b/src/main/java/cn/czyx007/week10/utils/JsonUtil.java new file mode 100644 index 0000000..de3991b --- /dev/null +++ b/src/main/java/cn/czyx007/week10/utils/JsonUtil.java @@ -0,0 +1,101 @@ +package cn.czyx007.week10.utils; + +import cn.czyx007.week10.bean.Student; +import com.google.gson.*; +import com.google.gson.reflect.TypeToken; + +import java.io.BufferedReader; +import java.io.BufferedWriter; +import java.io.FileReader; +import java.io.FileWriter; +import java.util.ArrayList; +import java.util.HashMap; +import java.util.List; +import java.util.Map; + +/** + * @author : 张宇轩 + * @createTime : 2022/11/3 + */ +public class JsonUtil { + /** + * 从json文件中加载数据 + * @return 所有不重复的学生数据的List集合 + */ + public static List loadDataFromJson() { + List students = null; + try (BufferedReader br = new BufferedReader(new FileReader("src/main/resources/student.json"))) { + StringBuilder jsonStr = new StringBuilder(); + String aLine; + while ((aLine=br.readLine()) != null){ + jsonStr.append(aLine); + } + + students = new GsonBuilder().create().fromJson(jsonStr.toString(), new TypeToken>(){}.getType()); + + Map> studentMap = new HashMap<>(); + for (int i = 0; i < students.size(); i++) { + String id = students.get(i).getId(); + String lessonName = students.get(i).getLessonName(); + + if (!StudentUtil.checkIfStudentScoreDuplicate(studentMap, id, lessonName)){ + students.remove(i--); + } + } + + System.out.println("成功导入 " + students.size() + " 条学生数据"); + System.out.print("按任意键返回主菜单"); + System.in.read(); + } catch (Exception e) { + System.out.println("数据导入失败!"); + e.printStackTrace(); + } + return students; + } + + /** + * 导出学生成绩信息到json文件中 + * @param students 待导出成绩信息的学生数据的List集合 + */ + public static void exportDataToJson(List students) { + try (BufferedWriter bw = new BufferedWriter(new FileWriter("src/main/resources/score.json"))) { + JsonArray jsonArray = new JsonArray(); + int studentCnt = 0; + Map isWritten = new HashMap<>(); + for (int i = 0; i < students.size(); i++) { + if (isWritten.containsKey(students.get(i).getId())) { + continue; + } + JsonObject jsonObject = new JsonObject(); + jsonObject.addProperty("id", students.get(i).getId()); + jsonObject.addProperty("name", students.get(i).getName()); + jsonObject.addProperty("gender", students.get(i).getGender()); + + int lessonCnt = 0; + double allScore = 0; + for (Student stu : students) { + if (stu.getId().equals(students.get(i).getId())) { + lessonCnt++; + allScore += stu.getScore(); + } + } + jsonObject.addProperty("total", allScore); + jsonObject.addProperty("average", allScore / lessonCnt); + + jsonArray.add(jsonObject); + studentCnt++; + + isWritten.put(students.get(i).getId(), true); + } + + Gson gson = new GsonBuilder().setPrettyPrinting().create(); + bw.write(gson.toJson(jsonArray)); + System.out.println("成功导出 " + studentCnt + " 条学生成绩信息到 json 文件中"); + System.out.print("按任意键返回主菜单"); + System.in.read(); + } catch (Exception e) { + System.out.println("数据导出失败!"); + e.printStackTrace(); + } + } +} diff --git a/src/main/java/cn/czyx007/week10/utils/StudentUtil.java b/src/main/java/cn/czyx007/week10/utils/StudentUtil.java new file mode 100644 index 0000000..fc1a3ab --- /dev/null +++ b/src/main/java/cn/czyx007/week10/utils/StudentUtil.java @@ -0,0 +1,104 @@ +package cn.czyx007.week10.utils; + +import cn.czyx007.week10.bean.Student; + +import java.io.IOException; +import java.util.*; + +/** + * @author : 张宇轩 + * @createTime : 2022/11/3 + */ +public class StudentUtil { + /** + * 检查学生课程成绩是否重复 + * @param studentMap 存储各学生的所有课程名称,用于辅助验证特定课程成绩是否重复。 + * Key存储学生学号,Value存储学生所有课程名称的List集合 + * @param id 学生学号 + * @param lessonName 特定课程名称 + * @return true:课程成绩未重复 false:课程成绩重复 + */ + public static boolean checkIfStudentScoreDuplicate(Map> studentMap, String id, String lessonName) { + if (!(studentMap.containsKey(id) && studentMap.get(id).contains(lessonName))) { + if (!studentMap.containsKey(id)) { + List lessons = new ArrayList<>(); + lessons.add(lessonName); + studentMap.put(id, lessons); + } else { + studentMap.get(id).add(lessonName); + } + return true; + } + return false; + } + + /** + * 从键盘依次录入学生成绩信息 + * @return 录入的所有学生成绩信息的List集合 + */ + public static List inputDataFromKeyBoard() { + List students = new ArrayList<>(); + + System.out.println("学生成绩信息录入格式:学号,姓名,性别,课程名称,成绩"); + Scanner scanner = new Scanner(System.in); + Map> studentMap = new HashMap<>(); + while (true) { + System.out.println("请依次输入学生成绩信息(输入end结束):"); + String str = scanner.nextLine(); + if ("end".equalsIgnoreCase(str)) { + break; + } + try { + String[] attributes = str.split("[,,]"); + String id = attributes[0]; + String name = attributes[1]; + String gender = attributes[2]; + String lessonName = attributes[3]; + Double score = Double.parseDouble(attributes[4]); + + if (StudentUtil.checkIfStudentScoreDuplicate(studentMap, id, lessonName)) { + students.add(new Student(id, name, gender, lessonName, score)); + System.out.println("增加成功!"); + } else { + System.out.println("该学生不能重复录入成绩信息,请重新输入!"); + } + } catch (Exception e) { + System.out.println("输入出错!请检查输入格式!"); + } + } + try { + System.out.print("按任意键返回主菜单"); + System.in.read(); + } catch (IOException e) { + e.printStackTrace(); + } + return students; + } + + /** + * 根据学生学号查询其所有课程成绩 + * @param id 待查询课程成绩的学生学号 + * @param students 所有学生成绩信息的List集合 + */ + public static void selectAllScoreById(String id, List students) { + boolean flag = false; + if (students != null) { + for (Student student : students) { + if (student.getId().equals(id)) { + flag = true; + System.out.println(student.getLessonName() + " " + student.getScore()); + } + } + } + if (!flag) { + System.out.println("不存在该学生!"); + } + + try { + System.out.print("按任意键返回主菜单"); + System.in.read(); + } catch (IOException e) { + e.printStackTrace(); + } + } +} diff --git a/src/main/java/cn/czyx007/week10/utils/TxtUtil.java b/src/main/java/cn/czyx007/week10/utils/TxtUtil.java new file mode 100644 index 0000000..7fe80a4 --- /dev/null +++ b/src/main/java/cn/czyx007/week10/utils/TxtUtil.java @@ -0,0 +1,87 @@ +package cn.czyx007.week10.utils; + +import cn.czyx007.week10.bean.Student; + +import java.io.*; +import java.util.*; + +/** + * @author : 张宇轩 + * @createTime : 2022/11/3 + */ +public class TxtUtil { + /** + * 从txt文件中加载数据 + * @return 所有不重复的学生数据的List集合 + */ + public static List loadDataFromTxt() { + List students = new ArrayList<>(); + + Map> studentMap = new HashMap<>(); + try(BufferedReader br = new BufferedReader(new FileReader("src/main/resources/student.txt"))) { + int cnt = 0; + String aLine; + br.readLine(); + while ((aLine=br.readLine()) != null){ + String[] attributes = aLine.split("[ \t]"); + String id = attributes[0]; + String name = attributes[1]; + String gender = attributes[2]; + String lessonName = attributes[3]; + Double score = Double.parseDouble(attributes[4]); + + if(StudentUtil.checkIfStudentScoreDuplicate(studentMap, id, lessonName)){ + students.add(new Student(id, name, gender, lessonName, score)); + cnt++; + } + } + + System.out.println("成功导入 " + cnt + " 条学生数据"); + System.out.print("按任意键返回主菜单"); + System.in.read(); + } catch (Exception e) { + System.out.println("数据导入失败!"); + e.printStackTrace(); + } + return students; + } + + /** + * 导出学生成绩信息到txt文件中 + * @param students 待导出成绩信息的学生数据的List集合 + */ + public static void exportDataToTxt(List students) { + try(BufferedWriter bw = new BufferedWriter(new FileWriter("src/main/resources/score.txt"))) { + bw.write("学号\t姓名\t性别\t总分\t平均分\n"); + + int studentCnt = 0; + Map isWritten = new HashMap<>(); + for (int i = 0; i < students.size(); i++) { + if(isWritten.containsKey(students.get(i).getId())){ + continue; + } + + bw.write(students.get(i).getId() + "\t" + students.get(i).getName() + "\t" + students.get(i).getGender() + "\t"); + + int lessonCnt=0; + double allScore=0; + for (Student stu : students) { + if(stu.getId().equals(students.get(i).getId())){ + lessonCnt++; + allScore += stu.getScore(); + } + } + bw.write(allScore + "\t" + allScore/lessonCnt + "\n"); + studentCnt++; + + isWritten.put(students.get(i).getId(), true); + } + System.out.println("成功导出 " + studentCnt + " 条学生成绩信息到 txt 文件中"); + System.out.print("按任意键返回主菜单"); + System.in.read(); + } catch (Exception e) { + System.out.println("数据导出失败!"); + e.printStackTrace(); + } + } +} diff --git a/src/main/resources/score.json b/src/main/resources/score.json new file mode 100644 index 0000000..d791ea3 --- /dev/null +++ b/src/main/resources/score.json @@ -0,0 +1,30 @@ +[ + { + "id": "1001", + "name": "张三", + "gender": "男", + "total": 279.0, + "average": 93.0 + }, + { + "id": "1002", + "name": "李四", + "gender": "男", + "total": 98.0, + "average": 98.0 + }, + { + "id": "1003", + "name": "王五", + "gender": "女", + "total": 175.0, + "average": 87.5 + }, + { + "id": "1004", + "name": "赵六", + "gender": "女", + "total": 82.0, + "average": 82.0 + } +] \ No newline at end of file diff --git a/src/main/resources/score.txt b/src/main/resources/score.txt new file mode 100644 index 0000000..b9db144 --- /dev/null +++ b/src/main/resources/score.txt @@ -0,0 +1,5 @@ +学号 姓名 性别 总分 平均分 +1001 张三 男 279.0 93.0 +1002 李四 男 98.0 98.0 +1003 王五 女 175.0 87.5 +1004 赵六 女 82.0 82.0 diff --git a/src/main/resources/score.xls b/src/main/resources/score.xls new file mode 100644 index 0000000000000000000000000000000000000000..63e6620830d331215d6401fbbb9578980135fd3b GIT binary patch literal 13824 zcmeHOO=whC6h8OOn@Ogc%p~zQAdZ$&n}pCAwT_zlQ~&BhO{1+1iYBq96}3uYM5V2x ztsq!Y(50I!l|tK1-4rnep^HLG3$0WNiMT0UlnT;C)$#kzoo8aqfP#XSbB4L!J3sH- zbH97%%`DFR^kdCn|JU_HGD;RnOzswwk{DrkxSks6X@S33q#EHAT*GAY95Ilr#6~9K za&zJj72Hei_mBkgRXBiAAeDUyU9&;FzRkMVys~u6xt;zI4~0pL{MMPD&FF&lP<-PlOkzyL;2W>jA&CS8V{i z+|k$uSlE$hi;3&qvT9?Z4Yy_GRlKr{&umSub>imr#l_`hp3IkKxDYd6W=EGkJjd|0 z?_YaIo%siyv*|q1dzQI++mS1aTyvwCJd|dr_otr2@V=9~--0DCIgKmI1uW=SoX+uB z${)Zw;0<6s@GsyD;7#Bx;D5j@FcFHh0IPt@fVIFkfzyF+0~>%Hz`4Mkz!qQ+a24=l zAn1_ez;@s%;1=Ln;7(vaa6j-1;1S?O;Bnw3;0t*BhiLkNhv>M#f3V>e?wG@q^%@?r zRa`Mv7RY;&((4+Gf{m?|+vorJc}-XA;;m|LPD=*>T;Bh5K;28)x z7dQS>js8r>ewisr*u2D~$u;qb0vTK!p#wJovPw{`COunPZ)Jcl21p!psNi1Om}0bz z^^dk;TOP8p;*oK8ls&6g5`CO0r8RktS;pP>jm#3Dj+CBHAIU5{t<+dy3i}*s%tCg(k6E~0uQ3aG z_8PO)lr*j^g|9R3!^Z;}KL?BqQR#4&P;21{@IGdt_8VsX4#c#|%F=65P%Gc)FS;f0 zx8MX)rXij+Lr5cqhuXv#Fb0ePW55_N28;n?z!)$Fi~(c77%&Em0b{@zFb0ePW55_N z28;n?z!)$Fi~(c77%&Em0b{@zFb0ePW55_N2A)+0*zw1YWZ_DugD0Jcl=e;sU% zWH%t&Alcx^wnjEHvW1a;wkxtpk*$eQ6Y3;fPsW@6J9raKo=pbYWDj2ZBqJ;2Ltu{_ z#LhjsOkzWCNuuu2a(C}tcm39xzppx;hbU$vX752mc9+({#_Y!v{u6{}H>%;0@Aloz zsD8cl$!@$lb?vLcLbujL%Rc=7V-GClWftb=x}zG(M-F?~e5_r+fVeEj4BNDZ?YaYx US5F@EM{6ez&r<$MmtI=`J!R3q4gdfE literal 0 HcmV?d00001 diff --git a/src/main/resources/student.json b/src/main/resources/student.json new file mode 100644 index 0000000..c4271be --- /dev/null +++ b/src/main/resources/student.json @@ -0,0 +1,58 @@ +[ + { + "id": "1001", + "name": "张三", + "gender": "男", + "lessonName": "高数", + "score": 95 + }, + { + "id": "1001", + "name": "张三", + "gender": "男", + "lessonName": "高数", + "score": 55 + }, + { + "id": "1001", + "name": "张三", + "gender": "男", + "lessonName": "c语言", + "score": 94 + }, + { + "id": "1002", + "name": "李四", + "gender": "男", + "lessonName": "英语", + "score": 98 + }, + { + "id": "1003", + "name": "王五", + "gender": "女", + "lessonName": "高数", + "score": 90 + }, + { + "id": "1001", + "name": "张三", + "gender": "男", + "lessonName": "英语", + "score": 90 + }, + { + "id": "1003", + "name": "王五", + "gender": "女", + "lessonName": "英语", + "score": 85 + }, + { + "id": "1004", + "name": "赵六", + "gender": "女", + "lessonName": "高数", + "score": 82 + } +] \ No newline at end of file diff --git a/src/main/resources/student.txt b/src/main/resources/student.txt new file mode 100644 index 0000000..58a5939 --- /dev/null +++ b/src/main/resources/student.txt @@ -0,0 +1,9 @@ +学号 姓名 性别 课程名称 成绩 +1001 张三 男 高数 95 +1001 张三 男 c语言 94 +1002 李四 男 英语 98 +1003 王五 女 高数 90 +1001 张三 男 英语 90 +1003 王五 女 英语 85 +1004 赵六 女 高数 82 +1001 张三 男 高数 55 diff --git a/src/main/resources/student.xls b/src/main/resources/student.xls new file mode 100644 index 0000000000000000000000000000000000000000..54a638d7354fa20702b38a5cd7f806916739b63e GIT binary patch literal 27136 zcmeHw2~-qE_ixQGz#yU^h%5rbjsmjCrbxhj0~JKn7{rAER1|}I6d~@2A}WfaamQUm zT!@Oh#-JEM+(9EME>T2@hG^9J-`ma1^z`%)`2OE{@4WM-I5pjMtLk@e-MV#a>258# zZt!U9A+t)t3f~Y7@>QZkv>0?A+;^0w^$FxlB$$+5J>ecm>hS-N26Tkbky@H0-0zxp z5#bXpAt9A;%@dr1UqT*3{EkeN(2bH|G!JDs3x*c}cRaEYs0PH8lB^Z=Ye@Yb zq{;<keoFWoT#*tVON2U^#*@ef0GKHu@g|-M( z&?`V6T;)+GMlxQCIx*m+^FW8nd=cME1zm@e&L?d+@d;_Bg6^e)-i4FSBY~WJ3HgSz zyeiue5KF2&PeIQWL;$vmeJ!V33QUM5F(kw$$Hvyh*4Eu0ZoYG+ZY>2C;BQSBc_YHa z(UHsomP8vMWtBU)GwVajQeX?Jw^S^_LZOQJlJ*4rb(9Fu+lwgnQ6m5PWW79cf{m*U zl?aLwSqeIkcJK#Pnf2O>n3dX#6lw$#7t&dg83-YVudk{=1AxFlIa43v3^pxiDlIGH zD<`mOnt=_q1}A1mH?p1ocTV;9-?g(8Sb@IHn7Nd)6pDyIgmS{`M(D*Qtt zw14ID$0@oN(V^w}o9Zq2q5BaQDm4AQB3(yHzexrWk^=6OF5gUnPK>2=T{&F@x5{)D zesgJgnSKsXasnfe2OwDG^_0rf{oX=Kzez?Da!4kp7C1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M9YGf7epPLVm%EC1wSgGQ;1?vkD^hJGK`W1TLvh@XcRcLg_5X0tS6vQ z&;sZbvqge>ln4q1bs%pM9{dH#^aAe!K?--4iIC7ZAdJm0vHl{28|xH=a#{!Z~m`n;42)=(PLeaJ^GMG3pdw(92lp+ zZ>5kpJ08C04m5c5PmN#94}yrD-UlM~a5zM?_E8YgH_U{Hqk92FJon3h$cMNa?9CFc zSQi8P9z99OxUq=|QxamPih9l*D~_jlk-#vQ!p$YTAjnU-|GKhM&0QWqse@VrY7MA0 zpw@s|18NPZHK5jjS_5hgs5PM0fLa4;4g8A+8ruK!Z(X~!v4gq(>MYp*yL`;W{r_2r zc-n>g|3MJ(Txu9Z{6{*XA>s*IJVe~XPlbs4{y7lw4GBC4!1I7*5b=CqGeoZQ0D4ca zPhmk3l~+q(f^y(l8vRNfX$~ZW#3KbHAK!7O?oc(HebFW1q7G^es5PM0fLa4;4X8Ds z)___AY7MA0pw@s|18NQYf2aZ6KjVfOcgXlW9^a9{mp*XwjL-COuaEDg;JzOB?6`l& zcWrRrk9&N4M+Tqy<38UABEAEMdwo0)FoB5wWG4QLm-r7>;wK*Xu^Dd8tssgZT0_MD zKgJfWb`b3$IzV)U=mfDHM9g=Fs|!R|i129=d<;$CBV students = ExcelUtil.loadDataFromExcel(); + students.forEach(System.out::println); + } + + @Test + public void testExportDataToExcel(){ + List students = ExcelUtil.loadDataFromExcel(); + ExcelUtil.exportDataToExcel(students); + } +} diff --git a/src/test/java/cn/czyx007/week10/test/JsonUtilTest.java b/src/test/java/cn/czyx007/week10/test/JsonUtilTest.java new file mode 100644 index 0000000..34ed4f9 --- /dev/null +++ b/src/test/java/cn/czyx007/week10/test/JsonUtilTest.java @@ -0,0 +1,25 @@ +package cn.czyx007.week10.test; + +import cn.czyx007.week10.bean.Student; +import cn.czyx007.week10.utils.JsonUtil; +import org.junit.Test; + +import java.util.List; + +/** + * @author : 张宇轩 + * @createTime : 2022/11/3 + */ +public class JsonUtilTest { + @Test + public void testLoadDataFromJson(){ + List students = JsonUtil.loadDataFromJson(); + students.forEach(System.out::println); + } + + @Test + public void testExportDataToJson(){ + List students = JsonUtil.loadDataFromJson(); + JsonUtil.exportDataToJson(students); + } +} diff --git a/src/test/java/cn/czyx007/week10/test/StudentUtilTest.java b/src/test/java/cn/czyx007/week10/test/StudentUtilTest.java new file mode 100644 index 0000000..62304ba --- /dev/null +++ b/src/test/java/cn/czyx007/week10/test/StudentUtilTest.java @@ -0,0 +1,43 @@ +package cn.czyx007.week10.test; + +import cn.czyx007.week10.bean.Student; +import cn.czyx007.week10.utils.StudentUtil; +import cn.czyx007.week10.utils.TxtUtil; +import org.junit.Test; + +import java.util.*; + +/** + * @author : 张宇轩 + * @createTime : 2022/11/3 + */ +public class StudentUtilTest { + @Test + public void testCheckIfStudentScoreDuplicate() { + List students = new ArrayList<>(); + students.add(new Student("1001", "张三", "男", "高数", 95.0)); + + Map> studentMap = new HashMap<>(); + List lessons = new ArrayList<>(); + lessons.add("高数"); + lessons.add("英语"); + studentMap.put("1001", lessons); + + if (!StudentUtil.checkIfStudentScoreDuplicate(studentMap, "1001", "高数")) { + System.out.println("Duplicated!"); + students.forEach(System.out::println); + } + } + + @Test + public void testSelectAllScoreById(){ + List students = TxtUtil.loadDataFromTxt(); + StudentUtil.selectAllScoreById("1001", students); + } + + //testInputDataFromKeyBoard + public static void main(String[] args) { + List students = StudentUtil.inputDataFromKeyBoard(); + students.forEach(System.out::println); + } +} diff --git a/src/test/java/cn/czyx007/week10/test/TxtUtilTest.java b/src/test/java/cn/czyx007/week10/test/TxtUtilTest.java new file mode 100644 index 0000000..cd767d0 --- /dev/null +++ b/src/test/java/cn/czyx007/week10/test/TxtUtilTest.java @@ -0,0 +1,25 @@ +package cn.czyx007.week10.test; + +import cn.czyx007.week10.bean.Student; +import cn.czyx007.week10.utils.TxtUtil; +import org.junit.Test; + +import java.util.List; + +/** + * @author : 张宇轩 + * @createTime : 2022/11/3 + */ +public class TxtUtilTest { + @Test + public void testLoadDataFromTxt(){ + List students = TxtUtil.loadDataFromTxt(); + students.forEach(System.out::println); + } + + @Test + public void testExportDataToTxt(){ + List students = TxtUtil.loadDataFromTxt(); + TxtUtil.exportDataToTxt(students); + } +} diff --git a/src/test/java/cn/czyx007/week10/test/UserLoginTest.java b/src/test/java/cn/czyx007/week10/test/UserLoginTest.java new file mode 100644 index 0000000..d487adb --- /dev/null +++ b/src/test/java/cn/czyx007/week10/test/UserLoginTest.java @@ -0,0 +1,35 @@ +package cn.czyx007.week10.test; + +import cn.czyx007.week10.bean.User; +import cn.czyx007.week10.service.UserLogin; +import org.junit.Test; + +/** + * @author : 张宇轩 + * @createTime : 2022/11/3 + */ +public class UserLoginTest { + @Test + public void testLogin(){ + if (UserLogin.login(new User("admin", "123"))) { + System.out.println("true"); + } else System.out.println("false"); + } + + @Test + public void testCheckPassword(){ + if (UserLogin.checkPassword(new User("admin", "123"), "123")){ + System.out.println("true"); + } else System.out.println("false"); + } + + @Test + public void testUpdateUserDataFile(){ + UserLogin.updateUserDataFile(new User("admin", "123")); + } + + //testChangePassword + public static void main(String[] args) { + UserLogin.changePassword(new User("admin", "123")); + } +}