Write a program that grades arithmetic quizzes as follows: Ask the user how many
ID: 651808 • Letter: W
Question
Write a program that grades arithmetic quizzes as follows:
Ask the user how many questions are in the quiz.
Ask the user to enter the key (that is, the correct answers). There should be one answer for each question in the quiz, and each answer should be an integer. They can be entered on a single line, e.g., 34 7 13 100 81 3 9 10 321 12 might be the key for a 10-question quiz. You will need to store the key in an array.
Ask the user to enter the answers for the quiz to be graded. As for the key, these can be entered on a single line. Again there needs to be one for each question. Note that these answers do not need to be stored; each answer can simply be compared to the key as it is entered.
When the user has entered all of the answers to be graded, print the number correct and the percent correct.
When this works, add a loop so that the user can grade any number of quizzes with a single key. After the results have been printed for each quiz, ask
Explanation / Answer
Answer
please rate - thanks
I tried to clean the form a little, and don't need to ask how manyquizzes or the variable total_Quizzes
import java.util.*;
public class Quiz
{
public static void main(String[] args)
{
int num_quiz; //numberon the quiz
int to_grade;
int count = 0;
double total;
char yesorno='y';
Scanner scan = newScanner (System.in);
System.out.print ("Howmany questions are in the quiz? ");
num_quiz =scan.nextInt();
int [] answers = new int[num_quiz];
System.out.println("Enter the answer keys for the questions.");
for (int i=0; i<answers.length; i++)
{
answers[i] = scan.nextInt();
}
while(yesorno=='y'||yesorno=='Y')
{count=0;
for (int i =0; i< answers.length; i++)
{
System.out.println("Enter the answer to be graded : ");
to_grade = scan.nextInt();
if(to_grade == answers[i])
{
++count;
}
}
total =(double)count / num_quiz *100;
System.out.println("Thenumber of questions correct are: " + count);
System.out.println("Thepercentage correct is: " +total);
System.out.println("Grade another Quiz? y/n");
yesorno=scan.next().charAt(0);
}
}
}
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.