最终版1.0

陈映江 5 months ago committed by Gitea
parent 2e05297261
commit 7184db66e0

@ -1,9 +1,17 @@
[ {
"username" : "LXR",
"email" : "2759462569@qq.com",
"passwordHash" : "$2a$12$AiupZKqpZMXvstX6XYNGUuBDZOMdzqXy/ADaYzurUYatM293Lbxii",
"registrationDate" : [ 2025, 10, 11, 19, 40, 59, 177105400 ],
"verificationCode" : "371978",
"verified" : true,
"type" : "高中"
}, {
"username" : "小鱼",
"email" : "1280556515@qq.com",
"passwordHash" : "$2a$12$dbNwBK6NBj7mXU6YzNMAweTMhD9NOxsjPGzW2SfIM.QvGdWt7Lyvy",
"registrationDate" : [ 2025, 10, 10, 11, 7, 5, 853200500 ],
"verificationCode" : "688201",
"verified" : true,
"type" : "初中"
"type" : "中"
} ]

@ -9,10 +9,12 @@ public class MultipleChoiceGenerator {
String[] QuestionList ;
String[] AnswerList ;
String[] ChoiceList ;
String[] CorrectAnswerNo;
MultipleChoiceGenerator(int count, User nowUser){// 如此声明MultipleChoiceGenerator实例,再调用下面三个接口
public MultipleChoiceGenerator(int count, User nowUser){// 如此声明MultipleChoiceGenerator实例,再调用下面三个接口
this.QuestionList = new String[count];
this.ChoiceList = new String[count];
this.CorrectAnswerNo = new String[count];
this.QuestionList = SetQuestionList(count, nowUser);
SetChoiceList();
}
@ -29,24 +31,33 @@ public class MultipleChoiceGenerator {
return this.AnswerList;
}
public String[] GetCorrectAnswerNo(){
return this.CorrectAnswerNo;
}
private void SetChoiceList(){
for(int i = 0 ; i < this.AnswerList.length ; i++){
Random random = new Random();
String[] choiceNo = {"A","B","C","D"};
String[] choices = new String[4];
double correctChoice = Double.parseDouble(this.AnswerList[i]);
int position = random.nextInt(4);
choices[position] = String.format("%.2f", correctChoice);
choices[position] = choiceNo[position] + String.format("%.2f", correctChoice);
for(int j = 0 ; j < 4 ; j++){
if(j != position){
double choice = correctChoice;
double offset = random.nextInt(41) - 20;
choice += offset;
choices[j] = String.format("%.2f", choice);
choices[j] =choiceNo[j] +"." + String.format("%.2f", choice);
}
else{
CorrectAnswerNo[i] = choiceNo[j];
}
}
this.ChoiceList[i] = String.join("\n", choices);
this.ChoiceList[i] = String.join(" ", choices);
}
}
@ -87,4 +98,4 @@ public class MultipleChoiceGenerator {
}
}

@ -1,6 +1,7 @@
package mathlearning.ui;
import mathlearning.model.User;
import mathlearning.service.MultipleChoiceGenerator.MultipleChoiceGenerator;
import mathlearning.service.UserService;
import javax.swing.*;
@ -10,9 +11,11 @@ public class SelTestFrame extends JFrame {
private MainFrame mainFrame;
private User user;
private UserService userService;
private MultipleChoiceGenerator multipleChoiceGenerator;
private int questionNum;
private int currentQuestionDex;
private String[] answers;
private String[] myAnswers;
private JLabel titleLabel;
@ -23,6 +26,8 @@ public class SelTestFrame extends JFrame {
private JButton prevButton;
private JButton nextButton;
private JButton submitButton;
private JLabel question;
private JLabel choice;
public SelTestFrame(MainFrame mainFrame, User user, UserService userService, int num) {
this.mainFrame = mainFrame;
@ -31,6 +36,8 @@ public class SelTestFrame extends JFrame {
this.questionNum = num;
this.currentQuestionDex = 0;
this.myAnswers = new String[questionNum];
this.multipleChoiceGenerator = new MultipleChoiceGenerator(num, user);
this.answers = multipleChoiceGenerator.GetCorrectAnswerNo();
InitUI();
addWindowListener(new java.awt.event.WindowAdapter() {
@Override
@ -95,7 +102,21 @@ public class SelTestFrame extends JFrame {
}
private JPanel centerPanel() {
JPanel panel = new JPanel(new BorderLayout());
JPanel panel = new JPanel(new GridLayout(6, 1));
JLabel questionLabel = new JLabel("题目:");
questionLabel.setFont(new Font("微软雅黑", Font.PLAIN, 14));
question = new JLabel(multipleChoiceGenerator.GetQuestionList()[currentQuestionDex]);
question.setFont(new Font("微软雅黑", Font.PLAIN, 14));
panel.add(questionLabel);
panel.add(question);
JLabel choiceLabel = new JLabel("选项:");
choiceLabel.setFont(new Font("微软雅黑", Font.PLAIN, 14));
choice = new JLabel(multipleChoiceGenerator.GetChoiceList()[currentQuestionDex]);
choiceLabel.setFont(new Font("微软雅黑", Font.PLAIN, 16));
panel.add(choiceLabel);
panel.add(choice);
return panel;
}
@ -187,6 +208,7 @@ public class SelTestFrame extends JFrame {
if (currentQuestionDex > 0) {
currentQuestionDex--;
updateTitleLabel();
updateQuestion();
if (myAnswers[currentQuestionDex] == null) {
resetButtonColors();
}
@ -202,6 +224,7 @@ public class SelTestFrame extends JFrame {
if (currentQuestionDex < questionNum - 1) {
currentQuestionDex++;
updateTitleLabel();
updateQuestion();
if (myAnswers[currentQuestionDex] == null) {
resetButtonColors();
} else {
@ -216,6 +239,7 @@ public class SelTestFrame extends JFrame {
int confirm = JOptionPane.showConfirmDialog(SelTestFrame.this, "你确定要提交试卷吗?", "提示", JOptionPane.YES_NO_OPTION);
if (confirm == JOptionPane.YES_OPTION) {
int correctCount = 0;
correctCount = getScore(answers, myAnswers);
double accuracy = Math.round((double) correctCount / myAnswers.length * 10000) / 100.0;
double score = Math.round((double) correctCount * 100 / myAnswers.length * 10) / 10.0;
@ -224,7 +248,7 @@ public class SelTestFrame extends JFrame {
String[] options = {"返回主菜单", "继续做题"};
int choice = JOptionPane.showOptionDialog(
SelTestFrame.this,
"您答对了" + score + "道题,正确率为" + String.format("%.2f", accuracy) + "\n您的得分是: " + score + "分",
"您答对了" + correctCount + "道题,正确率为" + String.format("%.2f", accuracy) + "\n您的得分是: " + score + "分",
"测试结果",
JOptionPane.YES_NO_OPTION,
JOptionPane.INFORMATION_MESSAGE,
@ -237,8 +261,9 @@ public class SelTestFrame extends JFrame {
mainFrame.setVisible(true);
dispose();
} else if (choice == 1) {
mainFrame.reTryTest();
dispose();
mainFrame.setVisible(true);
mainFrame.reTryTest();
}
}
}
@ -292,7 +317,8 @@ public class SelTestFrame extends JFrame {
return score;
}
private String getQuestion(String[] questions, int dex) {
return questions[dex];
private void updateQuestion() {
question.setText(multipleChoiceGenerator.GetQuestionList()[currentQuestionDex]);
choice.setText(multipleChoiceGenerator.GetChoiceList()[currentQuestionDex]);
}
}

Loading…
Cancel
Save