import java.util.Scanner;
public class Quiz
{
public static void main (String[] args)
{
// initialize variables
final int NUM_QUESTIONS = 5; // number of questions in quiz
int random1, random2, answer; // question will be random1 * random2
int correct = 0; // will keep track of the number that they get correct
Scanner scan = new Scanner (System.in);
/**
* Create the arrays
*
* I already made an array of ints called answers to store the quiz answers
* Create an array of ints to store the user's answers
* Create an array of Strings called questions to store the quiz questions
*/
int[] answers = new int[NUM_QUESTIONS];
int[] store = new int[NUM_QUESTIONS];
String[] questions = new String[NUM_QUESTIONS];
int count = 0;
// fill the question and answer arrays
for (int i = 0; i < answers.length; i++)
{
random1 = (int) (Math.random() * 10 + 1);
random2 = (int) (Math.random() * 10 + 1);
count++;
questions[i] = "Question #" +count+ ": " + random1 + " * " + random2 + "? ";
answers[i] = random1 * random2;
}
/**
* Prompt questions and fill the user answers array
*
* You'll be filling the array with their answers
*/
for (int i = 0; i < answers.length; i++)
{
System.out.print (questions[i]);
store[i] = scan.nextInt();
}
/**
* Show which ones they got right and wrong
* by comparing their answer to the correct answer
*
* Also, keep track of the number correct
*/
System.out.println();
System.out.println("******************");
System.out.println();
int Correct = 0;
int count2 = 0;
for (int i = 0; i < answers.length; i++)
{
count2++;
System.out.print("Question #"+count2+": ");
if (answers[i] == store[i])
{
System.out.println ("Correct");
Correct++;
}
else
{
System.out.println ("Incorrect");
}
}
System.out.println();
System.out.println("******************");
System.out.println();
/**
* Print their results
*/
double score = (Correct/NUM_QUESTIONS) * 100;
System.out.println ("You got "+Correct+" out of "+NUM_QUESTIONS);
System.out.println ("Your score correct is "+score+"%");
}
}
public class Quiz
{
public static void main (String[] args)
{
// initialize variables
final int NUM_QUESTIONS = 5; // number of questions in quiz
int random1, random2, answer; // question will be random1 * random2
int correct = 0; // will keep track of the number that they get correct
Scanner scan = new Scanner (System.in);
/**
* Create the arrays
*
* I already made an array of ints called answers to store the quiz answers
* Create an array of ints to store the user's answers
* Create an array of Strings called questions to store the quiz questions
*/
int[] answers = new int[NUM_QUESTIONS];
int[] store = new int[NUM_QUESTIONS];
String[] questions = new String[NUM_QUESTIONS];
int count = 0;
// fill the question and answer arrays
for (int i = 0; i < answers.length; i++)
{
random1 = (int) (Math.random() * 10 + 1);
random2 = (int) (Math.random() * 10 + 1);
count++;
questions[i] = "Question #" +count+ ": " + random1 + " * " + random2 + "? ";
answers[i] = random1 * random2;
}
/**
* Prompt questions and fill the user answers array
*
* You'll be filling the array with their answers
*/
for (int i = 0; i < answers.length; i++)
{
System.out.print (questions[i]);
store[i] = scan.nextInt();
}
/**
* Show which ones they got right and wrong
* by comparing their answer to the correct answer
*
* Also, keep track of the number correct
*/
System.out.println();
System.out.println("******************");
System.out.println();
int Correct = 0;
int count2 = 0;
for (int i = 0; i < answers.length; i++)
{
count2++;
System.out.print("Question #"+count2+": ");
if (answers[i] == store[i])
{
System.out.println ("Correct");
Correct++;
}
else
{
System.out.println ("Incorrect");
}
}
System.out.println();
System.out.println("******************");
System.out.println();
/**
* Print their results
*/
double score = (Correct/NUM_QUESTIONS) * 100;
System.out.println ("You got "+Correct+" out of "+NUM_QUESTIONS);
System.out.println ("Your score correct is "+score+"%");
}
}
(0) Comments
Post a Comment