parent
7dc53d7ed9
commit
f107e7bd4e
@ -0,0 +1,24 @@
|
||||
public enum DifficultyLevel {
|
||||
PRIMARY("小学"),
|
||||
JUNIOR("初中"),
|
||||
SENIOR("高中");
|
||||
|
||||
private String chineseName;
|
||||
|
||||
DifficultyLevel(String chineseName) {
|
||||
this.chineseName = chineseName;
|
||||
}
|
||||
|
||||
public String getChineseName() {
|
||||
return chineseName;
|
||||
}
|
||||
|
||||
public static DifficultyLevel fromChineseName(String name) {
|
||||
for (DifficultyLevel level : values()) {
|
||||
if (level.chineseName.equals(name)) {
|
||||
return level;
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,23 @@
|
||||
import java.io.*;
|
||||
import java.text.SimpleDateFormat;
|
||||
import java.util.Date;
|
||||
|
||||
public class FileManager {
|
||||
public void savePaper(String username, DifficultyLevel level, QuestionPaper paper) {
|
||||
String folderPath = "papers/" + username + "/";
|
||||
File folder = new File(folderPath);
|
||||
if (!folder.exists()) {
|
||||
folder.mkdirs();
|
||||
}
|
||||
|
||||
String timestamp = new SimpleDateFormat("yyyy-MM-dd-HH-mm-ss").format(new Date());
|
||||
String filePath = folderPath + timestamp + ".txt";
|
||||
|
||||
try (PrintWriter writer = new PrintWriter(new FileWriter(filePath))) {
|
||||
writer.write(paper.getFormattedPaper());
|
||||
System.out.println("试卷已保存至: " + filePath);
|
||||
} catch (IOException e) {
|
||||
System.out.println("保存文件时出错: " + e.getMessage());
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,22 @@
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
public class QuestionPaper {
|
||||
private List<String> questions = new ArrayList<>();
|
||||
|
||||
public void addQuestion(String question) {
|
||||
questions.add(question);
|
||||
}
|
||||
|
||||
public List<String> getQuestions() {
|
||||
return questions;
|
||||
}
|
||||
|
||||
public String getFormattedPaper() {
|
||||
StringBuilder paper = new StringBuilder();
|
||||
for (int i = 0; i < questions.size(); i++) {
|
||||
paper.append(i + 1).append(". ").append(questions.get(i)).append("\n\n");
|
||||
}
|
||||
return paper.toString();
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,20 @@
|
||||
public class User {
|
||||
private String username;
|
||||
private String password;
|
||||
private DifficultyLevel level;
|
||||
|
||||
public User(String username, String password, DifficultyLevel level) {
|
||||
this.username = username;
|
||||
this.password = password;
|
||||
this.level = level;
|
||||
}
|
||||
|
||||
public String getUsername() { return username; }
|
||||
public String getPassword() { return password; }
|
||||
public DifficultyLevel getLevel() { return level; }
|
||||
public void setLevel(DifficultyLevel level) { this.level = level; }
|
||||
|
||||
public boolean authenticate(String inputUsername, String inputPassword) {
|
||||
return this.username.equals(inputUsername) && this.password.equals(inputPassword);
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,11 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<module type="JAVA_MODULE" version="4">
|
||||
<component name="NewModuleRootManager" inherit-compiler-output="true">
|
||||
<exclude-output />
|
||||
<content url="file://$MODULE_DIR$">
|
||||
<sourceFolder url="file://$MODULE_DIR$" isTestSource="false" />
|
||||
</content>
|
||||
<orderEntry type="inheritedJdk" />
|
||||
<orderEntry type="sourceFolder" forTests="false" />
|
||||
</component>
|
||||
</module>
|
||||
Binary file not shown.
Loading…
Reference in new issue