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

Directions In this module, you will create an outline for solving the project pr

ID: 3877262 • Letter: D

Question

Directions In this module, you will create an outline for solving the project problem described below. In addition, you will divide the problem into a sequence of steps (subtasks) and define an outcome of each step. Subsequently, you will formulate model questions and answers for the question bank. Save your assignment using a naming convention that includes your first and last name and the activity number (or description). Do not add punctuation or special characters. Project Problem Write a "quiz" program on a topic, about which you are knowledgeable. This quiz can be work related, general knowledge or any set of questions where there is a specific answer. Ignore questions where long descriptions or general answers needed. The program should display the questions, one at a time, and possible answers, and accept an answer from the user. If the answer is correct, the program should go on to the next question. If it is incorrect, store the question for the second attempt and go on to the next question. When the list of questions has ended, the questions that were missed previously, or answered incorrectly, should be displayed again, in their original order. Keep a count of the correct answers for each category of questions and display the final count after two attempts. Also, display the correct answer, when necessary, in the second round of questioning Limit the quiz to ten (10) questions. Include questions from both true/false and multiple-choice categories. Four (4) possible answers should be listed in multiple-choice questions.

Explanation / Answer

public class Quiz {

   //declare question and option

   String[] question = {"Prime Minister of India?","9*29=","Which city is famous for oranges?"," How may squares are there in a Chess Board?",

           "The oceans cover % of the surface of the earth","Largest river in the world is","Which of the following cities of India is called the "Silicon Valley of India"?",

           "The International Court of Justice has _ judges"," fresh water reserves constitute %"," The percentage of glucose present in the normal urine is"};

   String[] option1 = {"Narendra Modi","197","Kanpur","36","71","Ganga","Pune","10","4.5","0.1"};

   String[] option2 = {"Yogi Adityanath","261","Pune","48","60","Bharamputra","Banglore","15","1.2","0"};

   String[] option3 = {"Rahul Gandhi","271","Mumbai","64","81","Nile","Mumbai","20","7.2","0.2"};

   String[] option4 = {"Sachin Tendukar","191","Nagpur","72","90","Amazon","Chennai","25","2.7","0.9"};

   int[] answer = {1,2,4,3,1,3,2,2,4,1};

   ArrayList<Integer> correctAnswer,wrongAnswer;

   public Quiz() {

       correctAnswer = new ArrayList<>();

       wrongAnswer = new ArrayList<>();

   }

  

   // select random question

   public int SelectQuestion(){

       boolean selected = false;

       int num = 0;

       while(!selected){

           num = ThreadLocalRandom.current().nextInt(0, 10);

           if (!correctAnswer.contains(new Integer(num))){

               if(!wrongAnswer.contains(new Integer(num)))

                   selected = true;

           }

       }

       return num;

   }

  

   //Ask Question with option

   public int askQuestion(int num){

       System.out.println(question[num]);

       System.out.println("1: "+option1[num]);

       System.out.println("2: "+option2[num]);

       System.out.println("3: "+option3[num]);

       System.out.println("4: "+option4[num]);

       return num;

   }

   public static void main(String[] args) {

       Scanner sc = new Scanner(System.in);

       Quiz quiz = new Quiz();

       Integer num;

       System.out.println("Select answer or enter your choice");

       for( int i =0;i<quiz.question.length;i++){

           num = quiz.SelectQuestion();

           quiz.askQuestion(num);

           try{

           int n = sc.nextInt();

           //check answer

           if (n==quiz.answer[num]){

               System.out.println("Your Answer is correct");

               quiz.correctAnswer.add(num);

           }

           else{

               System.out.println("Your Answer is incorrect");

               quiz.wrongAnswer.add(num);

           }

           }

           catch(Exception e){

               System.out.println("Your Answer is incorrect");

               quiz.wrongAnswer.add(num);

           }

          

       }

       //check if any wrong answer

       if (!quiz.wrongAnswer.isEmpty()){

           for (Integer i:(Integer[])quiz.wrongAnswer.toArray()){

               quiz.askQuestion(i);

                   try{

                   int n = sc.nextInt();

                   if (n==quiz.answer[i]){

                       System.out.println("Your Answer is correct");

                       quiz.correctAnswer.add(i);

                   }

                   else{

                       System.out.println("Your Answer is incorrect and Correct answer is" + quiz.answer[i]);

                       quiz.correctAnswer.add(i);

                   }

                   }

                   catch(Exception e){

                       System.out.println("Your Answer is incorrect");

                       quiz.wrongAnswer.add(i);

                   }

           }

       }

       System.out.println("Quiz Completed");

       sc.close();

   }

}

Sample output:

Select answer or enter your choice

The International Court of Justice has _ judges

1: 10

2: 15

3: 20

4: 25

2

Your Answer is correct

Largest river in the world is

1: Ganga

2: Bharamputra

3: Nile

4: Amazon

1

Your Answer is incorrect

Prime Minister of India?

1: Narendra Modi

2: Yogi Adityanath

3: Rahul Gandhi

4: Sachin Tendukar

1

Your Answer is correct

The oceans cover % of the surface of the earth

1: 71

2: 60

3: 81

4: 90

1

Your Answer is correct

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote