-
Notifications
You must be signed in to change notification settings - Fork 0
/
TestHelper.java
39 lines (31 loc) · 1.34 KB
/
TestHelper.java
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
//Helper functions for TestLayout
//Calculates score and tracks questions/answers
import java.util.HashMap;
import java.util.ArrayList;
import java.util.Map.Entry;
public class TestHelper {
public static HashMap<String, Integer> currentTestAnswers = new HashMap<String, Integer>(); // at the start of every test we need to clear this
public static ArrayList<String> testAnswers;
public static int currentScore;
public static void addAnswer(String pageKey, int pressedButton){
currentTestAnswers.put(pageKey, pressedButton);
}
public static int getScore(){
String testKey = "";
int totalCorrect = 0;
testAnswers = new ArrayList<String>(currentTestAnswers.keySet());
java.util.Collections.sort(testAnswers);
for( String key : testAnswers){
AnswerKey ak = Resource_Manager.getAnswerKeys(key);
System.out.printf("%s, Answer: %d Correct: %d\n", key, currentTestAnswers.get(key), ak.correctAnswerIndex);
if(ak.correctAnswerIndex == currentTestAnswers.get(key))
{
totalCorrect++;
}
}
double finalScore = 100*((double)totalCorrect/currentTestAnswers.size());
System.out.printf("Final Grade: %.2f\nNum Correct: %d of %d\n", finalScore, totalCorrect, currentTestAnswers.size());
currentScore = (int)finalScore;
return currentScore;
}
}