Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

JAVA PROGRAM 1. Create a Question class. A Question object: . contains the text

ID: 3765072 • Letter: J

Question

JAVA PROGRAM

1. Create a Question class. A Question object: . contains the text of a simple question (that would require a simple 1 or 2 word answer) . contains the text representing the correct answer to the question. . knows whether or not it has been answered . contains the last answer it was given. knows whether or not the last answer given was correct or incorrect. Answers are to be judged as case insensitive, 2. Create a class called Quiz, that will represent a quiz. A Quiz object will contain a list of Question objects. You must use an ArrayList to represent this list: ArrayList questions ArrayList(); = new The quiz object will contain appropriate data and appropriate methods to: add the specified question to the quiz (this will simply add it to the ArrayList . containing the list of questions): public void add (Question question) We create a quiz by repeatedly adding questions to it, using this method. . return the number of questions in the quiz, so far. . returns the ith question in the quiz (starting at 0). Return null if i is invalid . return the number of questions answered so far. . return the number of questions correctly answered so far.

Explanation / Answer

Class Question

{

String q; // to represent question

String c; // to represent correct answers

Boolean ans; // to store whether answered or not

String last; // store last answer

Boolean check; // to store whether entered answer correct or not

}

Class Quiz

{

Question temp= question();

ArrayList <Question> questions = new ArrayList<question>();

Int I,nq,nc;

Public void add(Question question)

{

questions.add(question);

i++;

}

int noofquestions()

{

return i-1;

}

Int displayquestion(int n)

{

If (n>i)

return null;

else

{

Temp=questions.get(n);

System.out.println(“Enter Question”);

System.out.println(temp.q)

System.out.println(“Enter Correct answer”);

temp.last=br.readLine();

If temp.last!=null

Nq++;

If(temp.last.equalsIgnoreCase(temp.c))

Temp.check=true;

Else

temp].check=false

If(temp.check==true)

nc++;

}

Int noofquestions()

{

return nq;

}

Int nofcorrectanswers()

{

return nc;

}

}

Class quiz

{

Public static void main(String args[]) throws IOException

{

BufferedReader nr=new BufferedReader(new inputStreamreader(System.in));

Quiz a[]=new Quiz[5];

Quiz t=new quiz();

// Creating questions

for (i=0;i<5;i++)

{

System.out.println(“Enter Question””);

a[i].q=br.readLine();

System.out.println(“Enter Correct Answer”);

a[i].c=br.readLine();

t.add(q[i]);

}

// Display questions

for(i=0;i<5;i++)

t.displayquestion(i);

System.out.println(“No of questions answered”+ t.noofquestions());

System.out.println(“ No of Correct Answers”+t.nofcorrectanswers());

}

}