From f74013639a738647ea6b452b26988d813e9e0529 Mon Sep 17 00:00:00 2001 From: Violet <3551664030@qq.com> Date: Wed, 24 Sep 2025 08:50:52 +0800 Subject: [PATCH 01/12] Initial commit: Add Java teacher management system files --- JuniorTea.java | 20 ++++++++++ Main.java | 98 +++++++++++++++++++++++++++++++++++++++++++++++++ PrimaryTea.java | 20 ++++++++++ SeniorTea.java | 20 ++++++++++ Teacher.java | 31 ++++++++++++++++ 5 files changed, 189 insertions(+) create mode 100644 JuniorTea.java create mode 100644 Main.java create mode 100644 PrimaryTea.java create mode 100644 SeniorTea.java create mode 100644 Teacher.java diff --git a/JuniorTea.java b/JuniorTea.java new file mode 100644 index 0000000..527daa8 --- /dev/null +++ b/JuniorTea.java @@ -0,0 +1,20 @@ +public class JuniorTea extends Teacher{ + public JuniorTea(String name, String password) { + super(name, password); + } + + @Override + public boolean checkDuplicate(String question) { + return false; + } + + @Override + public String GenerateEX(int num, int type){ + return null; + } + + @Override + public String getType(){ + return "初中"; + } +} diff --git a/Main.java b/Main.java new file mode 100644 index 0000000..41e8071 --- /dev/null +++ b/Main.java @@ -0,0 +1,98 @@ +import java.util.Scanner; +import java.util.ArrayList; +import java.util.HashMap; + +public class Main { + static ArrayList teachers; // 用户列表 + static Teacher teacher; // 当前用户 + static HashMap type_map; + public static void main(String[] args) { + // 用户预加载 + teachers = new ArrayList<>(); + teachers.add(new PrimaryTea("张三1", "123")); + teachers.add(new PrimaryTea("张三2", "123")); + teachers.add(new PrimaryTea("张三3", "123")); + teachers.add(new JuniorTea("李四1", "123")); + teachers.add(new JuniorTea("李四2", "123")); + teachers.add(new JuniorTea("李四3", "123")); + teachers.add(new SeniorTea("王五1", "123")); + teachers.add(new SeniorTea("王五2", "123")); + teachers.add(new SeniorTea("王五3", "123")); + type_map = new HashMap<>(); + type_map.put("小学", 1); + type_map.put("初中", 2); + type_map.put("高中", 3); + + Scanner scanner = new Scanner(System.in); + while(true){ + boolean flage = false; + while(!flage){ // 登录界面 + System.out.println("--请登录您的账户--"); + System.out.println("用户名:"); + String cur_name = scanner.nextLine(); + System.out.println("密码:"); + String cur_password = scanner.nextLine(); + System.out.println(cur_name + " " + cur_password); + // 匹配已有帐户 + for(Teacher t : teachers){ + if(t.name.equals(cur_name) && t.password.equals(cur_password)){ + teacher = t; + flage = true; + System.out.println("当前选择为" + teacher.getType() + "出题"); + break; + } + } + if(!flage){ + System.out.println("请输入正确的用户名、密码"); + } + } + + int type = type_map.get(teacher.getType()); // 当前出题类型,默认值为当前用户类型 + System.out.println("准备生成" + teacher.getType() + "数学题目,请输入生成题目数量(输入-1将退出当前用户,重新登录):"); + int num = scanner.nextInt(); + while(true){ + while(true){ + try{ + if(num == -1){ + System.out.println("已退出登录"); + main(null); + } + if(num >= 10 && num <=30){ + teacher.GenerateEX(num, type); // 生成题目 + System.out.println("题目生成成功,已保存至" + teacher.path); + break; + } + else { + System.out.println("题目数量应在10-30之间,请重新输入"); + num = scanner.nextInt(); + } + } catch(NumberFormatException e){ + System.out.println("无效输入"); + } + } + + System.out.println("是否切换出题类型(y/n):"); + scanner.nextLine(); // 吸收换行符 + String choice = scanner.nextLine(); + if(choice.equals("y")){ + System.out.println("请输入类型:"); + while(true){ + String choice_type = scanner.nextLine(); + System.out.println(choice_type.substring(0,2) + " " + choice_type.substring(2)); + if(choice_type.substring(0,2).equals("切换") && type_map.containsKey(choice_type.substring(2))){ + type = type_map.get(choice_type.substring(2)); + System.out.println("准备生成" + choice_type.substring(2) + "数学题目,请输入生成题目数量"); + break; + } + else{ + System.out.println("请输入小学、初中和高中三个选项中的一个"); + } + } + } + else System.out.println("请继续输入题目数:"); + num = scanner.nextInt(); + } + + } + } +} diff --git a/PrimaryTea.java b/PrimaryTea.java new file mode 100644 index 0000000..ea13bb6 --- /dev/null +++ b/PrimaryTea.java @@ -0,0 +1,20 @@ +public class PrimaryTea extends Teacher{ + public PrimaryTea(String name, String password) { + super(name, password); + } + + @Override + public boolean checkDuplicate(String question) { + return false; + } + + @Override + public String GenerateEX(int num, int type){ + return null; + } + + @Override + public String getType(){ + return "小学"; + } +} diff --git a/SeniorTea.java b/SeniorTea.java new file mode 100644 index 0000000..d168845 --- /dev/null +++ b/SeniorTea.java @@ -0,0 +1,20 @@ +public class SeniorTea extends Teacher{ + public SeniorTea(String name, String password) { + super(name, password); + } + + @Override + public boolean checkDuplicate(String question) { + return false; + } + + @Override + public String GenerateEX(int num, int type){ + return null; + } + + @Override + public String getType(){ + return "高中"; + } +} diff --git a/Teacher.java b/Teacher.java new file mode 100644 index 0000000..35cc983 --- /dev/null +++ b/Teacher.java @@ -0,0 +1,31 @@ +import java.io.File; +import java.text.SimpleDateFormat; +import java.util.Date; + +abstract class Teacher { + String name; + String password; + String path; + + public Teacher(String name, String password) { + this.name = name; + this.password = password; + // 生成相对路径 + File file = new File(name); + if (!file.exists()) { + file.mkdirs(); + } + Date date = new Date(); + SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd-HH-mm-ss"); + this.path = name + File.separator + sdf.format(date) + ".txt"; + } + + // 查重 + public abstract boolean checkDuplicate(String question); + + // 生成题目 + public abstract String GenerateEX(int num, int type); + + // 返回教师类型 + public abstract String getType(); +} \ No newline at end of file -- 2.34.1 From 0ae42a76b41d22aed4ce9e91a14dfa8528e3828a Mon Sep 17 00:00:00 2001 From: Violet <3551664030@qq.com> Date: Wed, 24 Sep 2025 09:29:57 +0800 Subject: [PATCH 02/12] Commit Test --- JuniorTea.java => src/JuniorTea.java | 1 + Main.java => src/Main.java | 1 + PrimaryTea.java => src/PrimaryTea.java | 1 + SeniorTea.java => src/SeniorTea.java | 1 + Teacher.java => src/Teacher.java | 1 + 5 files changed, 5 insertions(+) rename JuniorTea.java => src/JuniorTea.java (92%) rename Main.java => src/Main.java (97%) rename PrimaryTea.java => src/PrimaryTea.java (92%) rename SeniorTea.java => src/SeniorTea.java (92%) rename Teacher.java => src/Teacher.java (94%) diff --git a/JuniorTea.java b/src/JuniorTea.java similarity index 92% rename from JuniorTea.java rename to src/JuniorTea.java index 527daa8..b9f2b9e 100644 --- a/JuniorTea.java +++ b/src/JuniorTea.java @@ -1,3 +1,4 @@ +package src; public class JuniorTea extends Teacher{ public JuniorTea(String name, String password) { super(name, password); diff --git a/Main.java b/src/Main.java similarity index 97% rename from Main.java rename to src/Main.java index 41e8071..341b848 100644 --- a/Main.java +++ b/src/Main.java @@ -1,3 +1,4 @@ +package src; import java.util.Scanner; import java.util.ArrayList; import java.util.HashMap; diff --git a/PrimaryTea.java b/src/PrimaryTea.java similarity index 92% rename from PrimaryTea.java rename to src/PrimaryTea.java index ea13bb6..c5942df 100644 --- a/PrimaryTea.java +++ b/src/PrimaryTea.java @@ -1,3 +1,4 @@ +package src; public class PrimaryTea extends Teacher{ public PrimaryTea(String name, String password) { super(name, password); diff --git a/SeniorTea.java b/src/SeniorTea.java similarity index 92% rename from SeniorTea.java rename to src/SeniorTea.java index d168845..38a1f94 100644 --- a/SeniorTea.java +++ b/src/SeniorTea.java @@ -1,3 +1,4 @@ +package src; public class SeniorTea extends Teacher{ public SeniorTea(String name, String password) { super(name, password); diff --git a/Teacher.java b/src/Teacher.java similarity index 94% rename from Teacher.java rename to src/Teacher.java index 35cc983..52eb0f8 100644 --- a/Teacher.java +++ b/src/Teacher.java @@ -1,3 +1,4 @@ +package src; import java.io.File; import java.text.SimpleDateFormat; import java.util.Date; -- 2.34.1 From 441574eac6b624791a172abec58a5b2b3ac5274d Mon Sep 17 00:00:00 2001 From: Violet <3551664030@qq.com> Date: Wed, 24 Sep 2025 10:59:19 +0800 Subject: [PATCH 03/12] =?UTF-8?q?=E6=B7=BB=E5=8A=A0=E9=A1=B9=E7=9B=AE?= =?UTF-8?q?=E6=96=87=E6=A1=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- doc/项目说明.md | 0 src/Main.java | 6 +++++- 2 files changed, 5 insertions(+), 1 deletion(-) create mode 100644 doc/项目说明.md diff --git a/doc/项目说明.md b/doc/项目说明.md new file mode 100644 index 0000000..e69de29 diff --git a/src/Main.java b/src/Main.java index 341b848..ad04183 100644 --- a/src/Main.java +++ b/src/Main.java @@ -56,7 +56,7 @@ public class Main { try{ if(num == -1){ System.out.println("已退出登录"); - main(null); + break; // 退出内层循环,返回到登录界面 } if(num >= 10 && num <=30){ teacher.GenerateEX(num, type); // 生成题目 @@ -72,6 +72,10 @@ public class Main { } } + if (num == -1) { + break; // 退出外层循环,返回到登录界面 + } + System.out.println("是否切换出题类型(y/n):"); scanner.nextLine(); // 吸收换行符 String choice = scanner.nextLine(); -- 2.34.1 From 75f10ea2a86678d4a30e8658342455da8b88b566 Mon Sep 17 00:00:00 2001 From: Violet <3551664030@qq.com> Date: Wed, 24 Sep 2025 23:44:53 +0800 Subject: [PATCH 04/12] =?UTF-8?q?=E6=B5=8B=E8=AF=95=E7=89=88?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/JuniorTea.java | 6 +-- src/Main.java | 102 ++++++++++++++++++++++---------------------- src/PrimaryTea.java | 81 ++++++++++++++++++++++++++++++++--- src/SeniorTea.java | 6 +-- src/Teacher.java | 38 +++++++++++++---- 5 files changed, 158 insertions(+), 75 deletions(-) diff --git a/src/JuniorTea.java b/src/JuniorTea.java index b9f2b9e..086bf53 100644 --- a/src/JuniorTea.java +++ b/src/JuniorTea.java @@ -1,14 +1,10 @@ package src; + public class JuniorTea extends Teacher{ public JuniorTea(String name, String password) { super(name, password); } - @Override - public boolean checkDuplicate(String question) { - return false; - } - @Override public String GenerateEX(int num, int type){ return null; diff --git a/src/Main.java b/src/Main.java index ad04183..a654b89 100644 --- a/src/Main.java +++ b/src/Main.java @@ -1,4 +1,5 @@ package src; + import java.util.Scanner; import java.util.ArrayList; import java.util.HashMap; @@ -6,8 +7,10 @@ import java.util.HashMap; public class Main { static ArrayList teachers; // 用户列表 static Teacher teacher; // 当前用户 - static HashMap type_map; + static HashMap typeMap; public static void main(String[] args) { + final int LEAST_NUM = 10, MAX_NUM = 30; + // 用户预加载 teachers = new ArrayList<>(); teachers.add(new PrimaryTea("张三1", "123")); @@ -19,48 +22,73 @@ public class Main { teachers.add(new SeniorTea("王五1", "123")); teachers.add(new SeniorTea("王五2", "123")); teachers.add(new SeniorTea("王五3", "123")); - type_map = new HashMap<>(); - type_map.put("小学", 1); - type_map.put("初中", 2); - type_map.put("高中", 3); + typeMap = new HashMap<>(); + typeMap.put("小学", 1); + typeMap.put("初中", 2); + typeMap.put("高中", 3); - Scanner scanner = new Scanner(System.in); + Scanner scanner = new Scanner(System.in, "GBK"); while(true){ - boolean flage = false; - while(!flage){ // 登录界面 - System.out.println("--请登录您的账户--"); - System.out.println("用户名:"); - String cur_name = scanner.nextLine(); - System.out.println("密码:"); - String cur_password = scanner.nextLine(); - System.out.println(cur_name + " " + cur_password); + boolean flag = false; + while(!flag){ // 登录界面 + System.out.println("-------请登录您的账户-------"); + System.out.println(" 请输入: 用户名 密码 "); + String cur = scanner.nextLine(); + if(cur.indexOf(" ") == -1){ + System.out.println("请输入用户名和密码,中间用空格隔开"); + continue; + } + String cur_name = cur.substring(0, cur.indexOf(" ")); + String cur_password = cur.substring(cur.indexOf(" ") + 1); + // 匹配已有帐户 for(Teacher t : teachers){ if(t.name.equals(cur_name) && t.password.equals(cur_password)){ teacher = t; - flage = true; + flag = true; System.out.println("当前选择为" + teacher.getType() + "出题"); break; } } - if(!flage){ + if(!flag){ System.out.println("请输入正确的用户名、密码"); } } - int type = type_map.get(teacher.getType()); // 当前出题类型,默认值为当前用户类型 - System.out.println("准备生成" + teacher.getType() + "数学题目,请输入生成题目数量(输入-1将退出当前用户,重新登录):"); - int num = scanner.nextInt(); - while(true){ + int type = typeMap.get(teacher.getType()); // 当前出题类型,默认值为当前用户类型 + boolean logout = false; + while(!logout){ + System.out.println("-------是否切换出题类型(y/n)-------"); + String choice = scanner.nextLine(); + if(choice.equals("y")){ + System.out.println("请输入类型:"); + while(true){ + String choice_type = scanner.nextLine(); + if(choice_type.substring(0,2).equals("切换") && typeMap.containsKey(choice_type.substring(2))){ + type = typeMap.get(choice_type.substring(2)); + System.out.println("准备生成" + choice_type.substring(2) + "数学题目,请输入生成题目数量(输入-1将退出当前用户,重新登录):"); + break; + } + else{ + System.out.println("请输入小学、初中和高中三个选项中的一个"); + } + } + } + else if(choice.equals("n")){ + System.out.println("请继续输入题目数量:"); + } + int num = scanner.nextInt(); + scanner.nextLine(); // 吸收换行符 while(true){ try{ if(num == -1){ System.out.println("已退出登录"); - break; // 退出内层循环,返回到登录界面 + logout = true; + break; // 返回到登录界面 } - if(num >= 10 && num <=30){ - teacher.GenerateEX(num, type); // 生成题目 - System.out.println("题目生成成功,已保存至" + teacher.path); + if(num >= LEAST_NUM && num <= MAX_NUM){ + String filepath = teacher.GenerateEX(num, type); // 生成题目 + System.out.println("题目生成成功,已保存至" + filepath); break; } else { @@ -71,33 +99,7 @@ public class Main { System.out.println("无效输入"); } } - - if (num == -1) { - break; // 退出外层循环,返回到登录界面 - } - - System.out.println("是否切换出题类型(y/n):"); - scanner.nextLine(); // 吸收换行符 - String choice = scanner.nextLine(); - if(choice.equals("y")){ - System.out.println("请输入类型:"); - while(true){ - String choice_type = scanner.nextLine(); - System.out.println(choice_type.substring(0,2) + " " + choice_type.substring(2)); - if(choice_type.substring(0,2).equals("切换") && type_map.containsKey(choice_type.substring(2))){ - type = type_map.get(choice_type.substring(2)); - System.out.println("准备生成" + choice_type.substring(2) + "数学题目,请输入生成题目数量"); - break; - } - else{ - System.out.println("请输入小学、初中和高中三个选项中的一个"); - } - } - } - else System.out.println("请继续输入题目数:"); - num = scanner.nextInt(); } - } } } diff --git a/src/PrimaryTea.java b/src/PrimaryTea.java index c5942df..797b80b 100644 --- a/src/PrimaryTea.java +++ b/src/PrimaryTea.java @@ -1,17 +1,86 @@ package src; + +import java.nio.file.Path; +import java.nio.file.Paths; +import java.nio.file.StandardOpenOption; +import java.io.IOException; +import java.util.Random; + public class PrimaryTea extends Teacher{ public PrimaryTea(String name, String password) { super(name, password); } - @Override - public boolean checkDuplicate(String question) { - return false; - } - @Override public String GenerateEX(int num, int type){ - return null; + // 生成题目存储路径 + String curPath = super.generatePath(); + Path filepath = Paths.get(curPath); + + Random random = new Random(); + char[] operators = {'+', '-', '*', '/'}; + + for (int i = 0; i < num; i++) { + int operandCount = random.nextInt(4) + 2; // 2到5个操作数 + StringBuilder question = new StringBuilder(); + + int[] operands = new int[operandCount]; + for (int j = 0; j < operandCount; j++) { + operands[j] = random.nextInt(100) + 1; + } + + // 随机决定是否以及在哪里加括号 (对于3个以上操作数) + boolean useParentheses = operandCount > 2 && random.nextBoolean(); + int parenStartIndex = 0; + if (useParentheses) { + parenStartIndex = random.nextInt(operandCount - 2); + } + + for (int j = 0; j < operandCount; j++) { + if (useParentheses && j == parenStartIndex) { + question.append("("); + } + question.append(operands[j]); + if (useParentheses && j == parenStartIndex + 1) { + question.append(")"); + } + + if (j < operandCount - 1) { + char op = operators[random.nextInt(operators.length)]; + + // 避免除以0 + if (op == '/' && operands[j+1] != 0 && operands[j] % operands[j+1] != 0) { + // 对于小学生,更倾向于可整除的除法 + operands[j] = operands[j+1] * (random.nextInt(10) + 1); + } + + // 避免小学生不熟悉的负数结果 + if (op == '-' && operands[j] < operands[j+1]) { + int temp = operands[j]; + operands[j] = operands[j+1]; + operands[j+1] = temp; + // 更新已经添加到question中的数字 + int start = question.lastIndexOf(String.valueOf(operands[j+1]), question.length() - String.valueOf(operands[j+1]).length() -1); + if(start != -1) { + question.replace(start, start + String.valueOf(operands[j+1]).length(), String.valueOf(operands[j])); + } + } + question.append(" ").append(op).append(" "); + } + } + String qstr = "(" + (i + 1) + ") " + question.toString() + " =\n"; + if(super.checkDuplicate(qstr)){ // 题目查重 + i--; + continue; + } + // 写入文档 + try { + java.nio.file.Files.writeString(filepath, qstr, StandardOpenOption.APPEND); + } catch (IOException e){ + e.printStackTrace(); + } + } + return filepath.toString(); } @Override diff --git a/src/SeniorTea.java b/src/SeniorTea.java index 38a1f94..f0109bf 100644 --- a/src/SeniorTea.java +++ b/src/SeniorTea.java @@ -1,14 +1,10 @@ package src; + public class SeniorTea extends Teacher{ public SeniorTea(String name, String password) { super(name, password); } - @Override - public boolean checkDuplicate(String question) { - return false; - } - @Override public String GenerateEX(int num, int type){ return null; diff --git a/src/Teacher.java b/src/Teacher.java index 52eb0f8..9b73b71 100644 --- a/src/Teacher.java +++ b/src/Teacher.java @@ -1,28 +1,48 @@ package src; + import java.io.File; +import java.io.IOException; import java.text.SimpleDateFormat; import java.util.Date; abstract class Teacher { String name; String password; - String path; + String path = null; public Teacher(String name, String password) { this.name = name; this.password = password; - // 生成相对路径 - File file = new File(name); - if (!file.exists()) { - file.mkdirs(); + File folder = new File(name); // 生成文件夹 + try{ + if(!folder.exists()){ + folder.mkdirs(); + } + } catch(Exception e) { + e.printStackTrace(); } - Date date = new Date(); - SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd-HH-mm-ss"); - this.path = name + File.separator + sdf.format(date) + ".txt"; + path = folder.getAbsolutePath(); } // 查重 - public abstract boolean checkDuplicate(String question); + public boolean checkDuplicate(String question){ + return false; + } + + // 生成存储文档 + public String generatePath(){ + Date date = new Date(); + SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd-HH-mm-ss"); + File file = new File(this.path, sdf.format(date) + ".txt"); + try{ + if(!file.exists()){ + file.createNewFile(); + } + } catch(IOException e){ + e.printStackTrace(); + } + return file.getAbsolutePath(); + } // 生成题目 public abstract String GenerateEX(int num, int type); -- 2.34.1 From 2645345cc4ec201cee6475f9ca208b8af0fc108c Mon Sep 17 00:00:00 2001 From: Violet <3551664030@qq.com> Date: Thu, 25 Sep 2025 11:14:16 +0800 Subject: [PATCH 05/12] =?UTF-8?q?=E6=B5=8B=E8=AF=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/JuniorTea.java | 63 ++++++++++++++++++++++++++++++++++++++++++++- src/Main.java | 19 +++++++++----- src/PrimaryTea.java | 27 +++++++++++-------- src/Teacher.java | 24 +++++++++++++++-- 4 files changed, 112 insertions(+), 21 deletions(-) diff --git a/src/JuniorTea.java b/src/JuniorTea.java index 086bf53..4acaabc 100644 --- a/src/JuniorTea.java +++ b/src/JuniorTea.java @@ -1,5 +1,11 @@ package src; +import java.nio.file.Path; +import java.nio.file.Paths; +import java.nio.file.StandardOpenOption; +import java.io.IOException; +import java.util.Random; + public class JuniorTea extends Teacher{ public JuniorTea(String name, String password) { super(name, password); @@ -7,7 +13,62 @@ public class JuniorTea extends Teacher{ @Override public String GenerateEX(int num, int type){ - return null; + // 生成题目存储路径 + Path filePath = Paths.get(super.generatePath()); + + Random random = new Random(); + String[] operators = {"+", "-", "*", "/", "^2", "√"}; + + for(int i=0; i 2 && random.nextBoolean(); + int parenStartIndex = 0; + if (useParentheses) { + parenStartIndex = random.nextInt(operandCount - 2); + } + + for (int j = 0; j < operandCount; j++) { + if (useParentheses && j == parenStartIndex) { + question.append("("); + } + question.append(operands[j]); + if (useParentheses && j == parenStartIndex + 1) { + question.append(")"); + } + + if(j < operandCount - 1){ + String op = operators[random.nextInt(operators.length)]; + + // 避免除以0 + if (op == "/" && operands[j+1] == 0) { + operands[j+1] = random.nextInt(100) + 1; + } + + question.append(" " + op + " " ); + } + } + String qstr = "(" + (i+1) + ")" + question.toString() + " =\n"; + // 题目查重 + if(super.checkDuplicate(qstr)){ + i--; + continue; + } + // 写入文档 + try { + java.nio.file.Files.writeString(filePath, qstr, StandardOpenOption.APPEND); + } catch (IOException e){ + e.printStackTrace(); + } + } + return filePath.toString(); } @Override diff --git a/src/Main.java b/src/Main.java index a654b89..ca9ed0e 100644 --- a/src/Main.java +++ b/src/Main.java @@ -5,8 +5,10 @@ import java.util.ArrayList; import java.util.HashMap; public class Main { - static ArrayList teachers; // 用户列表 - static Teacher teacher; // 当前用户 + // 用户列表 + static ArrayList teachers; + // 当前用户 + static Teacher teacher; static HashMap typeMap; public static void main(String[] args) { final int LEAST_NUM = 10, MAX_NUM = 30; @@ -30,7 +32,8 @@ public class Main { Scanner scanner = new Scanner(System.in, "GBK"); while(true){ boolean flag = false; - while(!flag){ // 登录界面 + // 登录界面 + while(!flag){ System.out.println("-------请登录您的账户-------"); System.out.println(" 请输入: 用户名 密码 "); String cur = scanner.nextLine(); @@ -55,7 +58,8 @@ public class Main { } } - int type = typeMap.get(teacher.getType()); // 当前出题类型,默认值为当前用户类型 + // 当前出题类型,默认值为当前用户类型 + int type = typeMap.get(teacher.getType()); boolean logout = false; while(!logout){ System.out.println("-------是否切换出题类型(y/n)-------"); @@ -78,16 +82,17 @@ public class Main { System.out.println("请继续输入题目数量:"); } int num = scanner.nextInt(); - scanner.nextLine(); // 吸收换行符 + scanner.nextLine(); while(true){ try{ if(num == -1){ + // 返回到登录界面 System.out.println("已退出登录"); logout = true; - break; // 返回到登录界面 + break; } if(num >= LEAST_NUM && num <= MAX_NUM){ - String filepath = teacher.GenerateEX(num, type); // 生成题目 + String filepath = teacher.GenerateEX(num, type); System.out.println("题目生成成功,已保存至" + filepath); break; } diff --git a/src/PrimaryTea.java b/src/PrimaryTea.java index 797b80b..8181079 100644 --- a/src/PrimaryTea.java +++ b/src/PrimaryTea.java @@ -14,8 +14,7 @@ public class PrimaryTea extends Teacher{ @Override public String GenerateEX(int num, int type){ // 生成题目存储路径 - String curPath = super.generatePath(); - Path filepath = Paths.get(curPath); + Path filePath = Paths.get(super.generatePath()); Random random = new Random(); char[] operators = {'+', '-', '*', '/'}; @@ -47,14 +46,19 @@ public class PrimaryTea extends Teacher{ if (j < operandCount - 1) { char op = operators[random.nextInt(operators.length)]; - - // 避免除以0 - if (op == '/' && operands[j+1] != 0 && operands[j] % operands[j+1] != 0) { - // 对于小学生,更倾向于可整除的除法 - operands[j] = operands[j+1] * (random.nextInt(10) + 1); + + // 处理除法--避免除以0 & 保证可整除 + if (op == '/') { + if(operands[j+1] == 0) { + operands[j+1] = random.nextInt(100) + 1; + } + if(operands[j] % operands[j+1] != 0) { + operands[j+1] = random.nextInt(10) + 1; + operands[j] = operands[j+1] * (random.nextInt(10) + 1); + } } - // 避免小学生不熟悉的负数结果 + // 避免负数结果 if (op == '-' && operands[j] < operands[j+1]) { int temp = operands[j]; operands[j] = operands[j+1]; @@ -69,18 +73,19 @@ public class PrimaryTea extends Teacher{ } } String qstr = "(" + (i + 1) + ") " + question.toString() + " =\n"; - if(super.checkDuplicate(qstr)){ // 题目查重 + // 题目查重 + if(super.checkDuplicate(qstr)){ i--; continue; } // 写入文档 try { - java.nio.file.Files.writeString(filepath, qstr, StandardOpenOption.APPEND); + java.nio.file.Files.writeString(filePath, qstr, StandardOpenOption.APPEND); } catch (IOException e){ e.printStackTrace(); } } - return filepath.toString(); + return filePath.toString(); } @Override diff --git a/src/Teacher.java b/src/Teacher.java index 9b73b71..3297fb7 100644 --- a/src/Teacher.java +++ b/src/Teacher.java @@ -2,18 +2,22 @@ package src; import java.io.File; import java.io.IOException; +import java.nio.file.Files; +import java.nio.file.Paths; +import java.util.List; import java.text.SimpleDateFormat; import java.util.Date; abstract class Teacher { String name; String password; - String path = null; + String path = null; // 教师文件夹路径 public Teacher(String name, String password) { this.name = name; this.password = password; - File folder = new File(name); // 生成文件夹 + // 生成文件夹 + File folder = new File(name); try{ if(!folder.exists()){ folder.mkdirs(); @@ -26,6 +30,22 @@ abstract class Teacher { // 查重 public boolean checkDuplicate(String question){ + File folder = new File(this.path); + File[] files = folder.listFiles(); + if(files == null) return false; + for(File file : files){ + List lines = null; + try { + lines = Files.readAllLines(Paths.get(file.getAbsolutePath())); + for(String line : lines){ + if(line.substring(3).equals(question)){ + return true; + } + } + } catch (IOException e) { + e.printStackTrace(); + } + } return false; } -- 2.34.1 From c10777d74fc02f89c73d68b66c298a551ed41db3 Mon Sep 17 00:00:00 2001 From: Violet <3551664030@qq.com> Date: Sat, 27 Sep 2025 11:33:45 +0800 Subject: [PATCH 06/12] =?UTF-8?q?=E6=93=8D=E4=BD=9C=E6=B5=81=E7=A8=8B?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/SysFunc.java | 124 +++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 124 insertions(+) create mode 100644 src/SysFunc.java diff --git a/src/SysFunc.java b/src/SysFunc.java new file mode 100644 index 0000000..4c2d810 --- /dev/null +++ b/src/SysFunc.java @@ -0,0 +1,124 @@ +package src; + +import java.util.Scanner; +import java.util.ArrayList; +import java.util.HashMap; + +public class SysFunc { + static final int LEAST_NUM = 10; + static final int MAX_NUM = 30; + // 用户列表 + static ArrayList teachers; + // 当前用户 + static Teacher teacher; + static HashMap typeMap; + + public static void init(){ + // 用户预加载 + teachers = new ArrayList<>(); + teachers.add(new PrimaryTea("张三1", "123", null)); + teachers.add(new PrimaryTea("张三2", "123", null)); + teachers.add(new PrimaryTea("张三3", "123", null)); + teachers.add(new JuniorTea("李四1", "123", null)); + teachers.add(new JuniorTea("李四2", "123", null)); + teachers.add(new JuniorTea("李四3", "123", null)); + teachers.add(new SeniorTea("王五1", "123", null)); + teachers.add(new SeniorTea("王五2", "123", null)); + teachers.add(new SeniorTea("王五3", "123", null)); + typeMap = new HashMap<>(); + typeMap.put("小学", 1); + typeMap.put("初中", 2); + typeMap.put("高中", 3); + } + + public static Teacher login(Scanner scanner) { + boolean flag = false; + // 登录界面 + while(!flag){ + System.out.println("-------请登录您的账户-------"); + System.out.println(" 请输入: 用户名 密码 "); + String cur = scanner.nextLine(); + if(cur.indexOf(" ") == -1){ + System.out.println("请输入用户名和密码,中间用空格隔开"); + continue; + } + String cur_name = cur.substring(0, cur.indexOf(" ")); + String cur_password = cur.substring(cur.indexOf(" ") + 1); + + // 匹配已有帐户 + for(Teacher t : teachers){ + if(t.name.equals(cur_name) && t.password.equals(cur_password)){ + teacher = t; + flag = true; + System.out.println("当前选择为" + teacher.getType() + "出题"); + break; + } + } + if(!flag){ + System.out.println("请输入正确的用户名、密码"); + } + } + return teacher; + } + + // 切换类型界面 + public static void ShiftType(Scanner scanner) { + int type = SysFunc.typeMap.get(SysFunc.teacher.getType()); + System.out.println("-------是否切换出题类型(y/n)-------"); + String choice = scanner.nextLine(); + if(choice.equals("y")){ + System.out.println("请输入类型:"); + while(true){ + String choice_type = scanner.nextLine(); + if(choice_type.substring(0,2).equals("切换") && typeMap.containsKey(choice_type.substring(2))){ + type = typeMap.get(choice_type.substring(2)); + if(type == 1){ + teacher = new PrimaryTea(teacher.name, teacher.password, teacher.path); + } + else if(type == 2){ + teacher = new JuniorTea(teacher.name, teacher.password, teacher.path); + } + else{ + teacher = new SeniorTea(teacher.name, teacher.password, teacher.path); + } + System.out.println("准备生成" + teacher.getType() + "数学题目,请输入生成题目数量(输入-1将退出当前用户,重新登录):"); + break; + } + else{ + System.out.println("请输入小学、初中和高中三个选项中的一个"); + } + } + } + else if(choice.equals("n")){ + System.out.println("请继续输入题目数量:"); + } + } + + + // 出题界面 + public static void Operate(Scanner scanner){ + boolean logout = false; + while(!logout){ + SysFunc.ShiftType(scanner); + int num = scanner.nextInt(); + scanner.nextLine(); + while(true){ + if(num == -1) { + // 返回登录界面 + System.out.println("已退出登录"); + logout = true; + break; + } + if(num >= LEAST_NUM && num <= MAX_NUM) { + String filepath = teacher.GenerateEX(num); + System.out.println("题目生成成功,已保存至" + filepath); + break; + } + else { + System.out.println("题目数量应在10-30之间,请重新输入"); + num = scanner.nextInt(); + } + } + } + } +} -- 2.34.1 From ecafacc24923a45819ddc8b2f6a6474dd9f338f9 Mon Sep 17 00:00:00 2001 From: Violet <3551664030@qq.com> Date: Sat, 27 Sep 2025 12:08:56 +0800 Subject: [PATCH 07/12] =?UTF-8?q?=E5=B0=8F=E5=AD=A6=E5=87=BA=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/PrimaryTea.java | 100 +++++++++++++------------------------------- 1 file changed, 29 insertions(+), 71 deletions(-) diff --git a/src/PrimaryTea.java b/src/PrimaryTea.java index 8181079..7e725a1 100644 --- a/src/PrimaryTea.java +++ b/src/PrimaryTea.java @@ -1,95 +1,53 @@ package src; -import java.nio.file.Path; -import java.nio.file.Paths; -import java.nio.file.StandardOpenOption; -import java.io.IOException; import java.util.Random; public class PrimaryTea extends Teacher{ - public PrimaryTea(String name, String password) { - super(name, password); + public PrimaryTea(String name, String password, String path) { + super(name, password, path); } @Override - public String GenerateEX(int num, int type){ - // 生成题目存储路径 - Path filePath = Paths.get(super.generatePath()); - + protected String generateSingleQuestion() { Random random = new Random(); char[] operators = {'+', '-', '*', '/'}; + int operandCount = random.nextInt(4) + 2; // 2到5个操作数 + StringBuilder question = new StringBuilder(); + int[] operands = new int[operandCount]; + for (int j = 0; j < operandCount; j++) { + operands[j] = random.nextInt(100) + 1; + } - for (int i = 0; i < num; i++) { - int operandCount = random.nextInt(4) + 2; // 2到5个操作数 - StringBuilder question = new StringBuilder(); - - int[] operands = new int[operandCount]; - for (int j = 0; j < operandCount; j++) { - operands[j] = random.nextInt(100) + 1; - } + boolean useParen = operandCount > 2 && random.nextBoolean(); + int parenStart = useParen ? random.nextInt(operandCount - 1) : -2; - // 随机决定是否以及在哪里加括号 (对于3个以上操作数) - boolean useParentheses = operandCount > 2 && random.nextBoolean(); - int parenStartIndex = 0; - if (useParentheses) { - parenStartIndex = random.nextInt(operandCount - 2); - } + for (int j = 0; j < operandCount; j++) { + if (j == parenStart) question.append("("); + question.append(operands[j]); + if (j == parenStart + 1) question.append(")"); - for (int j = 0; j < operandCount; j++) { - if (useParentheses && j == parenStartIndex) { - question.append("("); - } - question.append(operands[j]); - if (useParentheses && j == parenStartIndex + 1) { - question.append(")"); + if (j < operandCount - 1) { + char op = operators[random.nextInt(operators.length)]; + if (op == '/') { + operands[j+1] = operands[j+1] == 0 ? 1 : operands[j+1]; } - - if (j < operandCount - 1) { - char op = operators[random.nextInt(operators.length)]; - - // 处理除法--避免除以0 & 保证可整除 - if (op == '/') { - if(operands[j+1] == 0) { - operands[j+1] = random.nextInt(100) + 1; - } - if(operands[j] % operands[j+1] != 0) { - operands[j+1] = random.nextInt(10) + 1; - operands[j] = operands[j+1] * (random.nextInt(10) + 1); - } - } - - // 避免负数结果 - if (op == '-' && operands[j] < operands[j+1]) { - int temp = operands[j]; - operands[j] = operands[j+1]; - operands[j+1] = temp; - // 更新已经添加到question中的数字 - int start = question.lastIndexOf(String.valueOf(operands[j+1]), question.length() - String.valueOf(operands[j+1]).length() -1); - if(start != -1) { - question.replace(start, start + String.valueOf(operands[j+1]).length(), String.valueOf(operands[j])); - } + if (op == '-' && operands[j] < operands[j+1]) { + int temp = operands[j]; + operands[j] = operands[j+1]; + operands[j+1] = temp; + if(question.charAt(question.length() - 1) != ')'){ + question.deleteCharAt(question.length() - 1); + question.append(operands[j]); } - question.append(" ").append(op).append(" "); } - } - String qstr = "(" + (i + 1) + ") " + question.toString() + " =\n"; - // 题目查重 - if(super.checkDuplicate(qstr)){ - i--; - continue; - } - // 写入文档 - try { - java.nio.file.Files.writeString(filePath, qstr, StandardOpenOption.APPEND); - } catch (IOException e){ - e.printStackTrace(); + question.append(" ").append(op).append(" "); } } - return filePath.toString(); + return question.toString(); } @Override public String getType(){ return "小学"; } -} +} \ No newline at end of file -- 2.34.1 From 8f8f1e0016806ac7039827b4fde5ddce42b3fc7d Mon Sep 17 00:00:00 2001 From: Violet <3551664030@qq.com> Date: Sat, 27 Sep 2025 12:41:00 +0800 Subject: [PATCH 08/12] =?UTF-8?q?=E5=88=9D=E7=89=88?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- README.md | 1 - src/JuniorTea.java | 91 +++++++++++----------------- src/Main.java | 101 ++------------------------------ src/PrimaryTea.java | 12 +--- src/SeniorTea.java | 45 ++++++++++++-- src/Teacher.java | 37 ++++++++++-- 张三3/2025-09-27-12-00-37.txt | 29 +++++++++ 李四1/2025-09-27-12-38-25.txt | 23 ++++++++ 李四1/2025-09-27-12-38-53.txt | 23 ++++++++ 9 files changed, 186 insertions(+), 176 deletions(-) create mode 100644 张三3/2025-09-27-12-00-37.txt create mode 100644 李四1/2025-09-27-12-38-25.txt create mode 100644 李四1/2025-09-27-12-38-53.txt diff --git a/README.md b/README.md index a373a1b..cf2db69 100644 --- a/README.md +++ b/README.md @@ -1,2 +1 @@ # Personal_Project - diff --git a/src/JuniorTea.java b/src/JuniorTea.java index 4acaabc..bb329ca 100644 --- a/src/JuniorTea.java +++ b/src/JuniorTea.java @@ -1,78 +1,55 @@ package src; -import java.nio.file.Path; -import java.nio.file.Paths; -import java.nio.file.StandardOpenOption; -import java.io.IOException; import java.util.Random; public class JuniorTea extends Teacher{ - public JuniorTea(String name, String password) { - super(name, password); + public JuniorTea(String name, String password, String path) { + super(name, password, path); } @Override - public String GenerateEX(int num, int type){ - // 生成题目存储路径 - Path filePath = Paths.get(super.generatePath()); - + protected String generateSingleQuestion(){ Random random = new Random(); - String[] operators = {"+", "-", "*", "/", "^2", "√"}; - - for(int i=0; i 2 && random.nextBoolean(); - int parenStartIndex = 0; - if (useParentheses) { - parenStartIndex = random.nextInt(operandCount - 2); - } - - for (int j = 0; j < operandCount; j++) { - if (useParentheses && j == parenStartIndex) { - question.append("("); - } - question.append(operands[j]); - if (useParentheses && j == parenStartIndex + 1) { - question.append(")"); + String[] binaryOps = {"+", "-", "*", "/"}; + String[] unaryOps = {"^2", "√"}; + int operandCount = random.nextInt(4) + 2; + + String[] questionParts = new String[operandCount]; + // 随机应用一个特殊操作符的位置 + int specialOpPos = random.nextInt(operandCount); + + for (int i = 0; i < operandCount; i++) { + int operand = random.nextInt(100) + 1; + if (i == specialOpPos) { + String op = unaryOps[random.nextInt(unaryOps.length)]; + if (op.equals("√")) { + questionParts[i] = op + operand; + } else { + questionParts[i] = operand + op; } + } else { + questionParts[i] = String.valueOf(operand); + } + } - if(j < operandCount - 1){ - String op = operators[random.nextInt(operators.length)]; + StringBuilder question = new StringBuilder(); + boolean useParen = operandCount > 2 && random.nextBoolean(); + int parenStart = useParen ? random.nextInt(operandCount - 1) : -2; - // 避免除以0 - if (op == "/" && operands[j+1] == 0) { - operands[j+1] = random.nextInt(100) + 1; - } + for (int i = 0; i < operandCount; i++) { + if (i == parenStart) question.append("("); + question.append(questionParts[i]); + if (i == parenStart + 1) question.append(")"); - question.append(" " + op + " " ); - } - } - String qstr = "(" + (i+1) + ")" + question.toString() + " =\n"; - // 题目查重 - if(super.checkDuplicate(qstr)){ - i--; - continue; - } - // 写入文档 - try { - java.nio.file.Files.writeString(filePath, qstr, StandardOpenOption.APPEND); - } catch (IOException e){ - e.printStackTrace(); + if (i < operandCount - 1) { + question.append(" ").append(binaryOps[random.nextInt(binaryOps.length)]).append(" "); } } - return filePath.toString(); + return question.toString(); } @Override public String getType(){ return "初中"; } -} +} \ No newline at end of file diff --git a/src/Main.java b/src/Main.java index ca9ed0e..0bc8cd3 100644 --- a/src/Main.java +++ b/src/Main.java @@ -1,110 +1,17 @@ package src; import java.util.Scanner; -import java.util.ArrayList; -import java.util.HashMap; public class Main { - // 用户列表 - static ArrayList teachers; - // 当前用户 - static Teacher teacher; - static HashMap typeMap; public static void main(String[] args) { - final int LEAST_NUM = 10, MAX_NUM = 30; - // 用户预加载 - teachers = new ArrayList<>(); - teachers.add(new PrimaryTea("张三1", "123")); - teachers.add(new PrimaryTea("张三2", "123")); - teachers.add(new PrimaryTea("张三3", "123")); - teachers.add(new JuniorTea("李四1", "123")); - teachers.add(new JuniorTea("李四2", "123")); - teachers.add(new JuniorTea("李四3", "123")); - teachers.add(new SeniorTea("王五1", "123")); - teachers.add(new SeniorTea("王五2", "123")); - teachers.add(new SeniorTea("王五3", "123")); - typeMap = new HashMap<>(); - typeMap.put("小学", 1); - typeMap.put("初中", 2); - typeMap.put("高中", 3); - + SysFunc.init(); Scanner scanner = new Scanner(System.in, "GBK"); while(true){ - boolean flag = false; // 登录界面 - while(!flag){ - System.out.println("-------请登录您的账户-------"); - System.out.println(" 请输入: 用户名 密码 "); - String cur = scanner.nextLine(); - if(cur.indexOf(" ") == -1){ - System.out.println("请输入用户名和密码,中间用空格隔开"); - continue; - } - String cur_name = cur.substring(0, cur.indexOf(" ")); - String cur_password = cur.substring(cur.indexOf(" ") + 1); - - // 匹配已有帐户 - for(Teacher t : teachers){ - if(t.name.equals(cur_name) && t.password.equals(cur_password)){ - teacher = t; - flag = true; - System.out.println("当前选择为" + teacher.getType() + "出题"); - break; - } - } - if(!flag){ - System.out.println("请输入正确的用户名、密码"); - } - } - - // 当前出题类型,默认值为当前用户类型 - int type = typeMap.get(teacher.getType()); - boolean logout = false; - while(!logout){ - System.out.println("-------是否切换出题类型(y/n)-------"); - String choice = scanner.nextLine(); - if(choice.equals("y")){ - System.out.println("请输入类型:"); - while(true){ - String choice_type = scanner.nextLine(); - if(choice_type.substring(0,2).equals("切换") && typeMap.containsKey(choice_type.substring(2))){ - type = typeMap.get(choice_type.substring(2)); - System.out.println("准备生成" + choice_type.substring(2) + "数学题目,请输入生成题目数量(输入-1将退出当前用户,重新登录):"); - break; - } - else{ - System.out.println("请输入小学、初中和高中三个选项中的一个"); - } - } - } - else if(choice.equals("n")){ - System.out.println("请继续输入题目数量:"); - } - int num = scanner.nextInt(); - scanner.nextLine(); - while(true){ - try{ - if(num == -1){ - // 返回到登录界面 - System.out.println("已退出登录"); - logout = true; - break; - } - if(num >= LEAST_NUM && num <= MAX_NUM){ - String filepath = teacher.GenerateEX(num, type); - System.out.println("题目生成成功,已保存至" + filepath); - break; - } - else { - System.out.println("题目数量应在10-30之间,请重新输入"); - num = scanner.nextInt(); - } - } catch(NumberFormatException e){ - System.out.println("无效输入"); - } - } - } + SysFunc.login(scanner); + // 出题界面 + SysFunc.Operate(scanner); } } } diff --git a/src/PrimaryTea.java b/src/PrimaryTea.java index 7e725a1..6cc9ae5 100644 --- a/src/PrimaryTea.java +++ b/src/PrimaryTea.java @@ -11,7 +11,8 @@ public class PrimaryTea extends Teacher{ protected String generateSingleQuestion() { Random random = new Random(); char[] operators = {'+', '-', '*', '/'}; - int operandCount = random.nextInt(4) + 2; // 2到5个操作数 + // 随机决定操作数个数 + int operandCount = random.nextInt(4) + 2; StringBuilder question = new StringBuilder(); int[] operands = new int[operandCount]; for (int j = 0; j < operandCount; j++) { @@ -31,15 +32,6 @@ public class PrimaryTea extends Teacher{ if (op == '/') { operands[j+1] = operands[j+1] == 0 ? 1 : operands[j+1]; } - if (op == '-' && operands[j] < operands[j+1]) { - int temp = operands[j]; - operands[j] = operands[j+1]; - operands[j+1] = temp; - if(question.charAt(question.length() - 1) != ')'){ - question.deleteCharAt(question.length() - 1); - question.append(operands[j]); - } - } question.append(" ").append(op).append(" "); } } diff --git a/src/SeniorTea.java b/src/SeniorTea.java index f0109bf..2d9a0af 100644 --- a/src/SeniorTea.java +++ b/src/SeniorTea.java @@ -1,17 +1,52 @@ package src; +import java.util.Random; + public class SeniorTea extends Teacher{ - public SeniorTea(String name, String password) { - super(name, password); + public SeniorTea(String name, String password, String path) { + super(name, password, path); } @Override - public String GenerateEX(int num, int type){ - return null; + protected String generateSingleQuestion(){ + Random random = new Random(); + String[] binaryOps = {"+", "-", "*", "/"}; + String[] trigOps = {"sin", "cos", "tan"}; + int operandCount = random.nextInt(4) + 2; + + String[] questionParts = new String[operandCount]; + // 随机应用一个三角函数的位置 + int trigOpPos = random.nextInt(operandCount); + + for (int i = 0; i < operandCount; i++) { + int operand = random.nextInt(100) + 1; + if (i == trigOpPos) { + String op = trigOps[random.nextInt(trigOps.length)]; + questionParts[i] = op + "(" + operand + ")"; + } else { + questionParts[i] = String.valueOf(operand); + } + } + + StringBuilder question = new StringBuilder(); + boolean useParen = operandCount > 2 && random.nextBoolean(); + int parenStart = useParen ? random.nextInt(operandCount - 1) : -2; + + for (int i = 0; i < operandCount; i++) { + if (i == parenStart) question.append("("); + question.append(questionParts[i]); + if (i == parenStart + 1) question.append(")"); + + if (i < operandCount - 1) { + String op = binaryOps[random.nextInt(binaryOps.length)]; + question.append(" ").append(op).append(" "); + } + } + return question.toString(); } @Override public String getType(){ return "高中"; } -} +} \ No newline at end of file diff --git a/src/Teacher.java b/src/Teacher.java index 3297fb7..a7a1353 100644 --- a/src/Teacher.java +++ b/src/Teacher.java @@ -3,19 +3,25 @@ package src; import java.io.File; import java.io.IOException; import java.nio.file.Files; +import java.nio.file.Path; import java.nio.file.Paths; +import java.nio.file.StandardOpenOption; import java.util.List; import java.text.SimpleDateFormat; import java.util.Date; -abstract class Teacher { +public abstract class Teacher { String name; String password; String path = null; // 教师文件夹路径 - public Teacher(String name, String password) { + public Teacher(String name, String password, String path) { this.name = name; this.password = password; + if(this.path != null){ + this.path = path; + return ; + } // 生成文件夹 File folder = new File(name); try{ @@ -25,7 +31,7 @@ abstract class Teacher { } catch(Exception e) { e.printStackTrace(); } - path = folder.getAbsolutePath(); + this.path = folder.getAbsolutePath(); } // 查重 @@ -38,7 +44,7 @@ abstract class Teacher { try { lines = Files.readAllLines(Paths.get(file.getAbsolutePath())); for(String line : lines){ - if(line.substring(3).equals(question)){ + if(line.substring(line.indexOf(")") + 2).equals(question)){ return true; } } @@ -64,8 +70,27 @@ abstract class Teacher { return file.getAbsolutePath(); } - // 生成题目 - public abstract String GenerateEX(int num, int type); + // 生成并存储题目 + public String GenerateEX(int num) { + Path filePath = Paths.get(generatePath()); + for (int i = 0; i < num; i++) { + String question = generateSingleQuestion(); + if(checkDuplicate(question)){ + i--; + continue; + } + String qstr = "(" + (i + 1) + ") " + question + " =\n"; + try { + Files.writeString(filePath, qstr, StandardOpenOption.APPEND); + } catch (IOException e) { + e.printStackTrace(); + } + } + return filePath.toString(); + } + + // 生成单个题目 + protected abstract String generateSingleQuestion(); // 返回教师类型 public abstract String getType(); diff --git a/张三3/2025-09-27-12-00-37.txt b/张三3/2025-09-27-12-00-37.txt new file mode 100644 index 0000000..f8f266f --- /dev/null +++ b/张三3/2025-09-27-12-00-37.txt @@ -0,0 +1,29 @@ +(1) 50 / 20 + 70 + 47 = +(2) 37 - 53 - (70 - 4) = +(3) 91 - 354 - (34 - 26) = +(4) 37 + 5 * 12 = +(5) 35 - (30 / 6) * 260 - 27 = +(6) 25 + 8 / 70 - 68 - 14 = +(7) 36 * 94 = +(8) 256 - (23 * 64) = +(9) 51 + 99 * 57 / 1 + 27 = +(10) 3 * 80 - 42 = +(11) 88 * 22 + 80 + 33 = +(12) 91 - 688 - 65 - 30 / 95 = +(13) 78 / (12 + 98) - 94 = +(14) 27 / 13 = +(15) 96 - 7 / 39 - 74 - 4 = +(16) 35 / 99 = +(17) 47 + 95 * 87 = +(18) 59 / 31 = +(19) 60 / 19 = +(20) 70 * 50 * 100 - (7 + 91) = +(21) 51 / 19 - 12 = +(22) 24 + 97 + 82 * 76 = +(23) 97 + 14 - 3 * 281 - 28 = +(24) 87 + 29 / (246 - 29) = +(25) 41 / 27 = +(26) 95 / 43 = +(27) 17 / 24 / 74 = +(28) 79 + 59 = +(29) 74 + 6 + 24 = diff --git a/李四1/2025-09-27-12-38-25.txt b/李四1/2025-09-27-12-38-25.txt new file mode 100644 index 0000000..9d52a5f --- /dev/null +++ b/李四1/2025-09-27-12-38-25.txt @@ -0,0 +1,23 @@ +(1) 83 + √88 + 87 = +(2) (95 / √52) - 33 = +(3) 85 - 70 / √35 * 60 - 59 = +(4) √100 - 25 * 59 + (56 + 23) = +(5) 69^2 * (8 + 82) - 8 + 92 = +(6) 95 * (16^2 / 17) = +(7) 35^2 - 28 = +(8) 51 + (19^2 / 94) = +(9) 63 * √69 - (78 + 76) = +(10) 37 + 9^2 = +(11) 58 * 45 - √86 = +(12) 29 - 11^2 = +(13) 3 + (29 * 49^2) = +(14) 72 + √88 = +(15) 39 * 59 * 5 - 34^2 / 13 = +(16) (99 * 38^2) * 17 + 38 = +(17) 21^2 - 43 = +(18) 10 - 29 * 26 - 92 + √44 = +(19) 95 * 56 * (14 - √100) / 77 = +(20) 95 / 3 * √46 * 35 = +(21) √54 / 17 / 29 / 15 / 43 = +(22) 40^2 + 76 + (54 / 87) + 67 = +(23) 88 * √17 = diff --git a/李四1/2025-09-27-12-38-53.txt b/李四1/2025-09-27-12-38-53.txt new file mode 100644 index 0000000..1fe75a9 --- /dev/null +++ b/李四1/2025-09-27-12-38-53.txt @@ -0,0 +1,23 @@ +(1) 6 / tan(3) - 66 = +(2) 25 + 26 - (13 + 24) * tan(72) = +(3) 85 * tan(94) = +(4) 72 - (36 / tan(93)) = +(5) 57 / (sin(46) * 15) = +(6) 83 * 92 * 31 / tan(23) - 73 = +(7) cos(58) * 79 / 10 = +(8) sin(23) * 25 - 100 - 68 = +(9) 75 - (52 * 39) - 85 - cos(44) = +(10) (52 + 17) * sin(24) - 18 = +(11) 57 / sin(2) - 78 = +(12) (16 / sin(33)) - 25 + 18 * 45 = +(13) cos(71) - 7 + 48 / 86 = +(14) 34 / sin(33) = +(15) 21 / 62 - 93 * 70 + sin(51) = +(16) tan(60) / 6 = +(17) sin(80) - 36 = +(18) 18 + sin(70) = +(19) sin(37) / 45 = +(20) (2 - 69) + tan(97) - 55 - 84 = +(21) 22 + tan(14) = +(22) (cos(39) * 24) - 7 / 43 * 37 = +(23) cos(92) * 30 = -- 2.34.1 From a5c791ba47d0842e7a84b624f069ba2d78e0fa90 Mon Sep 17 00:00:00 2001 From: Violet <3551664030@qq.com> Date: Sat, 27 Sep 2025 14:40:47 +0800 Subject: [PATCH 09/12] =?UTF-8?q?=E5=88=9D=E7=89=88?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/JuniorTea.java | 17 ++++++++++++++--- src/SeniorTea.java | 17 ++++++++++++++--- 张三3/2025-09-27-12-00-37.txt | 29 ----------------------------- 李四1/2025-09-27-12-38-25.txt | 23 ----------------------- 李四1/2025-09-27-12-38-53.txt | 23 ----------------------- 5 files changed, 28 insertions(+), 81 deletions(-) delete mode 100644 张三3/2025-09-27-12-00-37.txt delete mode 100644 李四1/2025-09-27-12-38-25.txt delete mode 100644 李四1/2025-09-27-12-38-53.txt diff --git a/src/JuniorTea.java b/src/JuniorTea.java index bb329ca..13780d2 100644 --- a/src/JuniorTea.java +++ b/src/JuniorTea.java @@ -1,5 +1,7 @@ package src; +import java.util.Arrays; +import java.util.Collections; import java.util.Random; public class JuniorTea extends Teacher{ @@ -15,12 +17,21 @@ public class JuniorTea extends Teacher{ int operandCount = random.nextInt(4) + 2; String[] questionParts = new String[operandCount]; - // 随机应用一个特殊操作符的位置 - int specialOpPos = random.nextInt(operandCount); + // 随机决定特殊操作符的数量 + int specialNum = random.nextInt(operandCount - 1) + 1; + int[] Index = new int[operandCount]; + for(int i=0; i Date: Sat, 27 Sep 2025 18:42:35 +0800 Subject: [PATCH 10/12] =?UTF-8?q?=E5=88=9D=E7=89=88?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- doc/项目说明.md | 124 ++++++++++++++++++++++++++++++++++++++++++++ src/JuniorTea.java | 18 ++++--- src/PrimaryTea.java | 8 ++- src/SeniorTea.java | 18 ++++--- src/SysFunc.java | 43 +++++++-------- src/Teacher.java | 28 +++++----- 6 files changed, 186 insertions(+), 53 deletions(-) diff --git a/doc/项目说明.md b/doc/项目说明.md index e69de29..48cb109 100644 --- a/doc/项目说明.md +++ b/doc/项目说明.md @@ -0,0 +1,124 @@ +# 数学题目生成系统 - 项目说明 + +## 项目概述 + +本项目是一个基于Java的数学题目生成系统,专门为不同学段(小学、初中、高中)的教师设计。系统能够根据教师类型自动生成相应难度的数学题目,并支持题目查重、文件存储等功能。 + +## 项目结构 + +``` +Personal_Project/ +├── src/ # 源代码目录 +│ ├── Main.java # 程序入口类 +│ ├── SysFunc.java # 系统功能类(登录、操作界面) +│ ├── Teacher.java # 教师抽象基类 +│ ├── PrimaryTea.java # 小学教师类 +│ ├── JuniorTea.java # 初中教师类 +│ └── SeniorTea.java # 高中教师类 +├── doc/ # 文档目录 +│ └── 项目说明.md # 项目说明文档 +├── 张三1/ # 教师个人文件夹(自动生成) +├── 张三2/ +├── 张三3/ +├── 李四1/ +├── 李四2/ +├── 李四3/ +├── 王五1/ +├── 王五2/ +└── 王五3/ +``` + +## 核心功能 + +### 1. 用户管理 +- **预置用户**:系统预置了9名教师用户(3名小学、3名初中、3名高中) +- **登录验证**:支持用户名和密码验证登录 +- **个人文件夹**:每个教师登录后自动创建个人文件夹用于存储生成的题目 + +### 2. 题目生成 +- **学段适配**:根据教师类型生成相应难度的数学题目 +- **类型切换**:可以切换指定类型出题 +- **题目数量**:支持一次性生成10-30道题目 +- **随机生成**:题目内容和结构随机生成,确保多样性 + +### 3. 题目类型 +- **小学题目**:包含加减乘除四则运算,支持括号 +- **初中题目**:在小学基础上增加平方(^2)和开方(√)运算 +- **高中题目**:在初中基础上增加三角函数(sin, cos, tan)运算 + +### 4. 查重机制 +- **自动查重**:生成题目时会检查是否与个人历史题目重复 +- **文件扫描**:扫描教师个人文件夹中的所有历史题目文件 +- **重复处理**:发现重复题目会自动重新生成 + +### 5. 文件管理 +- **自动存储**:生成的题目自动保存到教师个人文件夹 +- **时间戳命名**:文件名包含生成时间,便于管理 +- **格式规范**:题目按序号排列,格式统一 + +## 技术特点 + +### 面向对象设计 +- **继承体系**:使用抽象类`Teacher`作为基类,三个具体子类实现不同学段的题目生成 +- **多态应用**:通过抽象方法实现不同学段题目的差异化生成 +- **封装性**:将用户信息、文件操作等功能封装在相应的类中 + +### 算法设计 +- **随机算法**:使用Java Random类确保题目的随机性 +- **括号处理**:智能添加括号,保证表达式合理性 +- **操作符分布**:合理分布不同难度的操作符 + +### 文件操作 +- **NIO API**:使用Java NIO进行高效的文件读写操作 +- **异常处理**:完善的异常处理机制确保程序稳定性 +- **路径管理**:自动创建和管理教师个人文件夹 + +## 使用流程 + +1. **启动程序**:运行Main.java +2. **用户登录**:输入预置的用户名和密码(格式:用户名 密码) +3. **选择模式**:系统显示当前出题类型,可选择切换 +4. **生成题目**:输入题目数量(10-30) +5. **查看结果**:题目生成后显示保存路径 +6. **重复使用**:题目生成后可选择继续生成或切换难度 +7. **退出登录**:输入题目数量为-1则退出当前用户,可重新登录 + +## 预置用户信息 + +| 用户名 | 密码 | 类型 | 初始类型 | +|--------|------|------|----------| +| 张三1 | 123 | 小学教师 | 小学 | +| 张三2 | 123 | 小学教师 | 小学 | +| 张三3 | 123 | 小学教师 | 小学 | +| 李四1 | 123 | 初中教师 | 初中 | +| 李四2 | 123 | 初中教师 | 初中 | +| 李四3 | 123 | 初中教师 | 初中 | +| 王五1 | 123 | 高中教师 | 高中 | +| 王五2 | 123 | 高中教师 | 高中 | +| 王五3 | 123 | 高中教师 | 高中 | + +## 扩展性 + +系统具有良好的扩展性,可以通过以下方式增强功能: +- 添加新的学段类型 +- 增加新的数学运算类型 +- 支持自定义题目难度 +- 添加题目答案计算功能 +- 支持批量导入导出 + +## 开发环境 +- **语言**:Java +- **编码**:GBK(支持中文输入) +- **依赖**:纯Java标准库,无需额外依赖 + +## 项目价值 + +本项目展示了面向对象编程的实际应用,体现了良好的软件工程实践,包括: +- 清晰的代码结构 +- 符合Google编码规范的设计编写 +- 合理,扩展性良好的类设计 +- 完善的异常处理 +- 用户友好的交互界面 +- 实用的业务功能 + +该系统可以实际应用于教育场景,帮助教师快速生成练习题,提高教学效率。 diff --git a/src/JuniorTea.java b/src/JuniorTea.java index 13780d2..bb3b795 100644 --- a/src/JuniorTea.java +++ b/src/JuniorTea.java @@ -20,18 +20,18 @@ public class JuniorTea extends Teacher{ // 随机决定特殊操作符的数量 int specialNum = random.nextInt(operandCount - 1) + 1; int[] Index = new int[operandCount]; - for(int i=0; i= LEAST_NUM && num <= MAX_NUM) { + if (num >= LEAST_NUM && num <= MAX_NUM) { String filepath = teacher.GenerateEX(num); System.out.println("题目生成成功,已保存至" + filepath); break; - } - else { + } else { System.out.println("题目数量应在10-30之间,请重新输入"); num = scanner.nextInt(); } diff --git a/src/Teacher.java b/src/Teacher.java index a7a1353..bdde7d7 100644 --- a/src/Teacher.java +++ b/src/Teacher.java @@ -18,17 +18,17 @@ public abstract class Teacher { public Teacher(String name, String password, String path) { this.name = name; this.password = password; - if(this.path != null){ + if (this.path != null) { this.path = path; - return ; + return; } // 生成文件夹 File folder = new File(name); - try{ - if(!folder.exists()){ + try { + if (!folder.exists()) { folder.mkdirs(); } - } catch(Exception e) { + } catch (Exception e) { e.printStackTrace(); } this.path = folder.getAbsolutePath(); @@ -38,13 +38,15 @@ public abstract class Teacher { public boolean checkDuplicate(String question){ File folder = new File(this.path); File[] files = folder.listFiles(); - if(files == null) return false; - for(File file : files){ + if (files == null) { + return false; + } + for (File file : files) { List lines = null; try { lines = Files.readAllLines(Paths.get(file.getAbsolutePath())); - for(String line : lines){ - if(line.substring(line.indexOf(")") + 2).equals(question)){ + for (String line : lines) { + if (line.substring(line.indexOf(")") + 2).equals(question)) { return true; } } @@ -60,11 +62,11 @@ public abstract class Teacher { Date date = new Date(); SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd-HH-mm-ss"); File file = new File(this.path, sdf.format(date) + ".txt"); - try{ - if(!file.exists()){ + try { + if (!file.exists()) { file.createNewFile(); } - } catch(IOException e){ + } catch (IOException e) { e.printStackTrace(); } return file.getAbsolutePath(); @@ -75,7 +77,7 @@ public abstract class Teacher { Path filePath = Paths.get(generatePath()); for (int i = 0; i < num; i++) { String question = generateSingleQuestion(); - if(checkDuplicate(question)){ + if (checkDuplicate(question)) { i--; continue; } -- 2.34.1 From 199e016c634bac8f06280d362bab578b5bb123e8 Mon Sep 17 00:00:00 2001 From: Violet <3551664030@qq.com> Date: Sun, 28 Sep 2025 11:29:19 +0800 Subject: [PATCH 11/12] =?UTF-8?q?=E5=88=9D=E7=89=88?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- doc/项目说明.md | 12 +++++++----- src/JuniorTea.java | 23 ++++++++++------------- src/SeniorTea.java | 23 ++++++++++------------- src/SysFunc.java | 22 ++++++++++++++++++---- src/Teacher.java | 32 ++++++++++++++++++++++---------- 5 files changed, 67 insertions(+), 45 deletions(-) diff --git a/doc/项目说明.md b/doc/项目说明.md index 48cb109..65af6bd 100644 --- a/doc/项目说明.md +++ b/doc/项目说明.md @@ -60,6 +60,7 @@ Personal_Project/ ### 面向对象设计 - **继承体系**:使用抽象类`Teacher`作为基类,三个具体子类实现不同学段的题目生成 +- **统一方法**:由'Teacher'实现子类都具有的类似结构 - **多态应用**:通过抽象方法实现不同学段题目的差异化生成 - **封装性**:将用户信息、文件操作等功能封装在相应的类中 @@ -76,12 +77,13 @@ Personal_Project/ ## 使用流程 1. **启动程序**:运行Main.java -2. **用户登录**:输入预置的用户名和密码(格式:用户名 密码) +2. **用户登录**:根据提示输入预置的用户名和密码(格式:用户名 密码) 3. **选择模式**:系统显示当前出题类型,可选择切换 -4. **生成题目**:输入题目数量(10-30) -5. **查看结果**:题目生成后显示保存路径 -6. **重复使用**:题目生成后可选择继续生成或切换难度 -7. **退出登录**:输入题目数量为-1则退出当前用户,可重新登录 +4. **切换类型**:输入" 切换** "切换至对应出题类型 +5. **生成题目**:输入题目数量(10-30) +6. **查看结果**:题目生成后显示保存路径 +7. **重复使用**:题目生成后可选择继续生成或切换难度 +8. **退出登录**:输入题目数量为-1则退出当前用户,可重新登录 ## 预置用户信息 diff --git a/src/JuniorTea.java b/src/JuniorTea.java index bb3b795..5fc8e6b 100644 --- a/src/JuniorTea.java +++ b/src/JuniorTea.java @@ -1,7 +1,5 @@ package src; -import java.util.Arrays; -import java.util.Collections; import java.util.Random; public class JuniorTea extends Teacher{ @@ -17,21 +15,20 @@ public class JuniorTea extends Teacher{ int operandCount = random.nextInt(4) + 2; String[] questionParts = new String[operandCount]; - // 随机决定特殊操作符的数量 - int specialNum = random.nextInt(operandCount - 1) + 1; - int[] Index = new int[operandCount]; - for (int i=0; i lines = null; - try { - lines = Files.readAllLines(Paths.get(file.getAbsolutePath())); - for (String line : lines) { - if (line.substring(line.indexOf(")") + 2).equals(question)) { - return true; + if (!file.getName().endsWith(".txt")) { + continue; + } + try (BufferedReader reader = new BufferedReader(new FileReader(file))) { + String line; + while ((line = reader.readLine()) != null) { + if (line.contains(")")) { + try { + String fileQuestion = line.substring(line.indexOf(")") + 2).trim(); + if (fileQuestion.equals(question)) { + return true; + } + } catch (StringIndexOutOfBoundsException e) { + // 继续处理下一行 + continue; + } } } } catch (IOException e) { + System.err.println("读取文件时出错: " + file.getName()); e.printStackTrace(); } } @@ -83,7 +95,7 @@ public abstract class Teacher { } String qstr = "(" + (i + 1) + ") " + question + " =\n"; try { - Files.writeString(filePath, qstr, StandardOpenOption.APPEND); + Files.writeString(filePath, qstr + '\n', StandardOpenOption.APPEND); } catch (IOException e) { e.printStackTrace(); } @@ -96,4 +108,4 @@ public abstract class Teacher { // 返回教师类型 public abstract String getType(); -} \ No newline at end of file +} -- 2.34.1 From db4e07b840cbde3ccd1fa9eb02014ed7c4493345 Mon Sep 17 00:00:00 2001 From: Violet <3551664030@qq.com> Date: Sun, 28 Sep 2025 19:19:07 +0800 Subject: [PATCH 12/12] Version1.0 --- MANIFEST.MF | 3 + Math.bat | 19 ++++ MathQuestionGenerator.jar | Bin 0 -> 10965 bytes doc/项目说明.md | 200 +++++++++++++++++++++++++++++++++++--- src/JuniorTea.class | Bin 0 -> 2496 bytes src/JuniorTea.java | 60 +++++++----- src/Main.class | Bin 0 -> 1302 bytes src/Main.java | 17 ++++ src/PrimaryTea.class | Bin 0 -> 1640 bytes src/PrimaryTea.java | 44 ++++++--- src/SeniorTea.class | Bin 0 -> 2381 bytes src/SeniorTea.java | 49 ++++++---- src/SysFunc.class | Bin 0 -> 5420 bytes src/SysFunc.java | 100 +++++++++++-------- src/Teacher.class | Bin 0 -> 3876 bytes src/Teacher.java | 10 +- 16 files changed, 388 insertions(+), 114 deletions(-) create mode 100644 MANIFEST.MF create mode 100644 Math.bat create mode 100644 MathQuestionGenerator.jar create mode 100644 src/JuniorTea.class create mode 100644 src/Main.class create mode 100644 src/PrimaryTea.class create mode 100644 src/SeniorTea.class create mode 100644 src/SysFunc.class create mode 100644 src/Teacher.class diff --git a/MANIFEST.MF b/MANIFEST.MF new file mode 100644 index 0000000..1f6430b --- /dev/null +++ b/MANIFEST.MF @@ -0,0 +1,3 @@ +Manifest-Version: 1.0 +Main-Class: src.Main +Class-Path: . diff --git a/Math.bat b/Math.bat new file mode 100644 index 0000000..6160956 --- /dev/null +++ b/Math.bat @@ -0,0 +1,19 @@ +@echo off +REM Math Question Generator System - Windows Batch File +REM Author: 赵俊杰 +REM Created: 2025 + +@echo off + +REM Set console encoding to GBK to match scanner input +REM GBK code page is 936, which supports Chinese characters +chcp 936 >nul + +echo Starting Math Question Generator System... +echo. + +REM Execute Java program +java -jar MathQuestionGenerator.jar + +REM Pause after program execution to prevent window from closing immediately +pause diff --git a/MathQuestionGenerator.jar b/MathQuestionGenerator.jar new file mode 100644 index 0000000000000000000000000000000000000000..caa7c2e9eed1b4c54a04fd19cebb8cc86cd6ef87 GIT binary patch literal 10965 zcmaKS1ymkevNaAL?(WWqI|=UY4grF@yGw9)cXxMpcXtQ`cMlTylQ(bPy)*xNQ)~5F z-K$SkSIgPGPt{hC28VzJ0f7MlQBCL32Kk!-Kp;S5MO6gpCFR5z-^W2f6n+my2Z4cs z`TvHZ|91PIp|XN1d(;He#FQEu6@3(bx=k5W6Y*yWxq-z0%uztPp%q< zpLVd z-_bEjOq39;EbsI^@))JdI>R7HyJW%D)5ai;Cb>j?kt zU}z5wq~y8{3G%vB!O2aLx|Sv@oZ~S=%xO~wfZjY@)#|9Ut5Iv(pUQ!Y7RiQ@ z<|BurMD*%u^&{up`>tabp`91UR<(v%lvusT8iPGNp7#&wiGZ`Y`^30u6n7rO64#5% z4?Oo#a;b_XMK+`IK%_G>p$37WL}qiBb+tu1sJ&?}b@P$hAC4AxcG%S$p^~0;27!Sv@7n#F;u}Y?! zRn3W1KY62YCxoZ#*t<6xHMt^<<24kFW+%8PiPf(-4PRixrCz8JiFs!Wbr zya?o)T*TR1u4l73+D;`~rl2^VFGlvNpWS7%PJZT>4nQ+$FCJ;8VjcU)5%~B-O_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jy)_ip;V`f*9PBxS{qmI}w3Z4ZMOS&9iOeDusm0lZ+CAgAZJ}W!|5$iVZmKDCpD^O7Js1@eO z2DLqQ%DrhsZ-s=52|znKZ)@N z-{IoBbhL)e$^%k{MyJVqPB6d2`i#{@>U<|?f1*8m#yfk~K6~bPA9N0~^&Qq5qrCd~ z-GhdPVZOB)iT|xyBuDx~Xh6YWLH=(Q@V}<7_B)wB5&o@n_wNDz&NTn<$-fNrcSipe;P3V1 ne|P`;d;M4UJEDKM{|h-)kcRyIQ2yvwVL)C%K|ltn{~Y~4CGjBf literal 0 HcmV?d00001 diff --git a/doc/项目说明.md b/doc/项目说明.md index 65af6bd..f746afa 100644 --- a/doc/项目说明.md +++ b/doc/项目说明.md @@ -17,6 +17,8 @@ Personal_Project/ │ └── SeniorTea.java # 高中教师类 ├── doc/ # 文档目录 │ └── 项目说明.md # 项目说明文档 +├── MANIFEST.MF # JAVA JAR清单文件 +├── 运行程序.bat # Windows批处理文件 ├── 张三1/ # 教师个人文件夹(自动生成) ├── 张三2/ ├── 张三3/ @@ -72,18 +74,20 @@ Personal_Project/ ### 文件操作 - **NIO API**:使用Java NIO进行高效的文件读写操作 - **异常处理**:完善的异常处理机制确保程序稳定性 -- **路径管理**:自动创建和管理教师个人文件夹 +- **路径管理**:自动创建和管理教师个人文件夹以及题目文档 ## 使用流程 -1. **启动程序**:运行Main.java -2. **用户登录**:根据提示输入预置的用户名和密码(格式:用户名 密码) -3. **选择模式**:系统显示当前出题类型,可选择切换 -4. **切换类型**:输入" 切换** "切换至对应出题类型 -5. **生成题目**:输入题目数量(10-30) -6. **查看结果**:题目生成后显示保存路径 -7. **重复使用**:题目生成后可选择继续生成或切换难度 -8. **退出登录**:输入题目数量为-1则退出当前用户,可重新登录 +1. **保存文件**:将项目保存至同一目录 +2. **启动程序**:在当前目录下双击运行 “运行程序.bat” +3. **用户登录**:根据提示输入预置的用户名和密码(格式:用户名 密码) +4. **选择模式**:系统显示当前出题类型,可选择切换 +5. **切换类型**:输入" 切换** "切换至对应出题类型 +6. **生成题目**:输入题目数量(10-30) +7. **查看结果**:题目生成后显示保存路径 +8. **重复使用**:题目生成后可选择继续生成或切换难度 +9. **退出登录**:输入题目数量为-1则退出当前用户,可重新登录 +10. **退出系统**:可选返回登陆或者退出系统 ## 预置用户信息 @@ -99,9 +103,183 @@ Personal_Project/ | 王五2 | 123 | 高中教师 | 高中 | | 王五3 | 123 | 高中教师 | 高中 | +## API文档 + +### Teacher 抽象基类 + +#### 构造函数 +```java +public Teacher(String name, String password, String path) +``` +- **参数**: + - `name`: 教师用户名 + - `password`: 教师密码 + - `path`: 教师文件夹路径(可为null,自动创建) + +#### 公共方法 +```java +public boolean checkDuplicate(String question) +``` +- **功能**: 检查题目是否与历史题目重复 +- **参数**: `question` - 待检查的题目字符串 +- **返回**: `true` - 存在重复,`false` - 无重复 + +```java +public String generatePath() +``` +- **功能**: 生成题目文件的相对存储路径 +- **返回**: 包含时间戳的文件路径 + +```java +public String generateEX(int num) +``` +- **功能**: 生成指定数量的题目并保存到文件 +- **参数**: `num` - 题目数量(10-30) +- **返回**: 保存题目的文件路径 + +#### 抽象方法 +```java +protected abstract String generateSingleQuestion() +``` +- **功能**: 生成单个题目(由子类实现) +- **返回**: 题目字符串 + +```java +public abstract String getType() +``` +- **功能**: 返回教师类型 +- **返回**: "小学"、"初中"或"高中" + +### SysFunc 系统功能类 + +#### 静态字段 +```java +static final int LEAST_NUM = 10 // 最小题目数量 +static final int MAX_NUM = 30 // 最大题目数量 +static ArrayList teachers // 用户列表 +static Teacher teacher // 当前用户 +static HashMap typeMap // 类型映射 +``` + +#### 静态方法 +```java +public static void init() +``` +- **功能**: 初始化系统,预加载用户数据 + +```java +public static Teacher login(Scanner scanner) +``` +- **功能**: 用户登录界面 +- **参数**: `scanner` - 输入扫描器 +- **返回**: 登录成功的教师对象 + +```java +public static void ShiftType(Scanner scanner) +``` +- **功能**: 切换出题类型界面 +- **参数**: `scanner` - 输入扫描器 + +```java +public static void Operate(Scanner scanner) +``` +- **功能**: 主操作界面,处理题目生成流程 +- **参数**: `scanner` - 输入扫描器 + +### PrimaryTea 小学教师类 + +#### 构造函数 +```java +public PrimaryTea(String name, String password, String path) +``` + +#### 特有方法 +```java +public void getRandom() +``` +- **功能**: 生成随机操作数和括号位置 + +#### 重写方法 +```java +@Override +protected String generateSingleQuestion() +``` +- **功能**: 生成小学难度数学题目(四则运算) + +```java +@Override +public String getType() +``` +- **返回**: "小学" + +### JuniorTea 初中教师类 + +#### 构造函数 +```java +public JuniorTea(String name, String password, String path) +``` + +#### 特有方法 +```java +public void getRandom() +``` +- **功能**: 生成随机操作数、特殊运算符和括号位置 + +#### 重写方法 +```java +@Override +protected String generateSingleQuestion() +``` +- **功能**: 生成初中难度数学题目(四则运算 + 平方/开方) + +```java +@Override +public String getType() +``` +- **返回**: "初中" + +### SeniorTea 高中教师类 + +#### 构造函数 +```java +public SeniorTea(String name, String password, String path) +``` + +#### 特有方法 +```java +public void getRandom() +``` +- **功能**: 生成随机操作数、三角函数和括号位置 + +#### 重写方法 +```java +@Override +protected String generateSingleQuestion() +``` +- **功能**: 生成高中难度数学题目(四则运算 + 三角函数) + +```java +@Override +public String getType() +``` +- **返回**: "高中" + +### Main 程序入口类 + +#### 主方法 +```java +public static void main(String[] args) +``` +- **功能**: 程序入口点,启动数学题目生成系统 +- **流程**: + 1. 初始化系统 + 2. 创建GBK编码的Scanner + 3. 进入主循环(登录 → 操作 → 退出选择) + ## 扩展性 系统具有良好的扩展性,可以通过以下方式增强功能: +- 添加用户注册功能 - 添加新的学段类型 - 增加新的数学运算类型 - 支持自定义题目难度 @@ -109,8 +287,8 @@ Personal_Project/ - 支持批量导入导出 ## 开发环境 -- **语言**:Java -- **编码**:GBK(支持中文输入) +- **语言**:Java21.0.4 +- **编码**:标准输入(scanner)为GBK(支持中文输入),文件保存为UTF-8 - **依赖**:纯Java标准库,无需额外依赖 ## 项目价值 diff --git a/src/JuniorTea.class b/src/JuniorTea.class new file mode 100644 index 0000000000000000000000000000000000000000..33cc0845d604926500e940dbfdb1623539cb75f8 GIT binary patch literal 2496 zcma)8-A@!(6#w1bS!P&=4;K|z!A~s9BBIdN4^Svn>MDr3R0>qfusg!SFthH?Qt5Y- zKKR;=iYP9J@=m9@0>II z{CwdtfYcIeoN zD!%P{&dj+^j&w(E1dE*oECH_UPD)eFCMcsPq`_n1FvWWeWr%vBGm|bR57- zbj+sBM9Q#w(_NM^%HY1CL3wvXN1eP|%h^U|x;LHGP|qm8-@Fw>B^q=bLL*T!ujdSl zr?#%;p?755Ot>v|gCSCRL`M^v1u7?v3A59&6NcNLa>uyJx`r*&sa<=vz+tRzeTp*L zD>B-v@=R>K!v<&MV~^=LjuRwh%CK@~?=|__jp9pMTXmcS>uQrEu)}dI(;#gANSy~t zyUxlahrzUwG3~fZIwV$|I$oD*%~PMYlR+xGbi9Ex0>z`Io39%$&Se#63C1ct`Gh-i zDJyAaf{3A8R{R+a=UE&PskoryA}$eZBb_$wq(H+4fUVEH5VA!>A0yRixJM!!q7Ge9M!YU;Xj$YYl7_QLiCE(V)Skh-w(6 zXw;BmHC=6D4|F<7TFSapws}4`Ibvq|j1h~P5<-}m=rPiT{kBolW^=e^oPBJW7Yk)i z>Ih=rbec!B)`V5){b1b5WfEprN`@+3>D@yTTXq!LbF*&7NcWiTn3H4yv)z0`loeqr zh<9;A#k8!Z_XKKI=}6gA&V*SQCHZpgG7_$nnHKnBE$#)!eDE`DXv@sjbUV&OF8$&O z^sj?5sSVuMHu!Qkt*Q4yh)%<@;wjf`;Z%v)M6S~^vRN~$;zNN0>vG!YsVY7e*!5yp zvYpS1qebIX1~{^01#z`qP6%eBA+f93QCN_bN#HEg8(3EwXI2k6utjeZYRokvMvcn%eESMdmya|p|ov`I;` zGW-zLt)BfyWe)rOC#!be!GSd%r?}o<-F$25FK?mredZIhOTW=khPVS$`j#iXSe|cH z^9u(s<2YMfWtt17Mndqby!)z%bubnuXu=~aqq4f z?kfU!Jx8Y0G6Pkah2lRM_0OTrd%KdHLkHd3ZXr$~mlaC#HoBr!GpqS3@|Cj)ls}i} zXxU9a4+$kH4@3ED>eIev@!$n6mK z20u0v*v%%|gHKo$pJN}s#D3i4H)R2}c!UUkqR+25h$m>kpN#Z3zZV(~i+wmE&Y>9= zZ@PfZ&p4TdvWUG;A;dEdOcj-jDDf?#coBiE?cyoQ#Fz?gi50-V2Q;a2 RpT+y!1-beFAF&j|{{Y9`LWBSS literal 0 HcmV?d00001 diff --git a/src/JuniorTea.java b/src/JuniorTea.java index 5fc8e6b..c5b30a8 100644 --- a/src/JuniorTea.java +++ b/src/JuniorTea.java @@ -1,58 +1,68 @@ package src; -import java.util.Random; - public class JuniorTea extends Teacher{ + final static String[] binaryOps = {"+", "-", "*", "/"}; // 操作符 + final static String[] unaryOps = {"^2", "√"}; + int operandCount; + String[] questionParts; // 操作数 + boolean[] specialOpFlags; // 特殊操作符索引序列 + int parenStart; + int parenEnd; + public JuniorTea(String name, String password, String path) { super(name, password, path); } - @Override - protected String generateSingleQuestion(){ - Random random = new Random(); - String[] binaryOps = {"+", "-", "*", "/"}; - String[] unaryOps = {"^2", "√"}; - int operandCount = random.nextInt(4) + 2; - - String[] questionParts = new String[operandCount]; + // 数据预处理 + public void getRandom(){ + this.operandCount = random.nextInt(4) + 2; + this.questionParts = new String[this.operandCount]; // 随机决定特殊操作符的数量和位置 - int specialNum = Math.min(operandCount, random.nextInt(operandCount) + 1); - boolean[] specialOpFlags = new boolean[operandCount]; + int specialNum = Math.min(this.operandCount, random.nextInt(this.operandCount) + 1); + this.specialOpFlags = new boolean[this.operandCount]; for (int i = 0; i < specialNum; i++) { int pos; do { - pos = random.nextInt(operandCount); - } while (specialOpFlags[pos]); - specialOpFlags[pos] = true; + pos = random.nextInt(this.operandCount); + } while (this.specialOpFlags[pos]); + this.specialOpFlags[pos] = true; } - - for (int i = 0; i < operandCount; i++) { + for (int i = 0; i < this.operandCount; i++) { int operand = random.nextInt(100) + 1; - if (specialOpFlags[i]) { + if (this.specialOpFlags[i]) { String op = unaryOps[random.nextInt(unaryOps.length)]; if (op.equals("√")) { - questionParts[i] = op + operand; + this.questionParts[i] = op + operand; } else { - questionParts[i] = operand + op; + this.questionParts[i] = operand + op; } } else { - questionParts[i] = String.valueOf(operand); + this.questionParts[i] = String.valueOf(operand); } } + // 生成有效括号 + boolean useParen = this.operandCount > 2 && random.nextBoolean(); + this.parenStart = 0; + this.parenEnd = this.operandCount - 1; + while (this.parenStart == 0 && this.parenEnd == this.operandCount - 1) { + this.parenStart = useParen ? random.nextInt(this.operandCount - 1) : -2; + this.parenEnd = useParen ? random.nextInt(this.operandCount - 1 - this.parenStart) + this.parenStart + 1 : -2; + } + } + @Override + protected String generateSingleQuestion(){ + getRandom(); StringBuilder question = new StringBuilder(); - boolean useParen = operandCount > 2 && random.nextBoolean(); - int parenStart = useParen ? random.nextInt(operandCount - 1) : -2; for (int i = 0; i < operandCount; i++) { if (i == parenStart) { question.append("("); } question.append(questionParts[i]); - if (i == parenStart + 1) { + if (i == parenEnd) { question.append(")"); } - if (i < operandCount - 1) { question.append(" ").append(binaryOps[random.nextInt(binaryOps.length)]).append(" "); } diff --git a/src/Main.class b/src/Main.class new file mode 100644 index 0000000000000000000000000000000000000000..d2953ecd4973ade72bc74b359c51da5ae4f0c987 GIT binary patch literal 1302 zcmZuxSx*yD7(EwCryVZ}WfPS}RBQn$?n`k&1O&@wYjJrRh8q}dr_C@m@@mxh;Dd=8 zcO@Ey7lZOpiAH_*SNI?W|AH~%cUugg%p`a2@-63_@4NH$_lM5_T5wK94ssPZIP&0R zD7dIy*8EY;9QOAPUKF~`;A}Qb!#={0>-9xcxZqZxa;%Z&Yep^I9~v8NPntS|LmDc` zXDG~sN!mu#AJR3`6qXz7P@tfY!-Jv~dC1)sF@_w&WGD${JdL=&(@Z4okZlPq7I2}2 z(svv`rGleOLS4^L=Uvq{yP07?-iA3G$fDlBu@RdX@}lu!nW<*ceL2X0FDMCxg{F@P zD8g$qNw9`v3$_x}c#?!$;?hSrmblb1tWQ6fn!Wvc{>$Cj z$Is>-e*E$9hIhU9QgxcPu&iXl7DH`Ubdj))xT)eKIu&$roI-Gg65$c*!XbwIMQnf9D+SH& z5{8rL;pmmu!%bz%=26g3wUEu#t;z0lw8n?1B-WAM@joIfb(c0#1c{$ z{V70za-pIC`6!_aR*phq=0Por(1c>_rrpCRC7&{qy__O!q!^VHWfLwCR}Iw|B990~ eDueTv`~~q}s8O)1xL-lrPdKGK19Y5&vwr}g(NI|c literal 0 HcmV?d00001 diff --git a/src/Main.java b/src/Main.java index 0bc8cd3..c2879af 100644 --- a/src/Main.java +++ b/src/Main.java @@ -1,6 +1,7 @@ package src; import java.util.Scanner; +import java.util.concurrent.TimeUnit; public class Main { public static void main(String[] args) { @@ -12,6 +13,22 @@ public class Main { SysFunc.login(scanner); // 出题界面 SysFunc.Operate(scanner); + // 退出选项 + System.out.println("是否返回登陆(y/n)?"); + String choice = scanner.nextLine(); + if (choice.charAt(0) == 'y') { + continue; + } else if (choice.charAt(0) == 'n') { + System.out.println("感谢您的使用"); + break; + } else { + System.out.println("无效输入, 正在返回登陆界面"); + try { + TimeUnit.SECONDS.sleep(1); + } catch (InterruptedException e) { + Thread.currentThread().interrupt(); + } + } } } } diff --git a/src/PrimaryTea.class b/src/PrimaryTea.class new file mode 100644 index 0000000000000000000000000000000000000000..5d2983938ecf99ff4f58d55d5eae3cbd90ea0fe7 GIT binary patch literal 1640 zcma)6+inwA6kW$2XC}@N8z;m-oP>s(FC=ccCQS&CKuSs=(A?zqp&sl}aO;e%$+#*H ztyGC;`qCG8ilU0Vv=S}EsanJb^gGH=M3i*xvC~vdkt$2G_t}?q&RKgM|NiFJmjJHd zb{GK!b!a9+Xi;ceaSPcw+bZ0%U4@p>l2h`=6o!-2pIKj6*|OywpDmBR~KY7r^AskjPn#mP~z$a6(Pr^hG zdP#sFj#nyW+j10w$<)UJdc?##0vfJbuItoa%5Gjwo_CX_>VE9_ROIP zN%~SaD-h=t5~Sy?g$6Eg%aq(`*u?u7;o*IPyo&2HG-2Q(D~<@_B|*F_h!bx|l)`Zn z6Szupyh=kc3Z2QlEh7dddBs;xzkT)N6V7p>QnVE!(srBtY zBpdo3`z2FH_ao@qI<(+uI=F#8A4e;0pr7f!$C#xNw?iwgVlvI@4(V$|h`NqY^o{f} z)3=+U*C(5b&1?B)RsZ_-4|2nRf5X$f8Tdxq5hHsY=tn2c&<-PxJB%#w(dEgZhi*JX z0-NZ?6gw^;{F>w1Lhpgg>NO(jo(^N1^aN;|-@@Kdh{Sz}t4$h{9D)%4C|$?#-;l~} zA~PMln2?LD;Ty4is|aUe19fBf#A4@Aqr@!N)$?Z9B`EOl*`WJ#~!v&fGQzroBFB3r&(r*~N6Ao!knm|*OhoUfr&(K4ug12=b6%H4%rpj&?t$_1mD h`J5IVn9qfx>G@nsG&}zcL%ULM0BD4{#g+hO{sKzPNN)fD literal 0 HcmV?d00001 diff --git a/src/PrimaryTea.java b/src/PrimaryTea.java index 1b1512b..5b0f2d8 100644 --- a/src/PrimaryTea.java +++ b/src/PrimaryTea.java @@ -1,40 +1,52 @@ package src; -import java.util.Random; - public class PrimaryTea extends Teacher{ + final static char[] operators = {'+', '-', '*', '/'}; // 操作符 + int operandCount; // 操作数个数 + int[] operands; // 操作数列表 + int parenStart; // 左括号索引 + int parenEnd; // 右括号 + public PrimaryTea(String name, String password, String path) { super(name, password, path); } - @Override - protected String generateSingleQuestion() { - Random random = new Random(); - char[] operators = {'+', '-', '*', '/'}; + // 数据预处理 + public void getRandom(){ // 随机决定操作数个数 - int operandCount = random.nextInt(4) + 2; - StringBuilder question = new StringBuilder(); - int[] operands = new int[operandCount]; + this.operandCount = random.nextInt(4) + 2; + this.operands = new int[operandCount]; for (int j = 0; j < operandCount; j++) { operands[j] = random.nextInt(100) + 1; } + // 产生有效括号 + boolean useParen = this.operandCount > 2 && random.nextBoolean(); + this.parenStart = 0; + this.parenEnd = this.operandCount - 1; + while (this.parenStart == 0 && this.parenEnd == this.operandCount - 1) { + this.parenStart = useParen ? random.nextInt(this.operandCount - 1) : -2; + this.parenEnd = useParen ? random.nextInt(this.operandCount - 1 - this.parenStart) + this.parenStart + 1 : -2; + } + } - boolean useParen = operandCount > 2 && random.nextBoolean(); - int parenStart = useParen ? random.nextInt(operandCount - 1) : -2; + @Override + protected String generateSingleQuestion() { + getRandom(); + StringBuilder question = new StringBuilder(); - for (int j = 0; j < operandCount; j++) { - if (j == parenStart) { + for (int j = 0; j < this.operandCount; j++) { + if (j == this.parenStart) { question.append("("); } question.append(operands[j]); - if (j == parenStart + 1) { + if (j == this.parenEnd) { question.append(")"); } - if (j < operandCount - 1) { + if (j < this.operandCount - 1) { char op = operators[random.nextInt(operators.length)]; if (op == '/') { - operands[j+1] = operands[j+1] == 0 ? 1 : operands[j+1]; + this.operands[j+1] = this.operands[j+1] == 0 ? 1 : this.operands[j+1]; } question.append(" ").append(op).append(" "); } diff --git a/src/SeniorTea.class b/src/SeniorTea.class new file mode 100644 index 0000000000000000000000000000000000000000..ff62a8fb80919c521c90ecdd2c3d8b3594904542 GIT binary patch literal 2381 zcma)8OH&kA6#g#LLpNjda8MD2_yFQOL=+6lLqt*HD2O^lf|!J6riGTKdz|S(NwUZy ze;_+`6N^d}i0WvS%5JtL4nSt)Az+flaw=s%6+TQd4GDptRd^EU!nPBQkK^m^E5#!l_bj{RlE2m!LIo;SRO#4^ zut1d`!5RYr)iG~*3C9yqB8g~1p0!2CR%{c{-Ha)H_qlng7YP;HU;9{-h1{}3$4=BS zwi|gf=UJ|E!N__!f$FjKDTeSCcB$B{V-NNURIH*hXn0csff>sY2u2dca2jI=bYt<}aUi(jhJ$)6s+D0%en?SD@4Pb6Ld+Cbo)Np_WeO zEjw*yL+C}HEX3m)PLs2UTzFT<86;RKMkZrAX@TYql3$-s(Pfv0bMzFIfez|8FR?D0 zupA>hN3=CupmMi7=8}#ihM9%u7Ge_E5?Sw-{w_0?Kfb>G`{QpkywB}%4Ob|dHC&~L zY50($MZ-8V&RLFz2@X;&4`c8FGRSJ}bJM0k<$&dw=kqfYW_H+^u(?uBR8!M~My5F5 zHfcI6W6w;o<81R{u|UZtaUGt^aEsQRvWs0BO1k-M%IvqKtBRE_J0Rg^?UPV1=Vgt| zpy^GyX$Isn6cG{8%2M12A&Z;}PZnQZpmCKW%b9hj&0^aZ>apKQd2V)2;PzTFiiQRE zXV`qUnQI(y-RXSh&9}wBHp;X%Fkjn@Llf7{l-ISEo}!CB!?u%_XLj)hNI1l<&o**7 zlZo9DXj+%kMxmBZse&u)uEGxSH|>KoIuwgNgsLu~ zJUG6HYB{U^2{ntTl_RN>l4@oAG3vX0{g28b8Un}acFv<|jYSW~4fSnzm;dqy%JAnU zVqy6=8cG-QI4fwyy0CnjT=ET&H+SO>3vZS#4ddQvU=oAi02Yf1&;{4kUet z4>_+6eud3)+Y(yuKvfo?1dhc5i)i-)RMLy+pt}7ok`!`St)%avKUQ~VH7P}gvVdUK zE4h!FUD9L0mfv=%mU3JfFIsghEZ>*VmiW+4kTf7nV5?C}+76JIqo^UoJ8+JV!!QXP zX@k^Y~V@UMvDPwW>eukwRv!6Z*epze=y?HHy>ZZ#cx+YY-eo(ZH(kFbhHz~BZTBA-@i`2KwTVl6VT%Xp%g^FIWtu{(Hn3%Pa-cHU0T?fMN$TGmWDq_evg6Dg6bowGNdZS)qVf%GKHiEiRv`HmB7XfrN$F8{5hEA NEX2`G%;6K%{sZmRB1ixL literal 0 HcmV?d00001 diff --git a/src/SeniorTea.java b/src/SeniorTea.java index 5c65b03..3db2525 100644 --- a/src/SeniorTea.java +++ b/src/SeniorTea.java @@ -1,31 +1,32 @@ package src; -import java.util.Random; - public class SeniorTea extends Teacher{ + final static String[] binaryOps = {"+", "-", "*", "/"}; // 操作符 + final static String[] trigOps = {"sin", "cos", "tan"}; + int operandCount; + String[] questionParts; // 操作数 + boolean[] specialOpFlags; // 特殊操作符索引序列 + int parenStart; + int parenEnd; + public SeniorTea(String name, String password, String path) { super(name, password, path); } - @Override - protected String generateSingleQuestion(){ - Random random = new Random(); - String[] binaryOps = {"+", "-", "*", "/"}; - String[] trigOps = {"sin", "cos", "tan"}; - int operandCount = random.nextInt(4) + 2; - - String[] questionParts = new String[operandCount]; + // 数据预处理 + public void getRandom(){ + this.operandCount = random.nextInt(4) + 2; + this.questionParts = new String[this.operandCount]; // 随机决定特殊操作符的数量和位置 - int specialNum = Math.min(operandCount, random.nextInt(operandCount) + 1); - boolean[] specialOpFlags = new boolean[operandCount]; + int specialNum = Math.min(this.operandCount, random.nextInt(this.operandCount) + 1); + this.specialOpFlags = new boolean[this.operandCount]; for (int i = 0; i < specialNum; i++) { int pos; do { - pos = random.nextInt(operandCount); - } while (specialOpFlags[pos]); - specialOpFlags[pos] = true; + pos = random.nextInt(this.operandCount); + } while (this.specialOpFlags[pos]); + this.specialOpFlags[pos] = true; } - for (int i = 0; i < operandCount; i++) { int operand = random.nextInt(100) + 1; if (specialOpFlags[i]) { @@ -35,17 +36,27 @@ public class SeniorTea extends Teacher{ questionParts[i] = String.valueOf(operand); } } + // 生成有效括号 + boolean useParen = this.operandCount > 2 && random.nextBoolean(); + this.parenStart = 0; + this.parenEnd = this.operandCount - 1; + while (this.parenStart == 0 && this.parenEnd == this.operandCount - 1) { + this.parenStart = useParen ? random.nextInt(this.operandCount - 1) : -2; + this.parenEnd = useParen ? random.nextInt(this.operandCount - 1 - this.parenStart) + this.parenStart + 1 : -2; + } + } + @Override + protected String generateSingleQuestion(){ + getRandom(); StringBuilder question = new StringBuilder(); - boolean useParen = operandCount > 2 && random.nextBoolean(); - int parenStart = useParen ? random.nextInt(operandCount - 1) : -2; for (int i = 0; i < operandCount; i++) { if (i == parenStart) { question.append("("); } question.append(questionParts[i]); - if (i == parenStart + 1) { + if (i == parenEnd) { question.append(")"); } diff --git a/src/SysFunc.class b/src/SysFunc.class new file mode 100644 index 0000000000000000000000000000000000000000..80d0c9c898079a600c1161e924c2b4dc2a224c76 GIT binary patch literal 5420 zcma)A30PFu75=X*^BA7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ym2EdY2yl1M7;xN`Scs$7fp;1p)+c%~wf=`F(K@j_P zA7o(~Q%HJjK1c6(7rJulvj5Vl&bEdtr;ZvlOuFGvVsC=(uS~m90ftko6Yr)2fhk_w z?>*UYrRKaC7%5b<=r0DC#6X^2Vi57!O(8b>I>%b;B;%km4z#&iAzSZ zPVfIcWnM4XR^-DYsQ&}U{Sljk^L#+LBSiL6_J_zOE5y|g==-sXS75t4zY=$_?hQMe1%5LyU7=_QfOvQAzUm5%hiR7d@D^lxFq`g9v&@YM5#~h(gzjL>WL`<|Fk=+s6^F@0 z#T<;``)4d{7>6e?9$Rr64&!#big>(+1iZuN>id`gACefvYxsfzWxT}-gfpzb8)2E} zaF1o72aDwIa{k6P;$_)h5zyW5!Ky?LwE0PvVh?Qn4q|}pcCfqY`nySChT4Ni@{){Z z_(L94q=z#D9;{D~h>5s}Cj|Cju53Lc@H(o~BV!^jpf=fqEqgFQwztNF>%z#G$n)49 zF1ihN88Mf_bxQl)|SXN;;+mk7!Fh;4c@YXgAQy8(S zjLLLIVFp`w@H&&uw{#|Q*;>KYdd%Xzd^UD5nhks;pFlQV!QD8Gc{q<8wDDXs6~w;) literal 0 HcmV?d00001 diff --git a/src/SysFunc.java b/src/SysFunc.java index 1e582c1..a8b0be7 100644 --- a/src/SysFunc.java +++ b/src/SysFunc.java @@ -1,17 +1,29 @@ package src; -import java.util.Scanner; import java.util.ArrayList; import java.util.HashMap; +import java.util.Scanner; public class SysFunc { + // 题目数量 static final int LEAST_NUM = 10; static final int MAX_NUM = 30; // 用户列表 static ArrayList teachers; // 当前用户 - static Teacher teacher; + static Teacher teacher; + static HashMap typeMap; + + // ANSI颜色代码 + static final String RESET = "\u001B[0m"; + static final String RED = "\u001B[31m"; + static final String GREEN = "\u001B[32m"; + static final String YELLOW = "\u001B[33m"; + static final String BLUE = "\u001B[34m"; + static final String PURPLE = "\u001B[35m"; + static final String CYAN = "\u001B[36m"; + static final String BOLD = "\u001B[1m"; public static void init(){ // 用户预加载 @@ -31,15 +43,18 @@ public class SysFunc { typeMap.put("高中", 3); } + // 登陆界面 public static Teacher login(Scanner scanner) { boolean flag = false; - // 登录界面 - while(!flag){ - System.out.println("-------请登录您的账户-------"); - System.out.println(" 请输入: 用户名 密码 "); + System.out.println(BOLD + CYAN + "=== 数学题目生成系统 ===" + RESET); + System.out.println(BOLD + CYAN + "请登录您的账户" + RESET); + while (!flag) { + System.out.println(BOLD + YELLOW + "请输入: 用户名 密码" + RESET); + System.out.print(BOLD + BLUE + "> " + RESET); + String cur = scanner.nextLine(); if (cur.indexOf(" ") == -1) { - System.out.println("请输入用户名和密码,中间用空格隔开"); + System.out.println(RED + "请输入用户名和密码,中间用空格隔开"); continue; } String cur_name = cur.substring(0, cur.indexOf(" ")); @@ -50,46 +65,50 @@ public class SysFunc { if (t.name.equals(cur_name) && t.password.equals(cur_password)) { teacher = t; flag = true; - System.out.println("当前选择为" + teacher.getType() + "出题"); + System.out.println(GREEN + "当前选择为" + teacher.getType() + "出题"); break; } } if (!flag) { - System.out.println("请输入正确的用户名、密码"); + System.out.println(RED + "请输入正确的用户名、密码"); } } - return teacher; + return teacher; } // 切换类型界面 public static void ShiftType(Scanner scanner) { int type = SysFunc.typeMap.get(SysFunc.teacher.getType()); - System.out.println("-------是否切换出题类型(y/n)-------"); - String choice = scanner.nextLine(); - if (choice.equals("y")) { - System.out.println("请输入类型(切换**)支持小学,初中,高中难度:"); - while (true) { - String choice_type = scanner.nextLine(); - if (choice_type.substring(0, 2).equals("切换") && typeMap.containsKey(choice_type.substring(2))) { - type = typeMap.get(choice_type.substring(2)); - if (type == 1) { - teacher = new PrimaryTea(teacher.name, teacher.password, teacher.path); - } else if (type == 2) { - teacher = new JuniorTea(teacher.name, teacher.password, teacher.path); - } else { - teacher = new SeniorTea(teacher.name, teacher.password, teacher.path); - } - System.out.println("准备生成" + teacher.getType() + "数学题目,请输入生成题目数量(输入-1将退出当前用户,重新登录):"); - break; + System.out.println(BOLD + PURPLE + "=== 是否切换出题类型(y/n) ===" + RESET); + System.out.print(BOLD + BLUE + "> " + RESET); + + String choice = scanner.nextLine(); + if (choice.equals("y")) { + System.out.println(BOLD + YELLOW + "请输入指令: 切换** (支持小学,初中,高中难度): " + RESET); + while (true) { + System.out.print(BOLD + BLUE + "> " + RESET); + String choice_type = scanner.nextLine(); + if (choice_type.substring(0, 2).equals("切换") && typeMap.containsKey(choice_type.substring(2))) { + type = typeMap.get(choice_type.substring(2)); + if (type == 1) { + teacher = new PrimaryTea(teacher.name, teacher.password, teacher.path); + } else if (type == 2) { + teacher = new JuniorTea(teacher.name, teacher.password, teacher.path); } else { - System.out.println("请输入小学、初中和高中三个选项中的一个"); + teacher = new SeniorTea(teacher.name, teacher.password, teacher.path); } + System.out.println(GREEN + "准备生成" + teacher.getType() + "数学题目,请输入生成题目数量(输入-1将退出当前用户,重新登录):"); + break; + } else { + System.out.println(RED + RESET + "请输入小学、初中和高中三个选项中的一个"); } - } else if (choice.equals("n")) { - System.out.println("请继续输入题目数量:"); - } else { - System.out.println("无效输入,已为您设置默认类型"); } + } else if (choice.equals("n")) { + System.out.println(GREEN + "请继续输入题目数量:"); + } else { + System.out.println(RED + RESET + "无效输入,已为您设置默认类型:" + teacher.getType()); + System.out.println(GREEN + "请输入题目数量:"); + } } @@ -101,30 +120,33 @@ public class SysFunc { int num = 0; while (true) { try { + System.out.print(BOLD + BLUE + "> " + RESET); String input = scanner.nextLine(); num = Integer.parseInt(input); break; } catch (NumberFormatException e) { - System.out.println("请输入有效的数字(10-30之间的整数,或-1退出登录):"); + System.out.println(RED + RESET + "请输入有效的数字(10-30之间的整数,或-1退出登录):"); } } while (true) { if (num == -1) { - // 返回登录界面 - System.out.println("已退出登录"); + System.out.println(BOLD + YELLOW + "已退出登录" + RESET); logout = true; break; } if (num >= LEAST_NUM && num <= MAX_NUM) { - String filepath = teacher.GenerateEX(num); - System.out.println("题目生成成功,已保存至" + filepath); + System.out.println(BOLD + GREEN + "正在生成题目..." + RESET); + String filepath = teacher.generateEX(num); + System.out.println(GREEN + RESET + "题目生成成功,已保存至" + filepath); + System.out.println(BOLD + CYAN + "=== 操作完成 ===" + RESET); break; } else { - System.out.println("题目数量应在10-30之间,请重新输入"); + System.out.println(RED + RESET + "题目数量应在10-30之间,请重新输入"); try { + System.out.print(BOLD + BLUE + "> " + RESET); num = Integer.parseInt(scanner.nextLine()); } catch (NumberFormatException e) { - System.out.println("请输入有效的数字:"); + System.out.println(RED + RESET + "请输入有效的数字:"); } } } diff --git a/src/Teacher.class b/src/Teacher.class new file mode 100644 index 0000000000000000000000000000000000000000..4242b0ffa23500e43aff329b409a8d4c95c4ff37 GIT binary patch literal 3876 zcmaJ^`+pQy75`55F}s@~Kp?;d)25V1He}gKY1-^U3JI^&ykJvkD6~v=C&{u;c4r~f zV$mX~C>2|2!HN~Fsfuku*w93Zk4kOT`tD!Q_M`sb&z27*e(%igW@A*eK9pL2gdS)kk&K=(g54!1mMU0gOvIz%NID~9g@k!i z@ogFjX(>IDOt`Qd9tDj8#MvnZtp{~A6zxl^A;X0x1zxP;+>oYk7|0}JSzYTj;F{my zndy}{`W^+J#%c-97+n&f(5<-*o<~jVe0Tw2xkkZ#Vsn|BcM}>1?k7mA^by^K7WicZ z6s*O%0tE)WCNqRiON28!BZ9cH@a&TDpo9elNZYc5gIZb(Z`ahYmX@)BWEJLwkLG(9 z)}vj3zEQY5-C+TED>jSSEyQwa)?6Ae=Q|WUBtmkec~EC0!I(NFNFEVTw}Kw@axRoi z=xQWETo#uy+dizOgWCSAmI!G94{2<{b_GH75ur#Ttc~;x{*PcggzXLmJMjo{&twNO zhJJ;0M_HCyuuH+C!ci+NspuB$QScZZ7gE}vRb%vR8mwkk8D6zQRWKj~V++NS8BIo5 zf@exwCPN*D!&$v&uq~M-RYk?gU=$@%>>Exe52^z~@fwB|M6gf7EHxYsW>cxOmdR+` zeo-k-#TCR{My#+KmDSNxJjRIxk}^^X_JcWIQXqndGP)LLs%U9W)D&6nHPuhz;(=;b z8C^jZ2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$3o43;b)Oh5UtX!n#F#Dag5XGwf*P2TY$pKXk=eFBH6=%+d-aHPNb3u8Fi zRZv0`Y5C$fz6?73m2R&gXa|R{8G1G({v;n)zRoQhum<-NL=(K_^bP1_+I3OP-JI=Z zsM~1sFs*`ws*kYjFan-ja}?uMH+fx`vg@oE|EqzshecF+Q}Drxx`q0BO^mEO o;xF9_T*uEj*0L(RL-&4RTz_R;e{Edf#veHE;@ltcXR68lAL~}-5&!@I literal 0 HcmV?d00001 diff --git a/src/Teacher.java b/src/Teacher.java index 2831db5..3ad8d36 100644 --- a/src/Teacher.java +++ b/src/Teacher.java @@ -10,11 +10,13 @@ import java.nio.file.Paths; import java.nio.file.StandardOpenOption; import java.text.SimpleDateFormat; import java.util.Date; +import java.util.Random; public abstract class Teacher { - String name; - String password; - String path = null; // 教师文件夹路径 + protected String name; + protected String password; + protected String path = null; // 教师文件夹路径 + public Random random = new Random(); // 共用Random public Teacher(String name, String password, String path) { this.name = name; @@ -85,7 +87,7 @@ public abstract class Teacher { } // 生成并存储题目 - public String GenerateEX(int num) { + public String generateEX(int num) { Path filePath = Paths.get(generatePath()); for (int i = 0; i < num; i++) { String question = generateSingleQuestion(); -- 2.34.1