Java Code that executes the following: * There is a Quiz class, a question class
ID: 3753058 • Letter: J
Question
Java Code that executes the following:
* There is a Quiz class, a question class and a main class.
In a quiz system, teachers write quizzes and students then take the quizzes. The same quiz question can appear in more than one quiz. If a teacher updates a quiz question, it's important that all quizzes reflect that change. Each question should have both an identification number and data. The data should be the actual question being asked, stored as a String. When displaying a quiz, the id of the quiz should be shown, in addition to the id of each question and the text data it stores.
Explanation / Answer
Java coding:
import java.util.Scanner;
import java.util.*;
class Question
{
String question(data) ;
int question no; //declaration of question number
int identification num; //declaration of identification number
int ques data; //defining data stored
HashMap<Integer,String> options;
String exactanswer;
public static void question_no(){
System.out.println("enter a question no"); //giving a question number
int num;
Scanner number = new Scanner(System.in);
num = no.nextInt();
}
public static void set_question(){ //setting of question declaration
System.out.println("enter aquestion");
Scanner f = new Scanner(System.in);
update.change(question); //when updation of question happened
reflect.change(all quiz); //reflects changes in all the question in the quiz
String question = f.nextLine();
}
//for setting options of quiz question
public void defining_options(){
System.out.println("enter options");
int count = 1;
options = new HashMap<Integer, String>();
String question;//questions in string
Scanner str = new Scanner(System.in);
while(count<4){ //no.of options for each question
System.out.print("define option "+count); //including answer in the options
question= str.nextLine();
options.put(count,question);
count++;
}
}s
public void declare_exactanswer(){ //declaration of exact answer
System.out.println("enter exact answer");
Scanner d = new Scanner(System.in);
String answer = d.nextLine(); //the answer defines and go to the next line
}
public static void marks(){ //result declaration of marks
}
}
class Quiz
{
//teacher write quiz
first==write.quiz(teacher);//first the teacher writes the quiz
next==take.quiz(students); //then the students take the quiz
ArrayList<Question> list = new ArrayList<Question>(); //no.of.questions in the list
public ArrayList<Question> adding(Question q){ //adding of new questions
same.question(appear)>>1(quiz); //same question can appear more than quiz
update.question();//when the question got updated by the teacher
quiz.reflect(change); //change reflected in all quiz
list.add(q); //listing of added questions in the quiz
return list;
}
public void show(){
int e = list.limit(); //limits of the lists
int count =0;
while(count<e){>
list.get(count);
//displaying quiz question
display.quiz();
display.id(shown); //displaying the id of the quiz
display.idtextdata(question); //display of text in data question
display.storedata(); //displaying the stored data
//}
}
}
class Main{
public static void main(String[] args) {
System.out.println("enter 1 for adding questions");
Scanner input = new Scanner(System.in);
int e;
e= input.nextInt();
if (e == 1){ //when one is pressed
System.out.println("questions need to add"); //number of questions needed to add
int number;
Scanner b = new Scanner(System.in);
Quiz programming = new Quiz();
number = b.nextInt();
int count=0;
while(count<number){//>
Question q1 = new Question();
question1.q_no(); //number of the question
question1.set_question(); //setting question to answer
question1.set_options(); //setting options for corresponding question
question1.set_correctanswer(); //set correctanswer for result declaration
programming.adding(q1);
++count;
}
}
else if(e ==2){
Quiz programming = new Quiz();
programming.show(); //to show the quiz programming
end program();
}
}
}
Hope you understand and this helps you.All the best
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.