-
Notifications
You must be signed in to change notification settings - Fork 0
/
report.tex
476 lines (405 loc) · 16.2 KB
/
report.tex
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
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
\documentclass{report}
%packages
\usepackage[utf8]{inputenc}
\usepackage{listings}
\usepackage{courier}
\usepackage{lipsum}
\usepackage{minted}
\usepackage{tabu}
\usepackage{graphicx}
\usepackage{longtable}
\usepackage{caption}
\graphicspath{ {screenshots/} }
\title{Programming Coursework Report}
\author{Quinn Stevens}
\date{June 2017}
\setminted{breaklines}
\begin{document}
\tabulinesep=1.2mm
\maketitle
\tableofcontents
\part{Quiz Game}
\chapter{Testing Plan}
\begin{longtable}[c]{|p{0.2\textwidth}|p{0.2\textwidth}|p{0.2\textwidth}|p{0.2\textwidth}|p{0.2\textwidth}|}
\hline
\textbf{Environment} & \textbf{Action} & \textbf{Expected Result} & \textbf{Actual Result} & \textbf{Proof}\\
\hline
Program Closed & Run Program & Main Menu form opens & Main Menu form opened & see screenshot \ref{fig:screenshot01}\\
\hline
Main Menu & Click 'Quit' Button & Program closes & Program closed & see screenshot \ref{fig:screenshot02}\\
\hline
Main Menu & Click 'Easy' Button & Asks first easy question & Asked first easy question & see screenshot \ref{fig:screenshot03}\\
\hline
Quiz & Click radio button & Radio button selected & Radio button selected & see screenshot \ref{fig:screenshot04}\\
\hline
Quiz & Click Answer while radio button selected & Ask next question & Asked next question & see screenshot \ref{fig:screenshot05} \\
\hline
Quiz & Click Answer while radio button not selected & Ask next question & Asked next question & see screenshot \ref{fig:screenshot06} \\
\hline
Quiz & Click Skip & Ask Next Question & Asked next question & see screenshot \ref{fig:screenshot07}\\
\hline
Quiz & Finish Quiz & Ask if you want to repeat skipped questions & Asked if you want to repeat skipped questions & see screenshot \ref{fig:screenshot08}\\
\hline
Skipped Questions Dialogue & Click `Yes' & Re-ask skipped questions & Re-asked skipped questions & see screenshot \ref{fig:screenshot09}\\
\hline
Quiz & Finish Quiz with wrong answers (No skipped questions or click `No' on skipped questions dialogue or finished retrying skipped questions) & Show end of quiz report with corrections & Showed end of quiz report with corrections & see screenshot \ref{fig:screenshot10}\\
\hline
Quiz & Finish Quiz with no wrong answers & Show end of quiz report without corrections & Showed end of quiz report without corrections & see screenshot \ref{fig:screenshot11}\\
\hline
Main Menu & Click `Hard' Button & Asks first hard question & Asked first hard question & see screenshot \ref{fig:screenshot12}\\
\hline
\end{longtable}
\chapter{Testing Screenshots}
\begin{figure}[H]
\centering
\includegraphics{Screenshot01}
\caption{Screenshot 01}
\label{fig:screenshot01}
\end{figure}
\begin{figure}
\centering
\includegraphics{Screenshot02}
\caption{Screenshot 02}
\label{fig:screenshot02}
\end{figure}
\begin{figure}
\centering
\includegraphics{Screenshot03}
\caption{Screenshot 03}
\label{fig:screenshot03}
\end{figure}
\begin{figure}
\centering
\includegraphics{Screenshot04}
\caption{Screenshot 04}
\label{fig:screenshot04}
\end{figure}
\begin{figure}
\centering
\includegraphics{Screenshot05}
\caption{Screenshot 05}
\label{fig:screenshot05}
\end{figure}
\begin{figure}
\centering
\includegraphics{Screenshot06}
\caption{Screenshot 06}
\label{fig:screenshot06}
\end{figure}
\begin{figure}
\centering
\includegraphics{Screenshot06}
\caption{Screenshot 07}
\label{fig:screenshot07}
\end{figure}
\begin{figure}
\centering
\includegraphics{Screenshot08}
\caption{Screenshot 08}
\label{fig:screenshot08}
\end{figure}
\begin{figure}
\centering
\includegraphics{Screenshot09}
\caption{Screenshot 09}
\label{fig:screenshot09}
\end{figure}
\begin{figure}
\centering
\includegraphics{Screenshot10}
\caption{Screenshot 10}
\label{fig:screenshot10}
\end{figure}
\begin{figure}
\centering
\includegraphics{Screenshot11}
\caption{Screenshot 11}
\label{fig:screenshot11}
\end{figure}
\begin{figure}
\centering
\includegraphics{Screenshot12}
\caption{Screenshot 12}
\label{fig:screenshot12}
\end{figure}
\chapter{Critical Analysis}
\section{Strengths}
\begin{itemize}
\item Allows users to choose from two different difficulties
\item Gives feedback on how the user did
\item Allows users to save questions for later
\end{itemize}
\section{Weaknesses}
\begin{itemize}
\item Scoring is binary - it doesn't give the user any second chances
\item Doesn't allow users to skip questions multiple times
\item Doesn't stop the user if they don't answer a question
\end{itemize}
\section{Suggested Enhancements}
\begin{itemize}
\item Allow user to skip a question multiple times
\item Stop the user from continuing with the quiz if they don't select an answer
\item Allow the user to retry questions they got wrong, but with a reduced points reward
\end{itemize}
\section{Adherence to Specification}
\begin{longtable}[c]{|p{0.6\textwidth}|p{0.2\textwidth}|}
\hline
\textbf{Requirement} & \textbf{Fulfilled?} \\ \hline
The system should be dialogue-based & Yes \\ \hline
Good interface design and programming principles should be applied throughout & Yes \\ \hline
Upon start of the program, the first question with its corresponding answers should be displayed & Yes \\ \hline
The question number should be displayed, and the options labelled appropriately & Yes \\ \hline
When the user clicks the OK button, the second question with its corresponding answers should be displayed & Yes \\ \hline
The above step should be repeated until all 10 questions have been displayed & Yes \\ \hline
When all questions are answered the program should display the user's score along with an appropriate message & Yes \\ \hline
Questions and answers should NOT be hard-coded and must be imported from external files & Yes \\ \hline
When taking the test, if the user tries to view the next question without providing an answer to the current question, a message should be displayed to alert them & No \\ \hline
In returning to a skipped question, an answer must be provided (A question cannot be skipped twice) & Yes (although I do not agree that this improves the test program) \\ \hline
The system should display the questions that have been incorrectly answered. Repeating the failed questions should not change the user's final score. & Yes (again, I believe that changing this would improve the program) \\ \hline
The user should have the choice of the difficulty level of the test: e.g. setting up two or more files each containing a set of questions at different levels of difficulty & Yes \\ \hline
\end{longtable}
\chapter{Source Code}
\begin{minted}{java}
import javax.swing.*;
/**
* Created by Quinn Stevens on 31/05/2017.
*/
public class Quiz {
static int score = 0;
public static void main (String[] args) {
runQuiz();
}
public static void runQuiz() {
String[] questions;
String[][] options;
String[] correctAnswers;
Object[] difficulties = {"Easy", "Hard", "Quit"};
int difficulty = JOptionPane.showOptionDialog(null, "Start quiz?", "Start quiz", JOptionPane.YES_NO_OPTION, JOptionPane.QUESTION_MESSAGE, null, difficulties, difficulties[0]);
FileReader fr = new FileReader();
if (difficulty == 0) {
questions = fr.getArray("resources/easy/questions.txt");
options = fr.getAnswerArray("resources/easy/options.txt");
correctAnswers = fr.getArray("resources/easy/answers.txt");
QuestionMaster qm = new QuestionMaster(questions, options, correctAnswers);
} else if (difficulty == 1){
questions = fr.getArray("resources/hard/questions.txt");
options = fr.getAnswerArray("resources/hard/options.txt");
correctAnswers = fr.getArray("resources/hard/answers.txt");
QuestionMaster qm = new QuestionMaster(questions, options, correctAnswers);
} else {
System.exit(0);
}
}
}
\end{minted}
\captionof{listing}{Quiz.java}
\begin{minted}{java}
import javax.swing.*;
import java.awt.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.util.Objects;
import java.util.Stack;
/**
* Created by Quinn Stevens on 31/05/2017.
*/
public class QuestionMaster implements ActionListener {
JFrame frame;
int questionNum= 0;
int score = 0;
String currentAnswer;
String[] questions;
String[][] options;
String[] answers;
boolean skipAllowed;
Stack skipped = new Stack();
int incorrectAnswers = 0;
String report = "";
public QuestionMaster (String[] questions, String[][] options, String[] answers) {
this.questions = questions;
this.options = options;
this.answers = answers;
this.questionNum = 0;
skipAllowed = true;
askQuestion(questions[questionNum], options[questionNum], answers[questionNum]);
}
private void askQuestion(String question, String[] options, String answer) {
frame = new JFrame("Qui[2{n}|z]");
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.setLocation(600, 300);
frame.setLayout(new BorderLayout());
// Panel for question
JLabel qLabel = new JLabel("Question " + (questionNum+1) + ": " + question);
// Panel for answer options
JPanel buttonPanel = new JPanel(new GridLayout(0, 1));
ButtonGroup buttonGroup = new ButtonGroup();
JRadioButton[] answerButtons = new JRadioButton[options.length];
for (int i = 0; i < answerButtons.length; i++) {
answerButtons[i] = new JRadioButton(options[i]);
answerButtons[i].addActionListener(this);
buttonGroup.add(answerButtons[i]);
buttonPanel.add(answerButtons[i]);
}
// Panel for controls
JPanel controlPanel = new JPanel(new FlowLayout());
// Create quit button
JButton quitButton = new JButton("Quit");
quitButton.setActionCommand("quit");
quitButton.addActionListener(this);
controlPanel.add(quitButton);
if (skipAllowed) {
// Create skip button
JButton skipButton = new JButton("Skip");
skipButton.setActionCommand("skip");
skipButton.addActionListener(this);
controlPanel.add(skipButton);
}
// Create submit button
JButton answerButton = new JButton("Answer");
answerButton.setActionCommand("answer");
answerButton.addActionListener(this);
controlPanel.add(answerButton);
frame.add(qLabel, BorderLayout.NORTH);
frame.add(buttonPanel, BorderLayout.CENTER);
frame.add(controlPanel, BorderLayout.SOUTH);
frame.pack();
frame.setVisible(true);
}
private void nextQuestion() {
frame.dispose();
questionNum++;
if (questionNum < questions.length) {
askQuestion(questions[questionNum], options[questionNum], answers[questionNum]);
} else if (!skipped.empty()) {
Object[] skipOptions = {"Yes", "No"};
int retry = JOptionPane.showOptionDialog(
null,
"You skipped " + skipped.size() + " questions. Would you like to retry them?",
"Retry skipped questions?",
JOptionPane.YES_NO_OPTION,
JOptionPane.QUESTION_MESSAGE,
null,
skipOptions,
skipOptions[1]);
if (retry == 0) {
skipAllowed = false;
retrySkipped();
} else {
endQuiz();
}
} else {
endQuiz();
}
}
private void updateReport() {
incorrectAnswers += 1;
report += "\n\nQ: " + questions[questionNum] + "\nCorrect answer: " + answers[questionNum] + "\n";
}
private void endQuiz() {
if (incorrectAnswers != 0) {
report = "\n\nYou got " + incorrectAnswers + " wrong:" + report;
}
JOptionPane.showMessageDialog(null, "You have scored " + score + " out of 10.\n" +
"This is equivalent to " + Math.round(score/10.0*100) + "%\nWell done!" + report);
}
private void checkAnswer() {
if (Objects.equals(currentAnswer, answers[questionNum])) {
score ++;
} else {
updateReport();
}
}
private void resetQuiz() {
frame.dispose();
Quiz.runQuiz();
}
private void retrySkipped() {
int stackSize = skipped.size();
String[] skippedQs = new String[stackSize];
String[][] skippedOpts = new String[stackSize][4];
String[] skippedAnsw = new String[stackSize];
for (int i = stackSize-1; i >= 0; i--) {
int qNum = (int) skipped.pop();
skippedQs[i] = questions[qNum];
skippedOpts[i] = options[qNum];
skippedAnsw[i] = answers[qNum];
}
questions = skippedQs;
options = skippedOpts;
answers = skippedAnsw;
questionNum = -1;
nextQuestion();
}
@Override
public void actionPerformed(ActionEvent event) {
String command = event.getActionCommand();
if (command == "answer" && currentAnswer != null) {
checkAnswer();
nextQuestion();
} else if (command == "answer" && currentAnswer == null) {
JOptionPane.showMessageDialog(null, "You haven't selected an answer!");
} else if (command == "quit") {
resetQuiz();
} else if (command == "skip") {
skipped.push(questionNum);
nextQuestion();
} else {
currentAnswer = command;
}
}
}
\end{minted}
\captionof{listing}{QuestionMaster.java}
\begin{minted}{java}
import java.io.File;
import java.io.IOException;
import java.util.Scanner;
import java.util.Stack;
/**
* Created by Quinn Stevens on 31/05/2017.
*/
public class FileReader {
public String[][] getAnswerArray(String filename) {
String[] inputArray = getArray(filename);
String[][] outputArray = new String[inputArray.length][4];
String[] splitText;
for (int i = 0; i < inputArray.length; i++) {
splitText = inputArray[i].split(", ");
for (int j = 0; j < splitText.length; j++) {
outputArray[i][j] = splitText[j];
}
}
return outputArray;
}
public String[] getArray(String filename) {
String[] text = null;
try {
text = readFile(filename);
} catch (IOException e) {
e.printStackTrace();
}
return text;
}
public static String[] readFile(String filename) throws IOException {
String fileLine;
Stack textStack = new Stack();
File questionFile = new File(filename);
Scanner fileScan = new Scanner(questionFile);
while (fileScan.hasNext()) {
fileLine = fileScan.nextLine();
textStack.push(fileLine);
}
String[] textArray = new String[textStack.size()];
for (int i = textArray.length -1; i >=0; i--) {
textArray[i] = (String) textStack.pop();
}
return textArray;
}
}
\end{minted}
\captionof{listing}{FileReader.java}
\addcontentsline{toc}{chapter}{Appendix I: Banking Program}
\chapter*{Appendix I: Banking Program}
\section{Source Code}
\section{Output}
\end{document}