I'm creating an application that has Professors create Tests. Each Test is composed of n amount of Questions that the Professor creates.
I have a Question Entity:
public class Question {
private int questionID;
private int testID;
private String question;
private String answer;
private int points;
public int getQuestionID() {
return questionID;
}
public void setQuestionID(int questionID) {
this.questionID = questionID;
}
public int getTestID() {
return testID;
}
public void setTestID(int testID) {
this.testID = testID;
}
public String getQuestion() {
return question;
}
public void setQuestion(String question) {
this.question = question;
}
public String getAnswer() {
return answer;
}
public void setAnswer(String answer) {
this.answer = answer;
}
public int getPoints() {
return points;
}
public void setPoints(int points) {
this.points = points;
}
}
And I have a Test Entity:
import Question;
public class Test {
private int testID;
private int courseID;
private String testName;
private List<Question> questions;
public int getTestID() {
return testID;
}
public void setTestID(int testID) {
this.testID = testID;
}
public int getCourseID() {
return courseID;
}
public void setCourseID(int courseID) {
this.courseID = courseID;
}
public String getTestName() {
return testName;
}
public void setTestName(String testName) {
this.testName = testName;
}
public List<Question> getQuestions() {
return questions;
}
public void setQuestions(List<String> questions) {
this.questions = questions;
}
}
The Test Entity has the list of Questions, and I'm not sure how to make that into a table. I would prefer to avoid a multi-value field in the table for a Test.
One idea that may be a possible solution is to create a table in the database that would help map the questions. I could just call it TestQuestion and it would have TestID(int):QuestionID(int) as its columns. The Test table would have columns (testID, courseID, testName). Then when I do the querying for a Test, I also query the TestQuestion Table for the list of questions and put those in the list in the Test Entity.
I would like to do this all with good practice.
TestandQuestionlooks fine to me, assuming that these two entities have a many-to-many relationship which seems to be the case here.