@ -0,0 +1,22 @@
|
|||||||
|
package Base;
|
||||||
|
|
||||||
|
public class Question {
|
||||||
|
private int number;
|
||||||
|
private String content;
|
||||||
|
private String type;
|
||||||
|
|
||||||
|
public Question(int number, String content, String type) {
|
||||||
|
this.number = number;
|
||||||
|
this.content = content;
|
||||||
|
this.type = type;
|
||||||
|
}
|
||||||
|
|
||||||
|
public int getNumber() { return number; }
|
||||||
|
public String getContent() { return content; }
|
||||||
|
public String getType() { return type; }
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String toString(){
|
||||||
|
return this.number+". "+this.content+" = ?";
|
||||||
|
}
|
||||||
|
}
|
||||||
@ -0,0 +1,21 @@
|
|||||||
|
package Base;
|
||||||
|
|
||||||
|
public class User {
|
||||||
|
private String id;
|
||||||
|
private String password;
|
||||||
|
private String type;
|
||||||
|
|
||||||
|
public User(String id, String ps, String type) {
|
||||||
|
this.id = id;
|
||||||
|
this.password = ps;
|
||||||
|
this.type = type;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getUsername() { return id; }
|
||||||
|
public String getPassword() { return password; }
|
||||||
|
public String getUserType() { return type; }
|
||||||
|
|
||||||
|
public void change_type(String new_type){
|
||||||
|
this.type=new_type;
|
||||||
|
}
|
||||||
|
}
|
||||||
@ -0,0 +1,75 @@
|
|||||||
|
package Deal;
|
||||||
|
|
||||||
|
import Base.Question;
|
||||||
|
|
||||||
|
import java.io.*;
|
||||||
|
import java.text.SimpleDateFormat;
|
||||||
|
import java.util.*;
|
||||||
|
|
||||||
|
public class Deal_file {
|
||||||
|
private static final String BASE_DIR="试卷/";
|
||||||
|
|
||||||
|
public Deal_file() {
|
||||||
|
File baseDir = new File(BASE_DIR);
|
||||||
|
if (!baseDir.exists()) {
|
||||||
|
if (!baseDir.mkdirs())
|
||||||
|
System.out.println("目录创建失败!");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public void savePaper(ArrayList<Question> paper, String username) {
|
||||||
|
String userDirPath = BASE_DIR + username + "/";
|
||||||
|
File userDir = new File(userDirPath);
|
||||||
|
if (!userDir.exists()) {
|
||||||
|
if (!userDir.mkdirs()) {
|
||||||
|
System.out.println("目录创建失败!");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
String timestamp = new SimpleDateFormat("yyyy-MM-dd-HH-mm-ss").format(new Date());
|
||||||
|
String filePath = userDirPath + timestamp + ".txt";
|
||||||
|
|
||||||
|
try (PrintWriter writer = new PrintWriter(new FileWriter(filePath))) {
|
||||||
|
for (int i = 0; i < paper.size(); i++) {
|
||||||
|
writer.println(paper.get(i).toString());
|
||||||
|
if (i < paper.size() - 1) {
|
||||||
|
writer.println();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
System.out.println("试卷已保存至: " + new File(filePath).getAbsolutePath());
|
||||||
|
} catch (IOException e) {
|
||||||
|
System.out.println("保存文件出错: " + e.getMessage());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public Set<String> Check_Existing(String username) {
|
||||||
|
Set<String> questions = new HashSet<>();
|
||||||
|
String userDirPath = BASE_DIR + username + "/";
|
||||||
|
File userDir = new File(userDirPath);
|
||||||
|
|
||||||
|
if (!userDir.exists() || !userDir.isDirectory()) {
|
||||||
|
return questions;
|
||||||
|
}
|
||||||
|
|
||||||
|
File[] files = userDir.listFiles();
|
||||||
|
if (files == null) {
|
||||||
|
return questions;
|
||||||
|
}
|
||||||
|
|
||||||
|
for (File file : files) {
|
||||||
|
if (file.isFile() && file.getName().endsWith(".txt")) {
|
||||||
|
try (BufferedReader reader = new BufferedReader(new FileReader(file))) {
|
||||||
|
String line;
|
||||||
|
while ((line = reader.readLine()) != null) {
|
||||||
|
if (!line.trim().isEmpty()) {
|
||||||
|
questions.add(line.trim());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} catch (IOException e) {
|
||||||
|
return questions;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return questions;
|
||||||
|
}
|
||||||
|
}
|
||||||
@ -0,0 +1,56 @@
|
|||||||
|
package Deal;
|
||||||
|
|
||||||
|
import Base.Question;
|
||||||
|
import Base.User;
|
||||||
|
import Generator.G_ques;
|
||||||
|
import Generator.Jun_g_ques;
|
||||||
|
import Generator.Pri_g_ques;
|
||||||
|
import Generator.Sen_g_ques;
|
||||||
|
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.Set;
|
||||||
|
|
||||||
|
public class Deal_paper {
|
||||||
|
private G_ques g_ques;
|
||||||
|
private Deal_file write_file;
|
||||||
|
public Deal_paper(User user){
|
||||||
|
write_file=new Deal_file();
|
||||||
|
switch (user.getUserType()){
|
||||||
|
case "小学":{
|
||||||
|
g_ques=new Pri_g_ques();
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
case "初中":{
|
||||||
|
g_ques=new Jun_g_ques();
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
case "高中":{
|
||||||
|
g_ques=new Sen_g_ques();
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
default:{
|
||||||
|
g_ques=new Pri_g_ques();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public void g_paper(int count,String username){
|
||||||
|
ArrayList<Question> result=new ArrayList<>();
|
||||||
|
Set<String> existing_ques=write_file.Check_Existing(username);
|
||||||
|
for (int i=0;i<count;i++) {
|
||||||
|
String temp;
|
||||||
|
int try_times = 0;
|
||||||
|
do {
|
||||||
|
temp = g_ques.g_question();
|
||||||
|
try_times++;
|
||||||
|
} while (existing_ques.contains(temp) && try_times <= 50);
|
||||||
|
result.add(new Question(i+1, temp, g_ques.g_type()));
|
||||||
|
existing_ques.add(temp);
|
||||||
|
}
|
||||||
|
write_file.savePaper(result,username);
|
||||||
|
}
|
||||||
|
|
||||||
|
public String get_type(){
|
||||||
|
return g_ques.g_type();
|
||||||
|
}
|
||||||
|
}
|
||||||
@ -0,0 +1,35 @@
|
|||||||
|
package Deal;
|
||||||
|
|
||||||
|
import Base.User;
|
||||||
|
import java.util.HashMap;
|
||||||
|
import java.util.Map;
|
||||||
|
|
||||||
|
public class Deal_user {
|
||||||
|
private Map<String,User> all_user;
|
||||||
|
public Deal_user(){
|
||||||
|
load_user();
|
||||||
|
}
|
||||||
|
|
||||||
|
public void load_user(){
|
||||||
|
all_user=new HashMap<>();
|
||||||
|
|
||||||
|
all_user.put("张三1", new User("张三1", "123", "小学"));
|
||||||
|
all_user.put("张三2", new User("张三2", "123", "小学"));
|
||||||
|
all_user.put("张三3", new User("张三3", "123", "小学"));
|
||||||
|
|
||||||
|
// 初中老师
|
||||||
|
all_user.put("李四1", new User("李四1", "123", "初中"));
|
||||||
|
all_user.put("李四2", new User("李四2", "123", "初中"));
|
||||||
|
all_user.put("李四3", new User("李四3", "123", "初中"));
|
||||||
|
|
||||||
|
// 高中老师
|
||||||
|
all_user.put("王五1", new User("王五1", "123", "高中"));
|
||||||
|
all_user.put("王五2", new User("王五2", "123", "高中"));
|
||||||
|
all_user.put("王五3", new User("王五3", "123", "高中"));
|
||||||
|
}
|
||||||
|
|
||||||
|
public User login(String id,String psw){
|
||||||
|
User temp=all_user.get(id);
|
||||||
|
return (temp!=null&&temp.getPassword().equals(psw))?temp:null;
|
||||||
|
}
|
||||||
|
}
|
||||||
@ -0,0 +1,7 @@
|
|||||||
|
package Generator;
|
||||||
|
|
||||||
|
public interface G_ques {
|
||||||
|
String g_question();
|
||||||
|
String g_type();
|
||||||
|
char g_operator();
|
||||||
|
}
|
||||||
@ -0,0 +1,63 @@
|
|||||||
|
package Generator;
|
||||||
|
|
||||||
|
import java.util.Random;
|
||||||
|
|
||||||
|
public class Jun_g_ques implements G_ques{
|
||||||
|
private Random ra= new Random();
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String g_question() {
|
||||||
|
int count=ra.nextInt(5)+1;
|
||||||
|
StringBuilder question = new StringBuilder();
|
||||||
|
boolean flag=false;
|
||||||
|
for (int i=0;i<count;i++){
|
||||||
|
if (i>0){
|
||||||
|
question.append(" ").append(g_operator()).append(" ");
|
||||||
|
}
|
||||||
|
if (ra.nextDouble()<0.25) {
|
||||||
|
if (ra.nextBoolean()) {
|
||||||
|
question.append(ra.nextInt(30) + 1).append("²");
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
question.append("√").append(ra.nextInt(100) + 1);
|
||||||
|
}
|
||||||
|
flag=true;
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
question.append(ra.nextInt(100) + 1);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (!flag){
|
||||||
|
if(count==1){
|
||||||
|
if (ra.nextBoolean()){
|
||||||
|
question.append("²");
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
question.insert(0,"√");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
String[] parts = question.toString().split(" ");
|
||||||
|
int pos = ra.nextInt(count);
|
||||||
|
if (ra.nextBoolean()) {
|
||||||
|
parts[pos * 2] = parts[pos * 2] + "²";
|
||||||
|
} else {
|
||||||
|
parts[pos * 2] = "√" + parts[pos * 2];
|
||||||
|
}
|
||||||
|
question = new StringBuilder(String.join(" ", parts));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return question.toString();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String g_type(){
|
||||||
|
return "初中";
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public char g_operator(){
|
||||||
|
char[] op={'+','-','*','/'};
|
||||||
|
return op[ra.nextInt(op.length)];
|
||||||
|
}
|
||||||
|
}
|
||||||
@ -0,0 +1,39 @@
|
|||||||
|
package Generator;
|
||||||
|
|
||||||
|
import java.util.Random;
|
||||||
|
|
||||||
|
public class Pri_g_ques implements G_ques{
|
||||||
|
private Random ra= new Random();
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String g_question() {
|
||||||
|
int count=ra.nextInt(4)+2;
|
||||||
|
StringBuilder question = new StringBuilder();
|
||||||
|
int count_bracket=0;
|
||||||
|
for (int i=0;i<count;i++) {
|
||||||
|
if (i > 0) {
|
||||||
|
question.append(" ").append(g_operator()).append(" ");
|
||||||
|
}
|
||||||
|
if (i!=count-1&&ra.nextDouble()<0.4){
|
||||||
|
question.append("(");
|
||||||
|
count_bracket++;
|
||||||
|
}
|
||||||
|
question.append(ra.nextInt(100) + 1);
|
||||||
|
}
|
||||||
|
if (count_bracket!=0){
|
||||||
|
question.append(")".repeat(Math.max(0, count_bracket)));
|
||||||
|
}
|
||||||
|
return question.toString();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String g_type(){
|
||||||
|
return "小学";
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public char g_operator(){
|
||||||
|
char[] op={'+','-','*','/'};
|
||||||
|
return op[ra.nextInt(op.length)];
|
||||||
|
}
|
||||||
|
}
|
||||||
@ -0,0 +1,47 @@
|
|||||||
|
package Generator;
|
||||||
|
|
||||||
|
import java.util.Random;
|
||||||
|
|
||||||
|
public class Sen_g_ques implements G_ques{
|
||||||
|
private Random ra= new Random();
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String g_question() {
|
||||||
|
int count=ra.nextInt(5)+1;
|
||||||
|
StringBuilder question = new StringBuilder();
|
||||||
|
boolean flag=false;
|
||||||
|
for (int i=0;i<count;i++) {
|
||||||
|
if (i > 0) {
|
||||||
|
question.append(" ").append(g_operator()).append(" ");
|
||||||
|
}
|
||||||
|
if (ra.nextDouble()<0.3){
|
||||||
|
question.append(g_trig()).append("²").append("(").append(g_angle()).append("°)");
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
question.append(g_trig()).append("(").append(g_angle()).append("°)");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return question.toString();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String g_type(){
|
||||||
|
return "高中";
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public char g_operator(){
|
||||||
|
char[] op={'+','-','*','/'};
|
||||||
|
return op[ra.nextInt(op.length)];
|
||||||
|
}
|
||||||
|
|
||||||
|
public String g_trig(){
|
||||||
|
String[] trig={"sin","cos","tan"};
|
||||||
|
return trig[ra.nextInt(trig.length)];
|
||||||
|
}
|
||||||
|
|
||||||
|
public String g_angle(){
|
||||||
|
String[] angle={"15","22.5","75","105","120","135","150","210","300"};
|
||||||
|
return angle[ra.nextInt(angle.length)];
|
||||||
|
}
|
||||||
|
}
|
||||||
@ -0,0 +1,6 @@
|
|||||||
|
public class Main {
|
||||||
|
public static void main(String[] args){
|
||||||
|
Math_System m_system=new Math_System();
|
||||||
|
m_system.main_menu();
|
||||||
|
}
|
||||||
|
}
|
||||||
Loading…
Reference in new issue