问答游戏 - 为管理员创建问题、答案和历史记录 [英] Quiz game - Create questions, answers and historical for admins

查看:25
本文介绍了问答游戏 - 为管理员创建问题、答案和历史记录的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在开发一款有两种类型用户的游戏;admin 和 user,因此 admin 可以生成任意数量的问题,因此这些问题可以是 NORMAL、MULTICHOICE、BINARI、SMALL_DESCRIPTION,因此每次 admin 想要创建一个时,他都必须决定哪种类型回答想要这个问题,也是这个问题的主题(它可以是一个子主题).

I'm working on a game which has two types of user; admin and user, so admin can generate as many questions as he wants, so those questions can be NORMAL, MULTICHOICE, BINARI, SMALL_DESCRIPTION, so every time admin wants to create one he has to decide which type of answer wants to this question, also the topic of this Question ( it can be a subtopic ).

他可以生成一个测验,生成测验的方式是他必须选择他之前创建的问题.

He can generate a Quiz, the way to generate a Quiz is that he has to select questions that he created before.

他还可以检查用户的历史记录,这意味着通过调用端点,他应该能够检查该用户所做的问题(包括分数、哪个问题失败了、他回答了什么).

Also he can check the historical of the user, means that with a call to an endpoint he should be able to check the questions that that user did (with the score, which question has failed, what he answered).

从现在开始,我有 QuestionAnswer 类,但我有点坚持使用分配给主题的答案生成问题,然后创建测验,因为我两个部分也都缺少用户,以了解哪个用户创建了问题/测验以及哪个用户回答了问题/测验并存储了一些数据以进行历史记录.

I have from now the classes Question and Answer but I'm kinda stuck with the Question generate with Answer assigned to a topic and then creating a Quiz, because I missing also User in both parts, to know which user has created the question / quiz and which user has answered the question / quiz and store some data to do the historical.

我的问题类有:

@Entity(name="question")
public class Question extends DateAudit {
@Id
@Column(name = "question_id")
@GeneratedValue(strategy = GenerationType.SEQUENCE, generator = "question_seq")
@SequenceGenerator(name = "question_seq", allocationSize = 1)
private Long id;

@Column(name = "text_question")
private String textQuestion; //The question itself "What's the name of ..."

@Column(name = "answerDescription")
@NotBlank(message = "Answer description")
private String answerDescription; //The answer to the question as an explanation

@Column(name = "isExamQuestion", nullable = false) 
private Boolean isExamQuestion; //A flag for the user to filter when he wants to do a question he only will see those that are not isExamQuestion, isExamQuestion are the questions that are going to appear when he wants to create a Quiz

@OneToMany(fetch = FetchType.EAGER, cascade = { CascadeType.PERSIST, CascadeType.MERGE })
private Set<Answer> answers; //List of answers...

@Column(name = "answer_type", nullable = false) 
private String answerType; //I don't know if it goes here, but the answerType mentioned before NORMAL,MULTICHOICE,.... is to render on the user app

答案

@Entity(name = "answer")
public class Answer extends DateAudit {

    @Id
    @Column(name = "answer_id")
    @GeneratedValue(strategy = GenerationType.SEQUENCE, generator = "answer_seq")
    @SequenceGenerator(name = "answer_seq", allocationSize = 1)
    private Long id;

    @Column(name = "answerToQuestion") 
    @NotBlank(message = "Answer to question name can not be blank") 
    private String answerToQuestion; //If the questions is what's 2*2 this could be 3

    @ManyToOne 
    private Question question; //In what question appear that answer

    //Here I'm wondering if I have to add a flag saying isCorrect to detect if it's the correct answer or not

如您所见,我遗漏了主题内容、历史和测验,而且我没有提及哪个用户提出了问题、测验或解决了测验/问题,请指导我如何做这个?

As you can see I'm missing the Topic stuff, the historical, and the quiz, and i'm not referencing which user did the question, or quiz, or solved the quiz / question would you please guide me how to do this?

我收到的问题:

问题是只针对一个用户还是一组用户?

is the question only targeted to one user or a group of user ?

可以为不同的用户回答相同的问题或测验,这意味着 Q1 可以由 40 个用户完成.

The same question or quiz can be answered for difference users, meaning, that Q1 can be done by 40 users.

测验与主题有关吗?

创建测验时,您可以选择一个主题来选择具有该主题的问题.示例:创建学习总结测验 我必须按主题过滤:数学,然后是子主题总和,以便我可以选择要放入测验中的问题.

When you create a quiz you select a topic to select the questions that has that topic. Example : Creating a Quiz of Learn to Sum I'll have to filter out by topic : Math and then a SubTopic Sum so I'll can choose the questions to put inside the Quiz.

您打算如何创建主题或副主题?

how do you plan to create a topic or subtopic ?

管理员应该有一个端点来创建主题或副主题,从现在开始只有一个副主题,没有副主题的副主题,从现在开始是主题:数学副主题:平方根.因此,在创建问题或测验之前,管理员应该首先创建一个主题,如果他想添加一个副主题,则创建一个,这样当他尝试创建一个问题时,他可以说该问题来自 X 主题/副主题这个问题可以分配给那个.

Admin should have an endpoint to create topic or subtopic, from now there's only a Subtopic, there's not Subtopic of a subtopic, from now is Topic : Math Subtopic : Square root. So, before creating a question, or a quiz, admin should first create a Topic and if he wants to add a subtopic then create one, so then when he tries to create a Question he can say that that question is from X topic / subtopic and that question can be assigned to that.

历史"是什么意思?

嗯,这是管理员方面的事情,管理员应该有一个端点,该端点带有用户的 ID 或名称,返回用户完成的所有测验(第一个端点)或所有问题(第二个端点),并带有分数,失败次数/正确次数,但我想知道这应该是前端进行计算,我的意思是,端点返回所有这些信息,问题总数/测验已经完成,分数,有什么问题失败,等等.然后在前端做更多的计算.

Well, that's something for Admin side, Admin should have an endpoint that with an Id or name of the user returns all of the Quiz (first endpoint) or all of the Questions(second endpoint) that user has done, with the score, number of fails / number of correct ones, but I'm wondering that this should be front end side do the calculation, I mean, endpoint returns all of this info, Total of Questions/Quiz has done, Score, what question has failed, etc.. and then in frontend do more calculations.

推荐答案

抱歉,我没有为我的答案添加注释.你把它们弄清楚.都是实体.不需要答案实体,或者它取决于您的问题类型.让他们拥有自己的类,并使用用户表单来填充它们.有多项选择的例子.

Sorry I do not put annotations for my answer. You figure them out. All are Entities. There is no need for Answer entity, or it depens about your question type. Do them own classes, and user forms to fill them. There is example for multichoice.

您可以管理谁可以从控制器创建测验.您可以将测验添加到您的用户实体:ListmyQuizesAsAdmin;<代码>列表<测验>myQuizesAsAnswerer;

You can manage who can create Quiz from Controller. You can add Quiz to your User entity: List<Quiz> myQuizesAsAdmin; List<Quiz> myQuizesAsAnswerer;

您可以从用户实体查询中查看历史记录;使用 List 过滤和排序它们myQuizesAsAnswerer; 您还可以像学校课程一样添加课程,并添加他们必须做的测验.

You can see history from User entity Query; filter and sort them using List<Quiz> myQuizesAsAnswerer; You can also add Classes for like a school class and add Quizes what they have to do.

如何编码:管理员创建一个Quiz myQuiz = new Quiz(name, QuizId, Questions, StartDate, EndDate, etc...)

How to code: Admin create a Quiz myQuiz = new Quiz(name, QuizId, Questions, StartDate, EndDate, etc...)

现在您有了一个原始测验,因此您可以复制或克隆它并带有唯一 ID.我向 Quiz.class 添加了一个构造函数来完成它.Quiz iDoThisQuiz = new Quiz (this.QuizRepository.findByQuizIdAndByOriginal(thisQuisId, true)); 现在回答者可以进行测验和回答问题了.填写后保存到数据库中.现在,在您的数据库中,您有一个原始测验"和已回答测验内容的副本.

Now you have an original Quiz, so you have do a copy or clone of it whit unique id. I added a constructor to Quiz.class to do it. Quiz iDoThisQuiz = new Quiz (this.QuizRepository.findByQuizIdAndByOriginal(thisQuisId, true)); Now answerer can do the quiz and answer questions. Save it to database after filling. Now in your database you have an "original quiz" and copies of it what are answered quizes.

    public class Quiz {
               private String name;
               private boolean original;
               private long id; // This is unique for every entity
               private String quizId; // this is for this quiz general id. Like a name. Unique for this quiz.
               private List<Question> questions;
               private User answerer;
               private User admin;
               private Date endDateToDoDate; // and another dates like when it has been done.
               private double totalPoints; // If you want to on

        }
public Quiz(Quiz originalQuiz) {
     this.id= this has to be unique, autogenerated or what you use to generate ids. 
     this.quizId = originalQuiz.quizId;
     this.name = originalQuiz.name;
     this.question = new Question(originalQuiz.question);
     this.original = false;
     ... 

--

@Entity(name = "question")
public class Question extends DateAudit {
    @Id
    @Column(name = "question_id")
    @GeneratedValue(strategy = GenerationType.SEQUENCE, generator = "question_seq")
    @SequenceGenerator(name = "question_seq", allocationSize = 1)
    private Long id;
    private boolean isAnswered;

    /* TOPIC AND SUBTOPIC, create class Topic. */
    private Topic topic;
    private Topic subtopic; //Or you have a subtopic in Topic class

    @Column(name = "text_question")
    private String textQuestion; // The question itself "What's the name of ..."

    /* question types. All have to have their own class. When admin create quetion he will add one question type --  setMultiChoice()
     * Another ones are NULL so when you create answer form it selects that what is not NULL */
    private MultiChoise multiChoise;
    private NormalQuestion normalQuestion;
    /* etc question types */

    @Column(name = "answerDescription")
    @NotBlank(message = "Answer description")
    private String answerDescription; // The answer to the question as an explanation

    @Column(name = "isExamQuestion", nullable = false)
    private Boolean isExamQuestion; // A flag for the user to filter when he wants to do a question he only will see
                                    // those that are not isExamQuestion, isExamQuestion are the questions that are
                                    // going to appear when he wants to create a Quiz


}



@Entity
public class MultiChoice extends Points{
    private List<TextAndBoolean> choices;
    private boolean answered;

}



 public class Points {
    private double points;

}


public class TextAndBoolean {
    private String text;
    private boolean selected;

}

这篇关于问答游戏 - 为管理员创建问题、答案和历史记录的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆