Question

In: Mechanical Engineering

write a “quiz” program on a topic, about which you are knowledgeable. this quiz can be...

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.

Solutions

Expert Solution

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","Ban

glore","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();

}

}


Related Solutions

Select a specific topic you are knowledgeable about. Write a blog post (at least three paragraphs)...
Select a specific topic you are knowledgeable about. Write a blog post (at least three paragraphs) on this topic. Include a keyword rich and optimized title, description, Write a 250 page paper on this topic and cite your sources.
Linux Shell Prpgramming 1.Write a quiz-script which will provide some statistics about a quiz results (summarize...
Linux Shell Prpgramming 1.Write a quiz-script which will provide some statistics about a quiz results (summarize how many good answers and how many wrong answers were provided). The script should use up to 3 execution parameters. When executed with two parameters (let’s call it interactive mode), it should assume, that the first file contains a list of questions and the second file contains correct answers to these questions. In such execution case your script should display questions one by one...
For this assignment, write a program that will calculate the quiz average for a student in...
For this assignment, write a program that will calculate the quiz average for a student in the CSCI 240 course. The student's quiz information will be needed for later processing, so it will be stored in an array. For the assignment, declare one array that will hold a maximum of 12 integer elements (ie. the quiz scores). It is recommended that this program be written in two versions. The first version of the program will read a set of quiz...
For this assignment, write a program that will calculate the quiz average for a student in...
For this assignment, write a program that will calculate the quiz average for a student in the CSCI 240 course. The student's quiz information will be needed for later processing, so it will be stored in an array. For the assignment, declare one array that will hold a maximum of 12 integer elements (ie. the quiz scores). It is recommended that this program be written in two versions. The first version of the program will read a set of quiz...
PICK ONE TOPIC AND WRITE ABOUT IT (maybe 3 pages?) or as much as you can...
PICK ONE TOPIC AND WRITE ABOUT IT (maybe 3 pages?) or as much as you can :) 1. Discuss and explain in detail the legacy (inheritance) you want to leave behind for your children? 2. If you were granted three wishes for the present or future what would you wish for and why? Discuss and explain in detail. 3. Discuss in detail five things on your bucket list, and explain why you want to accomplish them in your life time....
A. After studying nutrition science, you should be knowledgeable about nutrition guidelines and how nutrition can...
A. After studying nutrition science, you should be knowledgeable about nutrition guidelines and how nutrition can affect health. Please demonstrate what you have learned by explaining the following: Using terms and concepts that you have learned in this course, examine 8 aspects of your own diet, and explain any changes you may or may not make. For full credit, support each of your 8 choices with facts from the readings. (For example, currently, I rarely eat any nuts. So, I...
Overview For this assignment, write a program that will calculate the quiz average for a student...
Overview For this assignment, write a program that will calculate the quiz average for a student in the CSCI 240 course. The student's quiz information will be needed for later processing, so it will be stored in an array. For the assignment, declare one array that will hold a maximum of 12 integer elements (ie. the quiz scores). It is recommended that this program be written in two versions. The first version of the program will read a set of...
Overview For this assignment, write a program that will calculate the quiz average for a student...
Overview For this assignment, write a program that will calculate the quiz average for a student in the CSCI course. The student's quiz information will be needed for later processing, so it will be stored in an array. For the assignment, declare one array that will hold a maximum of 12 integer elements (ie. the quiz scores). It is recommended that this program be written in two versions. The first version of the program will read a set of quiz...
Overview For this assignment, write a program that will calculate the quiz average for a student...
Overview For this assignment, write a program that will calculate the quiz average for a student in the CSCI 240 course. The student's quiz information will be needed for later processing, so it will be stored in an array. For the assignment, declare one array that will hold a maximum of 12 integer elements (ie. the quiz scores). It is recommended that this program be written in two versions. The first version of the program will read a set of...
Overview For this assignment, write a program that will calculate the quiz average for a student...
Overview For this assignment, write a program that will calculate the quiz average for a student in the CSCI 240 course. The student's quiz information will be needed for later processing, so it will be stored in an array. For the assignment, declare one array that will hold a maximum of 12 integer elements (ie. the quiz scores). It is recommended that this program be written in two versions. The first version of the program will read a set of...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT