Written a class for organizing a question, answers in it are presented as a list. It does not go out to enter a list of answers in list
.
An example of a question:
How many programmers are needed to spin the light bulb?
- one
- not one. This is a hardware problem, programmers do not decide
- a lot
Right answer: 2
How to create a list of answers and add specific answers to it?
question q1 = new question ("How many programmers need to be tightened by a light bulb?",
/ * list ad * /, 3);
Class code:
Public Class Question
{
String QuestionText; // question
List & lt; String & GT; answers; // List of answers
INT CORRECTANSWERNUMBER; // Number of the correct answer
Public Question (String QuestionText, List & LT; String & GT; answers, Int Correctanswernumber)
{
this.questionText = QuestionText;
this.answers = answers;
this.correctanswernumber = Correctanswernumber;
}
}
Answer 1, Authority 100%
Creating List
and adding items to it:
list & lt; string & gt; Questionanswers = New List & LT; String & GT; () {"One", "None", "Many"};
Alternative variant via .add ()
:
list & lt; string & gt; Questionanswers = New List & lt; String & GT; ();
Questionanswers.add ("One");
Questionanswers.add ("None");
Questionanswers.add ("Many");
Transmission Questionanswers
in Designer Question
:
question q1 = new question ("How many programmers need to be tightened by a light bulb?",
Questionanswers, 3);
Answer 2
Public Class Question
{
// Identifier question
Public int ID {Get; set;}
// Text Question
Public String QuestionText {Get; set;}
// Hesh Right Answer
Public String Questionanswer {Get; Set;}
}
Public Class Answer.
{
// Answer ID
Public int ID {Get; set;}
// Text Answer
Public String AnswerText {Get; set;}
}
// Questory answers
Public Questionanswers.
{
Public int ID {Get; set;}
Public int QuestionID {Get; set;}
Public int Answerid {get; set;}
}
List & LT; Answer & GT; Listofanswer = New List & LT; Answer & GT;
{
New Answer {Answertext = "1"},
New Answer {Answertext = "2"},
New Answer {AnswerText = "Niode"}
}
I imagine something like this: in the Question Table (Question), questions and hashies of answers are stored on them, in the answer table (Answer) Possible answer options, questionanswers are necessary in order to bring the possible answers options (as on the exam In the traffic police: the answers are similar in a little exception). We form a list of questions for it. We get possible options for answers (correct and two any other) all this sort (answers, questions) Show the user.