-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathStatsMenu.java
More file actions
313 lines (268 loc) · 9.65 KB
/
StatsMenu.java
File metadata and controls
313 lines (268 loc) · 9.65 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
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
/**
* The StatsMenu class is in charge of displaying the different statistics given
* by the Statistics class in an organized manner. This class can be called from
* either TrainMenu or QQMenu, and has a back button to return to the screen
* this class was called from.
*
* @author Jason Dong
* @version May 23, 2018
* @author Period: 2
* @author Assignment: QuickQuiz
*
* @author Sources: none
*/
public class StatsMenu // problem encountered: percent dividing by 0: add
// conditional statement in Statistics
{
/**
* This is the statstics field for holding the Statistics variable passed in
* as a parameter in the constructor
*/
private Statistics stats;
/**
* This is the ProblemDatabase field for holding the ProblemDatabase
* instance taken in as a parameter in the constructor.
*/
private ProblemDatabase problem;
/**
* This is the overall frame for the StatsMenu window
*/
private JFrame frame;
/**
* This is the label which will show the average time for the kinematics
* problems
*/
private JLabel kinematics;
/**
* This is the label which will show the average time for the newton's law
* problems
*/
private JLabel newton;
/**
* This is the label which will show the average time for all the energy
* problems
*/
private JLabel energy;
/**
* This is the label which will show the average time spent for all the
* rotation problems
*/
private JLabel rotation;
/**
* This is the label which shows the average time spent for all the
* gravitation problems
*/
private JLabel gravitation;
/**
* This is the label which shows the average time spent for all of the fluid
* problems
*/
private JLabel fluids;
/**
* This is the label which shows the average number of problems the user got
* right for the kinematics problems
*/
private JLabel kinematicsRight;
/**
* This is the label which shows the average number of problems the user got
* right for the Newton's laws problems
*/
private JLabel newtonRight;
/**
* This is the label which shows the average number of problems the user got
* right for the energy problems
*/
private JLabel energyRight;
/**
* This is the label which shows the average number of problems the user got
* right for the rotation problems
*/
private JLabel rotationRight;
/**
* This is the label which shows the average number of problems the user got
* right for the gravitation problems
*/
private JLabel gravitationRight;
/**
* This is the label which shows the average number of problems the user got
* right for the fluis problems
*/
private JLabel fluidsRight;
/**
* This integer array shows the amount of minutes spent for each of the
* categories of problems
*/
private int minutes[];
/**
* This string simply holds the colon symbol so is easier to refer to later
* on
*/
private String colon;
/**
* This integer array shows the amount of seconds remaining after deducting
* the correct number of minutes from it
*/
private int remainingSeconds[];
/**
* This is an optional zero for the display of the times
*/
private int optionalZero;
/**
* This is the string for the display of the different times
*/
private String stringToReturn[];
/**
* This constructs a StatsMenu. This means creating the two text labels, the
* average time per problem and average number right, as well as the
* different displays for each of the categories for both of these
* categories
*
* @param prob
* is the problem database which although is not used in this
* class, is necessary to transfer around when called
* @param statistics
* is class which contains all the information which is displayed
* in StatsMenu
*/
public StatsMenu( ProblemDatabase prob, Statistics statistics )
{
stats = statistics;
problem = prob;
minutes = new int[6];
remainingSeconds = new int[6];
colon = ":";
optionalZero = 0;
stringToReturn = new String[6];
stringToReturn[0] = "Kinematics: ";
stringToReturn[1] = "Newton's: ";
stringToReturn[2] = "Energy: ";
stringToReturn[3] = "Rotation: ";
stringToReturn[4] = "Gravitation: ";
stringToReturn[5] = "Fluids: ";
JButton back = new JButton( "Back" );
back.setBounds( 10, 10, 50, 50 );
back.addActionListener( new BackButtonListener() );
JLabel text = new JLabel( "Statistics Menu" );
text.setFont( new Font( "font", Font.PLAIN, 48 ) );
text.setHorizontalAlignment( JLabel.CENTER );
text.setBounds( 100, 30, 600, 75 );
JLabel avgTimePerProblem = new JLabel( "Average Time Per Problem in Seconds" );
avgTimePerProblem.setFont( new Font( "font", Font.PLAIN, 30 ) );
avgTimePerProblem.setHorizontalAlignment( JLabel.CENTER );
avgTimePerProblem.setBounds( 100, 105, 600, 75 );
JLabel avgNumRight = new JLabel( "Average Number of Problems Right" );
avgNumRight.setFont( new Font( "font", Font.PLAIN, 30 ) );
avgNumRight.setHorizontalAlignment( JLabel.CENTER );
avgNumRight.setBounds( 100, 250, 600, 75 );
for ( int i = 0; i < 6; i++ )
{
if ( stats.getTime( i ) > 60 )
{
minutes[i] += ( stats.getTime( i ) ) / 60;
remainingSeconds[i] = stats.getTime( i ) - minutes[i] * 60;
}
else
{
minutes[i] = 0;
remainingSeconds[i] = stats.getTime( i );
}
if ( minutes[i] < 10 )
{
if ( remainingSeconds[i] < 10 )
{
stringToReturn[i] += optionalZero + minutes[i] + colon + optionalZero
+ remainingSeconds[i];
}
else
{
stringToReturn[i] += optionalZero + minutes[i] + colon + remainingSeconds[i];
}
}
else
{
if ( remainingSeconds[i] < 10 )
{
stringToReturn[i] += optionalZero + minutes[i] + colon + optionalZero
+ remainingSeconds[i];
}
else
{
stringToReturn[i] += optionalZero + minutes[i] + colon + remainingSeconds[i];
}
}
}
kinematics = new JLabel( stringToReturn[0] );
kinematics.setBounds( 150, 200, 150, 20 );
newton = new JLabel( stringToReturn[1] );
newton.setBounds( 350, 200, 150, 20 );
energy = new JLabel( stringToReturn[2] );
energy.setBounds( 550, 200, 150, 20 );
rotation = new JLabel( stringToReturn[3] );
rotation.setBounds( 150, 230, 150, 20 );
gravitation = new JLabel( stringToReturn[4] );
gravitation.setBounds( 350, 230, 150, 20 );
fluids = new JLabel( stringToReturn[5] );
fluids.setBounds( 550, 230, 150, 20 );
kinematicsRight = new JLabel(
"Kinematics: " + Math.floor( stats.getPercent( 0 ) * 100 ) / 100 );
kinematicsRight.setBounds( 150, 350, 150, 20 );
newtonRight = new JLabel( "Newton: " + Math.floor( stats.getPercent( 1 ) * 100 ) / 100 );
newtonRight.setBounds( 350, 350, 150, 20 );
energyRight = new JLabel( "Energy: " + Math.floor( stats.getPercent( 2 ) * 100 ) / 100 );
energyRight.setBounds( 550, 350, 150, 20 );
rotationRight = new JLabel(
"Rotation: " + Math.floor( stats.getPercent( 3 ) * 100 ) / 100 );
rotationRight.setBounds( 150, 380, 150, 20 );
gravitationRight = new JLabel(
"Graviation: " + Math.floor( stats.getPercent( 4 ) * 100 ) / 100 );
gravitationRight.setBounds( 350, 380, 150, 20 );
fluidsRight = new JLabel( "Fluids: " + Math.floor( stats.getPercent( 5 ) * 100 ) / 100 );
fluidsRight.setBounds( 550, 380, 150, 20 );
frame = new JFrame( "StatsMenu" );
frame.setDefaultCloseOperation( JFrame.EXIT_ON_CLOSE );
Container c = frame.getContentPane();
frame.setLayout( null );
frame.setBounds( 0, 0, 800, 600 );
c.add( back );
c.add( text );
c.add( avgTimePerProblem );
c.add( avgNumRight );
c.add( kinematics );
c.add( newton );
c.add( energy );
c.add( rotation );
c.add( gravitation );
c.add( fluids );
c.add( kinematicsRight );
c.add( newtonRight );
c.add( energyRight );
c.add( rotationRight );
c.add( gravitationRight );
c.add( fluidsRight );
frame.setDefaultCloseOperation( 0 );
frame.setResizable( false );
frame.setVisible( true );
}
/**
* This class is in charge of the back button, which creates a new MainMenu
* class (new window) and disposes of the StatsMenu window.
*
* @author Jason Dong
* @version May 23, 2018
* @author Period: 2
* @author Assignment: QuickQuiz
*
* @author Sources: none
*/
private class BackButtonListener implements ActionListener
{
public void actionPerformed( ActionEvent e )
{
MainMenu mainMenu = new MainMenu( problem, stats );
frame.dispose();
}
}
}