-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathGradeQuiz.java
More file actions
69 lines (63 loc) · 1.78 KB
/
GradeQuiz.java
File metadata and controls
69 lines (63 loc) · 1.78 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
import java.util.*;
public class GradeQuiz
{
private int[] key;
private int[] studentAnswers;
private int quizSize;
public GradeQuiz()
{
Scanner input = new Scanner(System.in);
System.out.println("How many questions are in the quiz?");
quizSize = input.nextInt();
key = new int[quizSize];
studentAnswers = new int[quizSize];
}
public void enterKey()
{
Scanner input1 = new Scanner(System.in);
System.out.println("Please enter the correct answers for the quiz, separated by spaces.");
String[] correctKey = input1.nextLine().split(" ");
for (int i = 0; i < correctKey.length; i++)
{
key[i] = Integer.valueOf(correctKey[i]);
}
}
public void enterStudentAnswers()
{
Scanner input2 = new Scanner(System.in);
System.out.println("Please enter the answers from your student, separated by spaces.");
String[] inputAnswers = input2.nextLine().split(" ");
for (int i = 0; i < inputAnswers.length; i++)
{
studentAnswers[i] = Integer.valueOf(inputAnswers[i]);
}
}
public void checkAnswers()
{
int numCorrect = 0;
for (int i = 0; i < quizSize; i++)
{
if (key[i] == studentAnswers[i])
{
numCorrect++;
}
}
System.out.println("The number of correct student answers was " + numCorrect + "/" + quizSize + ".");
System.out.println("The percentage of correct questions was " + ((double)numCorrect / (double)quizSize) * 100 + "%.");
}
public void loopMethod()
{
Scanner input3 = new Scanner(System.in);
System.out.println("Would you like to check another student's answers? (Y/N)");
if (input3.nextLine().equals("Y"))
{
enterStudentAnswers();
checkAnswers();
loopMethod();
}
else
{
System.out.println("Goodbye.");
}
}
}