-
Notifications
You must be signed in to change notification settings - Fork 0
/
Student.java
133 lines (118 loc) · 3.69 KB
/
Student.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
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
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
/**
*
*/
import java.util.Random;
import java.util.ArrayList;
import java.util.HashMap;
/**
* @author jmcgr
*This class will allow for student objects to be created in order to simulate those student answering random questions
*/
public class Student {
//random number generators to create unique student IDs and random choices made by each student
Random IDGenerator = new Random();
Random randChoice = new Random();
//hashmap to hold character answers(a-d) for each question
HashMap<Integer, Character> answerMap;
//a lists of multiple choice and single choice answers chosen by students
private ArrayList<Character> multipleChoiceAnswers;
private ArrayList<Character> singleChoiceAnswers;
//variables to store values used by methods of the student class, instantiated within said methods
private char choiceMade;
private int generatedID;
private int choiceNum;
private String uniqueStudentID = "011";
private static int asChosen, bsChosen, csChosen,dsChosen;
//constructor creates the student object and creates the student's unique ID,
//the hashmap of question answers, and the choices made for each question
Student(){
generateUniqueID();
generateAnswerMap();
generateAnswerList();
}
//creates unique student ID
private void generateUniqueID() {
generatedID = IDGenerator.nextInt(999999)+ 100000;
uniqueStudentID += Integer.toString(generatedID);
}
//returns the unique ID as a string
public String getStudentID() {
return uniqueStudentID;
}
//creates the answer key hashmap
public void generateAnswerMap() {
answerMap = new HashMap<Integer, Character>();
answerMap.put(0, 'a');
answerMap.put(1, 'b');
answerMap.put(2, 'c');
answerMap.put(3, 'd');
}
//creates the list for chosen answers
public void generateAnswerList() {
multipleChoiceAnswers = new ArrayList<Character>();
singleChoiceAnswers = new ArrayList<Character>();
}
//allows the student object to select an answer to a given question, and increments the total of each answer chosen
public void makeChoice(int questionType) {
if(questionType == 0) {
choiceNum = randChoice.nextInt(2);
if(choiceNum == 0) {
choiceMade = answerMap.get(0);
singleChoiceAnswers.add(choiceMade);
++asChosen;
}
else if(choiceNum == 1) {
choiceMade = answerMap.get(1);
singleChoiceAnswers.add(choiceMade);
++bsChosen;
}
}
else if(questionType == 1) {
choiceNum = randChoice.nextInt(4);
if(choiceNum == 0) {
choiceMade = answerMap.get(0);
multipleChoiceAnswers.add(choiceMade);
++asChosen;
}
else if(choiceNum == 1) {
choiceMade = answerMap.get(1);
multipleChoiceAnswers.add(choiceMade);
++bsChosen;
}
else if(choiceNum == 2) {
choiceMade = answerMap.get(2);
multipleChoiceAnswers.add(choiceMade);
++csChosen;
}
else if(choiceNum == 3) {
choiceMade = answerMap.get(3);
multipleChoiceAnswers.add(choiceMade);
++dsChosen;
}
}
}
//list of multiple choice answers chosen
public ArrayList<Character> getMultChoiceAnswers() {
return multipleChoiceAnswers;
}
//list of single choice answers chosen
public ArrayList<Character> getSingChoiceAnswers() {
return singleChoiceAnswers;
}
//returns the total amount of 'a' answers chosen
public int getAsChosen(){
return asChosen;
}
//returns the total amount of 'b' answers chosen
public int getBsChosen(){
return bsChosen;
}
//returns the total amount of 'c' answers chosen
public int getCsChosen() {
return csChosen;
}
//returns the total amount of 'd' answers chosen
public int getDsChosen() {
return dsChosen;
}
}