Skip to content

Commit 82b72e2

Browse files
documentation
1 parent b7a2573 commit 82b72e2

File tree

9 files changed

+80
-28
lines changed

9 files changed

+80
-28
lines changed

src/main/java/quiz_use_case/GUI/FlatLabel.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,11 @@
88
* @author Anthony
99
*/
1010
public class FlatLabel extends JLabel {
11+
/**
12+
* Creates a FlatLaf styled label.
13+
* @param text the display text
14+
* @param type the style type. Refer to FlatLaf documentation for a list of style types.
15+
*/
1116
public FlatLabel(String text, String type) {
1217
super(text);
1318
this.putClientProperty("FlatLaf.styleClass", type);

src/main/java/quiz_use_case/GUI/MultipleChoiceQuestionCard.java

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,14 +3,15 @@
33
import javax.swing.*;
44
import java.awt.*;
55
import java.awt.event.ActionEvent;
6+
import java.awt.event.ActionListener;
67
import java.util.ArrayList;
78

89
/**
910
* GUI panel that displays a multiple choice question.
1011
* Frameworks & Drivers
1112
* @author Anthony
1213
*/
13-
public class MultipleChoiceQuestionCard extends QuestionCard {
14+
public class MultipleChoiceQuestionCard extends QuestionCard implements ActionListener {
1415
private final ArrayList<JRadioButton> choices;
1516

1617
/**
@@ -99,6 +100,10 @@ public MultipleChoiceQuestionCard(int num, ArrayList<String> outputText, String
99100
}
100101
}
101102

103+
/**
104+
* When a multiple choice button is pressed, this method sets the user answer according to its source button.
105+
* @param e the action event
106+
*/
102107
@Override
103108
public void actionPerformed(ActionEvent e) {
104109
JRadioButton source = (JRadioButton) e.getSource();

src/main/java/quiz_use_case/GUI/QuestionCard.java

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,14 +2,13 @@
22

33
import javax.swing.*;
44
import java.awt.*;
5-
import java.awt.event.ActionListener;
65

76
/**
87
* Abstract class that represents a GUI panel that displays a quiz question.
98
* Frameworks & Drivers
109
* @author Anthony
1110
*/
12-
public abstract class QuestionCard extends JPanel implements ActionListener {
11+
public abstract class QuestionCard extends JPanel {
1312
private String userAnswer = null;
1413

1514
protected FlatLabel number;
@@ -46,11 +45,18 @@ public JLabel generateStatus(boolean isCorrect) {
4645
return new JLabel(statusMessage);
4746
}
4847

49-
/** GETTERS AND SETTERS **/
48+
/**
49+
* Gets the user answer.
50+
* @return the user answer
51+
*/
5052
public String getUserAnswer() {
5153
return this.userAnswer;
5254
}
5355

56+
/**
57+
* Sets the user answer.
58+
* @param userAnswer the user answer
59+
*/
5460
public void setUserAnswer(String userAnswer) {
5561
this.userAnswer = userAnswer;
5662
}

src/main/java/quiz_use_case/GUI/Slider.java

Lines changed: 17 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ public class Slider extends JPanel {
1212
public JSlider slider;
1313

1414
private JLabel title;
15-
private JLabel valueText;
15+
private final JLabel valueText;
1616

1717
/**
1818
* Constructs a slider.
@@ -47,28 +47,35 @@ public void updateValue() {
4747
this.valueText.setText(String.valueOf(this.slider.getValue()));
4848
}
4949

50+
/**
51+
* Gets the slider's current value.
52+
* @return the slider's value
53+
*/
5054
public int getValue() {
5155
return this.slider.getValue();
5256
}
5357

58+
/**
59+
* Adds a change listener to the slider.
60+
* @param listener the change listener
61+
*/
5462
public void addChangeListener(ChangeListener listener) {
5563
this.slider.addChangeListener(listener);
5664
}
5765

58-
/** GETTERS AND SETTERS **/
66+
/**
67+
* Gets the title.
68+
* @return the title
69+
*/
5970
public JLabel getTitle() {
6071
return title;
6172
}
6273

74+
/**
75+
* Sets the title.
76+
* @param title the title
77+
*/
6378
public void setTitle(JLabel title) {
6479
this.title = title;
6580
}
66-
67-
public JLabel getValueText() {
68-
return valueText;
69-
}
70-
71-
public void setValueText(JLabel valueText) {
72-
this.valueText = valueText;
73-
}
7481
}

src/main/java/quiz_use_case/GUI/TextEntryQuestionCard.java

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22

33
import javax.swing.*;
44
import java.awt.*;
5-
import java.awt.event.ActionEvent;
65
import java.util.ArrayList;
76

87
/**
@@ -108,9 +107,4 @@ public TextEntryQuestionCard(int num, ArrayList<String> outputText, String userA
108107
public void updateUserAnswer() {
109108
this.setUserAnswer(this.textArea.getText());
110109
}
111-
112-
@Override
113-
public void actionPerformed(ActionEvent e) {
114-
115-
}
116110
}

src/main/java/quiz_use_case/GUI/TrueFalseQuestionCard.java

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,14 +3,15 @@
33
import javax.swing.*;
44
import java.awt.*;
55
import java.awt.event.ActionEvent;
6+
import java.awt.event.ActionListener;
67
import java.util.ArrayList;
78

89
/**
910
* GUI panel that displays a true false question.
1011
* Frameworks & Drivers
1112
* @author Anthony
1213
*/
13-
public class TrueFalseQuestionCard extends QuestionCard {
14+
public class TrueFalseQuestionCard extends QuestionCard implements ActionListener {
1415
private final JButton trueButton;
1516
private final JButton falseButton;
1617

@@ -108,6 +109,10 @@ public TrueFalseQuestionCard(int num, ArrayList<String> outputText, String userA
108109
this.add(falseButton, c);
109110
}
110111

112+
/**
113+
* If TRUE is toggled, toggle the true button. If FALSE is toggled, toggle the false button.
114+
* @param e the action event
115+
*/
111116
@Override
112117
public void actionPerformed(ActionEvent e) {
113118
String c = e.getActionCommand();

src/main/java/quiz_use_case/QuizRequestModel.java

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
* @author Anthony
99
*/
1010
public class QuizRequestModel {
11-
private ArrayList<String> userAnswers;
11+
private final ArrayList<String> userAnswers;
1212

1313
/**
1414
* Constructs a quiz request model.
@@ -18,12 +18,11 @@ public QuizRequestModel(ArrayList<String> userAnswers) {
1818
this.userAnswers = userAnswers;
1919
}
2020

21-
/** GETTERS AND SETTERS **/
21+
/**
22+
* Gets the user answers.
23+
* @return the user answers
24+
*/
2225
public ArrayList<String> getUserAnswers() {
2326
return userAnswers;
2427
}
25-
26-
public void setUserAnswers(ArrayList<String> userAnswers) {
27-
this.userAnswers = userAnswers;
28-
}
2928
}

src/main/java/quiz_use_case/screens/QuizSettingsScreen.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,8 @@ private enum Actions {
3939
}
4040

4141
/**
42-
* Initializes the quiz settings screen.
42+
* Initializes the quiz settings screen. If there are less than 4 flashcards with the given flashcard set ID, then
43+
* just display an error pane.
4344
* @param controller the quiz settings controller
4445
* @param flashcardSetID the flashcard set ID
4546
*/

src/test/java/quiz_use_case/QuizUseCaseTest.java

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,23 @@
77
import java.io.IOException;
88
import java.util.ArrayList;
99

10+
/**
11+
* This class contains various test cases for the quiz use case.
12+
* @author Anthony
13+
*/
1014
public class QuizUseCaseTest {
1115
QuizController controller;
1216

17+
/**
18+
* This method sets up my tests.
19+
* @param numQuestions the number of questions
20+
* @param timerOn is the timer on
21+
* @param multipleChoiceOn is the multiple choice on
22+
* @param textEntryOn is the text entry on
23+
* @param trueFalseOn is the true false on
24+
* @return the quiz settings request model
25+
* @throws IOException if I can't access the test data
26+
*/
1327
QuizSettingsRequestModel setup(int numQuestions,
1428
boolean timerOn,
1529
boolean multipleChoiceOn,
@@ -32,6 +46,10 @@ QuizSettingsRequestModel setup(int numQuestions,
3246
0, multipleChoiceOn, textEntryOn, trueFalseOn, 0);
3347
}
3448

49+
/**
50+
* Tests the quiz use case when only multiple choice questions are enabled.
51+
* @throws IOException if I can't access the test data
52+
*/
3553
@Test
3654
void testOnlyMultipleChoice() throws IOException {
3755
QuizSettingsRequestModel quizSettingsRequestModel = this.setup(10, false,
@@ -62,6 +80,10 @@ void testOnlyMultipleChoice() throws IOException {
6280
assertEquals(10, quizResponseModel.getNumQuestions());
6381
}
6482

83+
/**
84+
* Tests the quiz use case when all question types are enabled.
85+
* @throws IOException if I can't access the test data
86+
*/
6587
@Test
6688
void testAllOptionsEnabled() throws IOException {
6789
QuizSettingsRequestModel quizSettingsRequestModel = this.setup(12, false,
@@ -90,6 +112,10 @@ void testAllOptionsEnabled() throws IOException {
90112
assertEquals(12, quizResponseModel.getNumQuestions());
91113
}
92114

115+
/**
116+
* Tests the quiz use case when no question types are enabled.
117+
* @throws IOException if I can't access the test data
118+
*/
93119
@Test
94120
void testNoOptionsEnabled() throws IOException {
95121
QuizSettingsRequestModel quizSettingsRequestModel = this.setup(12, false,
@@ -99,6 +125,10 @@ void testNoOptionsEnabled() throws IOException {
99125
assertTrue(quizSettingsResponseModel.isFailed());
100126
}
101127

128+
/**
129+
* Tests the quiz use case when the timer is set to a ridiculous value.
130+
* @throws IOException if I can't access the test data
131+
*/
102132
@Test
103133
void testRidiculousTimer() throws IOException {
104134
QuizSettingsRequestModel quizSettingsRequestModel = this.setup(12, true,

0 commit comments

Comments
 (0)