parent
6f60465022
commit
0bfeaea308
@ -0,0 +1,42 @@
|
||||
package Base;
|
||||
|
||||
import java.util.Date;
|
||||
import java.util.List;
|
||||
|
||||
public class Exam_result {
|
||||
private String exam_type;
|
||||
private int total_questions;
|
||||
private int correct_answers;
|
||||
private double score;
|
||||
private long duration; // 考试时长(秒)
|
||||
private List<Integer> wrong_questions; // 错题索引
|
||||
|
||||
public Exam_result( String examType, int total,
|
||||
int correct, double score, long duration,
|
||||
List<Integer> wrong) {
|
||||
this.exam_type = examType;
|
||||
this.total_questions = total;
|
||||
this.correct_answers = correct;
|
||||
this.score = Math.round(score * 100.0) / 100.0;
|
||||
this.duration = duration;
|
||||
this.wrong_questions = wrong;
|
||||
}
|
||||
|
||||
public String getExamType() { return exam_type; }
|
||||
public int getTotalQuestions() { return total_questions; }
|
||||
public int getCorrectAnswers() { return correct_answers; }
|
||||
public double getScore() { return score; }
|
||||
public long getDuration() { return duration; }
|
||||
public List<Integer> getWrongQuestions() { return wrong_questions; }
|
||||
|
||||
public String get_time() {
|
||||
long minutes = duration / 60;
|
||||
long seconds = duration % 60;
|
||||
return String.format("%d分%d秒", minutes, seconds);
|
||||
}
|
||||
|
||||
public String getCorrectRate() {
|
||||
return String.format("%.1f%%", (double) correct_answers / total_questions * 100);
|
||||
}
|
||||
|
||||
}
|
||||
@ -0,0 +1,25 @@
|
||||
import Base.Question;
|
||||
import Send_Email.Deal_i_code;
|
||||
import Send_Email.Send_email;
|
||||
import Service.Generate_paper;
|
||||
|
||||
import java.util.ArrayList;
|
||||
|
||||
public class Main {
|
||||
public static void main(String[] args){
|
||||
ArrayList<Question> q= Generate_paper.g_paper(12,"小学");
|
||||
for (int i=0;i<12;i++) {
|
||||
System.out.println(q.get(i));
|
||||
for (int j = 0; j < 4; j++) {
|
||||
System.out.print(q.get(i).getOptions(j) + " ");
|
||||
}
|
||||
System.out.println();
|
||||
System.out.println();
|
||||
}
|
||||
/*String email="835981889@qq.com";
|
||||
String code= Deal_i_code.generate_code(email);
|
||||
if (Send_email.judge_email_address(email).equals("邮箱格式正确")){
|
||||
Send_email.send_email(email,code);
|
||||
}*/
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,90 @@
|
||||
package Service;
|
||||
|
||||
import Base.Exam_result;
|
||||
import Base.Question;
|
||||
|
||||
import java.util.*;
|
||||
|
||||
public class Exam_service {
|
||||
private String type;
|
||||
private ArrayList<Question> paper;
|
||||
private int now_index;
|
||||
private Date start_time;
|
||||
private Date end_time;
|
||||
private Map<Integer, Integer> user_answers;
|
||||
|
||||
Exam_service(int num,String type){
|
||||
this.type=type;
|
||||
paper=Generate_paper.g_paper(num,type);
|
||||
now_index=0;
|
||||
this.start_time = new Date();
|
||||
this.user_answers = new HashMap<>();
|
||||
}
|
||||
|
||||
public ArrayList<Question> get_paper() { return paper; }
|
||||
public int get_now_index() { return now_index; }
|
||||
public Date get_start_time() { return start_time; }
|
||||
public Date get_end_time() { return end_time; }
|
||||
|
||||
public Question get_now_question() {
|
||||
if (now_index < paper.size()) {
|
||||
return paper.get(now_index);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public boolean next_one(int answer_index) {
|
||||
if (now_index < paper.size()) {
|
||||
user_answers.put(now_index, answer_index);
|
||||
|
||||
if (now_index < paper.size() - 1) {
|
||||
now_index++;
|
||||
return true;
|
||||
} else {
|
||||
end_time = new Date();
|
||||
return false;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
public boolean pre_one() {
|
||||
if (now_index > 0) {
|
||||
now_index--;
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
public boolean change_answer(int index,int choice){
|
||||
if (user_answers.containsKey(index)){
|
||||
user_answers.put(index,choice);
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
public Integer get_user_answer(int question_index) {
|
||||
return user_answers.get(question_index);
|
||||
}
|
||||
|
||||
public Exam_result calculate_result(){
|
||||
int correct = 0;
|
||||
List<Integer> wrong = new ArrayList<>();
|
||||
|
||||
for (int i = 0; i < paper.size(); i++) {
|
||||
Integer userAnswer = user_answers.get(i);
|
||||
if (userAnswer != null && paper.get(i).getOptions(userAnswer).equals(paper.get(i).getAnswer())) {
|
||||
correct++;
|
||||
} else {
|
||||
wrong.add(i);
|
||||
}
|
||||
}
|
||||
|
||||
double score = (double) correct / paper.size() * 100;
|
||||
long duration = (end_time.getTime() - start_time.getTime()) / 1000; // 秒
|
||||
|
||||
return new Exam_result(type, paper.size(), correct,
|
||||
score, duration, wrong);
|
||||
}
|
||||
}
|
||||
Loading…
Reference in new issue