The point of this project is to create a quiz system. Create a class called Quiz. This class manages up to 25 Question objects (create at least 10). Attached below is the Question interface, which your questions must implement. Define two methods in Quiz: public void addQuestion(Question q) - This accepts a question object and adds it to it's list of questions public double giveQuiz() - This presents each question, one by one, to the user and asks for their answer. After each answer, it checks if the answer is correct and keeps track of the results. Finally, it returns the score the user got. Create at least 3 classes that implement Question. You have some freedom in choosing the exact types, but I suggest: MultipleChoiceQuestion TrueFalseQuestion ShortAnswerQuestion Again, each question class MUST implement the Question interface. Implement these methods appropriately for the question type. DO NOT MODIFY THE QUESTION INTERFACE IN ANY WAY. Create a new class called QuizTime, which only has a main() method. In this method, create all of your Question objects and a single Quiz object. Add all of your questions to the quiz, then call giveQuiz() and print out the results to the user. Follow ALL of our rules of encapsulation and proper project design For extra credit, after the quiz is over go through each of the wrongly answered questions and printout the question followed by the correct answer.

Respuesta :

Answer:

Kindly note that, you're to replace "at" with shift 2 as the brainly text editor can't take the symbol

Explanation:

1) Question interface:

package chegg;

public interface Question {

   public String getTheQuestionText();

   public boolean isCorrectAnswer(String answer);

 

 public String getCorrectAnswer();

}

2) MultipleChoiceQuestion class:

package chegg;

public class MultipleChoiceQuestion implements Question {

   private String que;

   private String ans;

   public MultipleChoiceQuestion(String que, String ans) {

       this.que = que;

       this.ans = ans;

   }

   "at"Override

   public String getTheQuestionText() {

       return que;

   }

   "at"Override

   public boolean isCorrectAnswer(String answer) {

       if (ans.equals(answer)) return true;

       else return false;

   }

   "at"Override

   public String getCorrectAnswer() {

       return ans;

   }

}

3) TrueFalseQuestion class:

package chegg;

public class TrueFalseQuestion implements Question {

   private String que;

   private String ans;

   public TrueFalseQuestion(String que, String ans) {

       this.que = que;

       this.ans = ans;

   }

   "at"Override

   public String getTheQuestionText() {

       return que;

   }

   "at"Override

   public boolean isCorrectAnswer(String answer) {

       if (ans.equals(answer)) return true;

       else return false;

   }

   "at"Override

   public String getCorrectAnswer() {

       return ans;

   }

}

4) ShortAnswerQuestion class:

package chegg;

public class ShortAnswerQuestion implements Question {

   private String que;

   private String ans;

   public ShortAnswerQuestion(String que, String ans) {

       this.que = que;

       this.ans = ans;

   }

   "at"Override

   public String getTheQuestionText() {

       return que;

   }

   "at"Override

   public boolean isCorrectAnswer(String answer) {

       if (ans.equals(answer)) return true;

       else return false;

   }

   "at"Override

   public String getCorrectAnswer() {

       return ans;

   }

}

5) Quiz class:

package chegg;

import java.util.ArrayList;

import java.util.Scanner;

public class Quiz {

   private ArrayList<Question> questions;

   private ArrayList<Question> wrong;

   public Quiz(){

       questions = new ArrayList<>();

   }

   public void addQuestion(Question q){

       questions.add(q);

   }

   public double giveQuiz(){

       Scanner sc = new Scanner(System.in);

       int total = questions.size();

       int marks = 0;

       wrong = new ArrayList<>();

       for(int i=0; i<total; i++){

           Question q = questions.get(i);

           System.out.println("Question no. "+i+": "+q.getTheQuestionText());

           System.out.println("your answer: ");

           String ans = sc.next();

           if(q.isCorrectAnswer(ans)) marks++;

           else wrong.add(q);

       }

       double score = marks*100/(double)total;     // score in percentage

       return score;

   }

   public void showWrongAnswer(){

       System.out.println("Solutions to your wrong answers: ");

       for (Question q: wrong){

           System.out.println("Question: "+q.getTheQuestionText());

           System.out.println("Answer: "+q.getCorrectAnswer());

       }

   }

}

6) QuizTime class:

package chegg;

import java.util.Scanner;

public class QuizTime {

   public static void main(String[] args) {

       Scanner sc = new Scanner(System.in);

       System.out.println("Enter number of questions: ");

       int n = sc.nextInt();

       System.out.println("Please choose type of question (enter 1, 2 or 3) : ");

       System.out.println("1. Multiple choice question");

       System.out.println("2. True or False type question");

       System.out.println("3. Short answer question");

       int choice = sc.nextInt();

       Quiz quiz = new Quiz();

       while (n>0){

           System.out.println("Enter question: ");

           String q = sc.next();

           System.out.println("Enter answer: ");

           String ans = sc.next();

           Question question;

           if (choice == 1) question = new MultipleChoiceQuestion(q, ans);

           else if (choice == 2) question = new TrueFalseQuestion(q,  ans);

           else question = new ShortAnswerQuestion(q, ans);

           quiz.addQuestion(question);

           n--;

       }

       System.out.println("Give the following test: ");

       if (choice == 1) System.out.println("Note: all questions are Multiple choice question");

       else if (choice == 2) System.out.println("Note: all questions are True or False type question");

       else System.out.println("Note: all questions are Short answer question");

       double score = quiz.giveQuiz();

       System.out.println("your final score is: "+score+"%");

       quiz.showWrongAnswer();

   }

}