-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathStatistics.java
More file actions
276 lines (243 loc) · 7.41 KB
/
Statistics.java
File metadata and controls
276 lines (243 loc) · 7.41 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
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
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
import java.io.*;
import java.util.*;
/**
* This class is in charge of holding the statistics, including average time and
* average number of problems right for each category, for all the problems
* done. This holds the information regardless of whether the user is using the
* QQ mode or the Train mode.
*
* @author Jason Dong
* @version May 23, 2018
* @author Period: 2
* @author Assignment: QuickQuiz
*
* @author Sources: none
*/
public class Statistics
{
/**
* TotalProblems holds the total problems for each category, with the same
* order throughout all the classes
*/
private int[] totalProblems;
/**
* Holds the numer of problems right for each category, with the same order
* of categories as quickquiz
*/
private int[] correctProblems;
/**
* This double array holds all the percents for the different categories
*/
private Double[] quickQuizPercents;
/**
* This holds the times for all the different categories
*/
private int[] quickQuizTimes;
/**
* Method returns the integer array holding the number of problems for each
* category
*
* @return integer array totalProblems
*/
public int[] getTotalProblems()
{
return totalProblems;
}
/**
* Returns the integer array holding the number of correct problems for each
* category
*
* @return integer array correctProblems
*/
public int[] getCorrectProblems()
{
return correctProblems;
}
/**
* Returns the field, quickQuizPercents which is a double array holding the
* percentage of problems right
*
* @return double array quickQuizPercents
*/
public Double[] getQuickQuizPercents()
{
return quickQuizPercents;
}
/**
* Returns the field, quickQuizTimes which is an integer array holding the
* amount of time spent on each category of problems
*
* @return integer array quickQuizTimes
*/
public int[] getQuickQuizTimes()
{
return quickQuizTimes;
}
/**
* This constructs Statistics, initializing the quickQuizPercents to an
* empty array of size 6 to hold the percents for each category of problems.
* The quickQuizTimes array is initialized to an empty array also of size 6
* to hold all of the times. All values are set to 0.0 (for
* quickQuizPercents) or 0 (for quickQuizTimes), and totalProblems and
* correctProblems are also initialized to empty integer arrays of size 6.
*/
public Statistics()
{
quickQuizPercents = new Double[6];
quickQuizTimes = new int[6];
for ( int i = 0; i < 6; i++ )
{
quickQuizPercents[i] = 0.0;
quickQuizTimes[i] = 0;
}
totalProblems = new int[6];
correctProblems = new int[6];
}
/**
* Adds the time to the correct category, taking in two parameters: the time
* to add and the category to which the time should go in.
*
* @param category
* is the category of which the time should be added to
* @param newTime
* is the increased amount of time of which should be added to
* the time integer array
*/
public void addTime( int category, int newTime )
{
quickQuizTimes[category] += newTime;
}
/**
* This returns the average amount of time spent on a category of problems,
* which is the parameter taken in.
*
* @param category
* is the category of the problems which the user wants to see
* the time of
* @return the integer average number of seconds that the person has spent
* on each category of problems
*/
public int getTime( int category )
{
if ( totalProblems[category] != 0 )
{
return quickQuizTimes[category] / totalProblems[category];
}
else
{
return 0;
}
}
/**
* Returns the average percent for all the problems done, typically called
* by TrainMenu. This sums the total number of problems right as well as the
* total number of problems, then returns the correct average (after
* checking for a dividing by 0 menu)
*
* @return double percentage of problems, or 0.0 if no problems completed
* yet
*/
public double getPercent()
{
int total = 0;
int correct = 0;
for ( int i = 0; i < 6; i++ )
{
correct += correctProblems[i];
total += totalProblems[i];
}
if ( total != 0 )
{
return (double)correct / total;
}
else
{
return 0.0;
}
}
/**
* Returns the percent when given the type as a parameter. This returns the
* percent of problems right for a type of problem, and if there are no
* problems (the index for that totalproblems is 0) then returns 0.0
*
* @param type
* is the type of problem (categories determined previously)
* @return double percentage right or 0.0 if no problems have been completed
* yet
*/
public double getPercent( int type )
{
if ( totalProblems[type] != 0 )
{
return (double)correctProblems[type] / totalProblems[type];
}
else
{
return 0.0;
}
}
/**
* This method adds the proper number of problems correct and total number
* of problems completed to the respective type of problem.
*
* @param numCorrect
* is the number of problems the user correctly completed
* @param TotalNum
* is the total number of problems
* @param type
* is the category of problem
*/
public void addScore( int numCorrect, int TotalNum, int type )
{
correctProblems[type] += numCorrect;
totalProblems[type] += TotalNum;
}
/**
* Returns the average time the user spent per problem in a specific
* category, given by the category integer taken as a parameter. If no
* problems have been completed, then 0.0 is returned
*
* @param category
* is the type of problems that the average time is requested for
* @return the average time spent per problem or 0.0 if no problems have
* been completed
*/
public double avgTimePerProblem( int category )
{
if ( totalProblems[category] != 0 )
{
return (double)quickQuizTimes[category]
/ totalProblems[category];
}
else
{
return 0.0;
}
}
/**
* Returns the average time the user spent per problem in all the
* categories, which means summing up the total times as well as the total
* number of problems completed
*
* @return 0.0 if no problems have been completed or the average time spent
* per all problems if problems have been attempted
*/
public double avgTimePerProblem()
{
int total = 0;
int totProblems = 0;
for ( int i = 0; i < 6; i++ )
{
total += quickQuizTimes[i];
totProblems += totalProblems[i];
}
if ( totProblems != 0 )
{
return (double)total / totProblems;
}
else
{
return 0.0;
}
}
}