Write an application that contains 10 multiple-choice quiz questions related to
ID: 3766232 • Letter: W
Question
Write an application that contains 10 multiple-choice quiz questions related to your favorite hobby. Each question should contains three answer choices, named A, B and C. Another array holds the correct answer to each question --- A, B or C. Display each question. Write a method to make sure that user response is either A or B or C only. If not, keep prompting the user until a valid response is entered. If the user response is correct, display the message “Correct!”; if not, display the message “The correct answer is “ and the letter of the correct answer. After the user answers all the questions, compute the number of correct answers and the percentage. Use a void method to display the relevant outputs.
the above bolded items are the only things needed still. the code looks like so:
import java.util.*;
//class
public class MultipleChoiceQuiz
{
//main method
public static void main(String args[])
{
//ten Questions
String questions[]={
"1. SOCCER IS A SPORT",
"2. RUNNING IS DANGEROUS TO YOUR HEALTH",
"3. YOU CAN ONLY USE YOUR FEET IN SOCCER UNLESS YOU ARE THE GOALIE",
"4. YOU NEED CLEATS TO PLAY SOCCER",
"5. THERE ARE RULES IN SOCCER",
"6. SOCCER IS NOT A TEAM SPORT",
"7. SOCCER DOES NOT REQUIRE STAMINA",
"8. THERE ARE 11 PLAYERS ON THE FIELD",
"9. THERE IS NO REFEREE DURING A GAME" ,
"10. ANYONE CAN PLAY SOCCER" } ;
//variable declarations
int a,j,d=0;
char act_answers[]={'A','B','A','A','A','B','B','A','B','A'};
char answer;
Scanner scan = new Scanner(System.in);
//answer check
for(a=0;a<10;a++)
{
System.out.println(questions[a]);
System.out.println("A.True");
System.out.println("B.False");
System.out.println("C. Can'tSay");
answer=scan.nextLine().charAt(0);
//result check
if(answer==act_answers[a])
{
System.out.println("Correct!");
d++;
}
else
{
System.out.println("The correct answer is "+act_answers[a]);
}
}
System.out.println("Number of correct answers are "+d);
}
}
Explanation / Answer
Answer :
import java.util.*;
//class
public class MultipleChoiceQuiz
{
//main method
char act_answers[]={'A','B','A','A','A','B','B','A','B','A'};
String questions[]={
"1. SOCCER IS A SPORT",
"2. RUNNING IS DANGEROUS TO YOUR HEALTH",
"3. YOU CAN ONLY USE YOUR FEET IN SOCCER UNLESS YOU ARE THE GOALIE",
"4. YOU NEED CLEATS TO PLAY SOCCER",
"5. THERE ARE RULES IN SOCCER",
"6. SOCCER IS NOT A TEAM SPORT",
"7. SOCCER DOES NOT REQUIRE STAMINA",
"8. THERE ARE 11 PLAYERS ON THE FIELD",
"9. THERE IS NO REFEREE DURING A GAME" ,
"10. ANYONE CAN PLAY SOCCER" } ;
public static void main(String args[])
{
MultipleChoiceQuiz obj=new MultipleChoiceQuiz();
//ten Questions
//variable declarations
int j;
obj.calculate();
}
void calculate()
{
char answer;
int d=0;
float percentage;
Scanner scan = new Scanner(System.in);
//answer check
for(int a=0;a<10;a++)
{
//int ch;
//System.out.println("Please Enter any integer other than Z to proceed");
//ch=scan.nextInt();
System.out.println(questions[a]);
System.out.println("A.True");
System.out.println("B.False");
System.out.println("C. Can'tSay");
answer=scan.nextLine().charAt(0);
//result check
switch(answer){
case 'A':
if(answer==act_answers[a])
{
System.out.println("Correct!");
d++;
}
else
{
System.out.println("The correct answer is "+act_answers[a]);
}
break;
case 'B':
if(answer==act_answers[a])
{
System.out.println("Correct!");
d++;
}
else
{
System.out.println("The correct answer is "+act_answers[a]);
}
break;
case 'C':
if(answer==act_answers[a])
{
System.out.println("Correct!");
d++;
}
else
{
System.out.println("The correct answer is "+act_answers[a]);
}
break;
default:
System.out.println("Incorrect Input.Please Enter Only A B and C
Choices.Thank you");
break;
}
}
System.out.println("Number of correct answers are "+d);
percentage=(d/10)*100;
System.out.println("Total Percentage is"+percentage);
}
}
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.