Skip to content

Commit e86cd05

Browse files
authored
Merge pull request nus-cs2113-AY2324S1#10 from AY2324S1-CS2113-F11-3/master
Update
2 parents a746f34 + 5ba3bfe commit e86cd05

11 files changed

+169
-23
lines changed

src/main/java/seedu/duke/Duke.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
//@@author wendelinwemhoener & bayasgalankherlen
1+
//@@author wendelinwemhoener
22

33
package seedu.duke;
44

src/main/java/seedu/duke/flashcard/Flashcard.java

Lines changed: 38 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -2,16 +2,24 @@
22

33
package seedu.duke.flashcard;
44

5-
import java.time.LocalDateTime;
6-
import java.util.ArrayList;
7-
5+
/**
6+
* Represents a flashcard with its associated front and back text as well as
7+
* its id and current difficulty.
8+
*/
89
public class Flashcard {
910
private static int globalMaxId = 1;
1011
private String frontText;
1112
private String backText;
1213
private int id;
1314
private int difficulty;
1415

16+
/**
17+
* Instantiates and returns a flashcard with the given front and back text.
18+
* Its id and difficulty (which is 5) are automatically set.
19+
*
20+
* @param frontText The text on the front of the flashcard.
21+
* @param backText The text on the back of the flashcard.
22+
*/
1523
public Flashcard(String frontText, String backText) {
1624
this.frontText = frontText;
1725
this.backText = backText;
@@ -22,7 +30,13 @@ public Flashcard(String frontText, String backText) {
2230
id = globalMaxId;
2331
}
2432

25-
public static void calculateAndUpdateGlobalMaxId(FlashcardList flashcardList) {
33+
/**
34+
* Updates globalMaxId to be greater than the id of all passed flashcards.
35+
*
36+
* @param flashcardList List of flashcard to calculate the max id over.
37+
*/
38+
public static void calculateAndUpdateGlobalMaxId(
39+
FlashcardList flashcardList) {
2640
int currentMax = 1;
2741

2842
for (Flashcard flashcard : flashcardList.getFlashcards()){
@@ -34,35 +48,46 @@ public static void calculateAndUpdateGlobalMaxId(FlashcardList flashcardList) {
3448
globalMaxId = currentMax + 1;
3549
}
3650

37-
public String getFrontText() {
38-
return frontText;
39-
}
40-
4151
public int getId() {
4252
return id;
4353
}
4454

45-
public String getBackText() {
46-
return backText;
47-
}
48-
4955
//@@author junhyeong0411
5056
public void setId (int id) {
5157
this.id = id;
5258
}
5359

60+
public String getFrontText() {
61+
return frontText;
62+
}
63+
5464
public void setDifficulty(int difficulty) {
5565
this.difficulty = difficulty;
5666
}
5767

68+
public String getBackText() {
69+
return backText;
70+
}
71+
5872

5973
//@@author wendelinwemhoener
74+
/**
75+
* Returns a string representation of this flashcard.
76+
*
77+
* @return Front and back text as well as id and difficulty.
78+
*/
6079
public String toString() {
6180
return "front text: " + frontText + System.lineSeparator()
6281
+ "back text: " + backText + System.lineSeparator()
63-
+ "id: " + id + System.lineSeparator();
82+
+ "id: " + id
83+
+ "difficulty: " + difficulty + System.lineSeparator();
6484
}
6585

86+
/**
87+
* Adjusts (increases) the difficulty of this flashcard.
88+
*
89+
* @param difficultyChange The amount to increase the difficulty by.
90+
*/
6691
public void applyDifficultyChange(int difficultyChange) {
6792
difficulty += difficultyChange;
6893
}

src/main/java/seedu/duke/flashcard/FlashcardCommandParser.java

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,17 @@
1010
import seedu.duke.flashcard.command.DeleteFlashcardCommand;
1111
import seedu.duke.flashcard.command.UnknownCommand;
1212

13+
/**
14+
* Parses input entered by the user into a FlashcardCommand for further
15+
* processing.
16+
*/
1317
public class FlashcardCommandParser {
18+
/**
19+
* Returns the FlashcardCommand corresponding to the passed input.
20+
*
21+
* @param input The text inputted by the user.
22+
* @return The FlashcardCommand corresponding to input
23+
*/
1424
public FlashcardCommand parseInput(String input) {
1525
assert input != null : "input is null";
1626

src/main/java/seedu/duke/flashcard/FlashcardComponent.java

Lines changed: 16 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -8,17 +8,20 @@
88
import java.io.FileNotFoundException;
99
import java.util.ArrayList;
1010

11+
/**
12+
* Encapsulates all classes needed for the flashcard functionality and
13+
* allows access to them via one unified API.
14+
*/
1115
public class FlashcardComponent {
1216
private FlashcardCommandParser parser;
1317
private FlashcardList flashcardList;
1418
private FlashcardUi ui;
1519
private FlashcardStorage storage;
1620

17-
21+
//@@author junhyeong0411
1822
public FlashcardComponent() {
1923
parser = new FlashcardCommandParser();
2024

21-
//@@author junhyeong0411
2225
FlashcardDirectory flashcarddirectory = new FlashcardDirectory();
2326
flashcarddirectory.listFlashcardFiles();
2427

@@ -30,12 +33,10 @@ public FlashcardComponent() {
3033
flashcardList = new FlashcardList(new ArrayList<>());
3134
}
3235

33-
//@@author wendelinwemhoener
3436
Flashcard.calculateAndUpdateGlobalMaxId(flashcardList);
3537
ui = new FlashcardUi(flashcardList);
3638
}
3739

38-
//@@author junhyeong0411
3940
public FlashcardStorage getStorage(){
4041
return this.storage;
4142
}
@@ -54,6 +55,12 @@ public FlashcardUi getUi(){
5455
}
5556

5657
//@@author wendelinwemhoener
58+
/**
59+
* Returns if FlashcardComponent is responsible for handling this input.
60+
*
61+
* @param input The text inputted by the user.
62+
* @return Whether FlashcardComponent is responsible for handling the input.
63+
*/
5764
public boolean isResponsible(String input) {
5865
FlashcardCommand command = parser.parseInput(input);
5966

@@ -64,6 +71,11 @@ public boolean isResponsible(String input) {
6471
}
6572
}
6673

74+
/**
75+
* Processes user input by parsing it and executing the resulting command.
76+
*
77+
* @param input The text inputted by the user.
78+
*/
6779
public void processInput(String input) {
6880
FlashcardCommand command = parser.parseInput(input);
6981
assert !(command instanceof UnknownCommand) : "Command cannot be " +
@@ -74,7 +86,5 @@ public void processInput(String input) {
7486
//@@author junhyeong0411
7587
// save after every commands
7688
storage.saveFlashcards(flashcardList.getFlashcards());
77-
78-
//@@author wendelinwemhoener
7989
}
8090
}

src/main/java/seedu/duke/flashcard/FlashcardList.java

Lines changed: 34 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,18 @@
44

55
import java.util.ArrayList;
66

7+
/**
8+
* Container class for a list of flashcards.
9+
* Exposes a simple, unified API for dealing with a list of flashcards.
10+
*/
711
public class FlashcardList {
812
private ArrayList<Flashcard> flashcards;
913

14+
/**
15+
* Instantiates and returns a FlashcardList holding the passed flashcards.
16+
*
17+
* @param flashcards The flashcards to be contained by the FlashcardList.
18+
*/
1019
public FlashcardList(ArrayList<Flashcard> flashcards) {
1120
this.flashcards = flashcards;
1221
}
@@ -15,25 +24,47 @@ public ArrayList<Flashcard> getFlashcards() {
1524
return flashcards;
1625
}
1726

18-
// @@author junhyeong0411
27+
/**
28+
* Returns the amount of flashcards held by the FlashcardList.
29+
*
30+
* @return The size of the FlashcardList.
31+
*/
1932
public int getSize(){
2033
return flashcards.size();
2134
}
2235

23-
24-
//@@author wendelinwemhoener
36+
/**
37+
* Adds a flashcard to the FlashcardList.
38+
*
39+
* @param flashcard The flashcard that shall be added.
40+
*/
2541
public void add(Flashcard flashcard) {
2642
flashcards.add(flashcard);
2743
}
2844

45+
/**
46+
* Deletes all flashcards in the FlashcardList, effectively emptying it.
47+
*/
2948
public void deleteAllFlashcards() {
3049
flashcards.clear();
3150
}
3251

52+
/**
53+
* Returns whether the FlashcardList contains any flashcards or not.
54+
*
55+
* @return If the FlashcardList is empty.
56+
*/
3357
public boolean isEmpty() {
3458
return flashcards.isEmpty();
3559
}
3660

61+
/**
62+
* Attempts to delete a flashcard by the passed id.
63+
* If no flashcard with the passed id exists, returns false.
64+
*
65+
* @param flashcardId The id of the flashcard to delete.
66+
* @return Whether the deletion was successful (true if successful).
67+
*/
3768
public boolean deleteFlashcardById(int flashcardId) {
3869
int indexToDeleteAt = -1;
3970

src/main/java/seedu/duke/flashcard/FlashcardUi.java

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,15 +6,31 @@
66

77
import java.util.Scanner;
88

9+
/**
10+
* Responsible for interfacing with the user by managing the dispatching of
11+
* commands to be executed and show to the user.
12+
*/
913
public class FlashcardUi {
1014
private Scanner scanner;
1115
private FlashcardList flashcardList;
1216

17+
/**
18+
* Instantiates and returns a new FlashcardUi.
19+
*
20+
* @param flashcardList The flashcards to be used for this Ui.
21+
*/
1322
public FlashcardUi(FlashcardList flashcardList) {
1423
scanner = new Scanner(System.in);
1524
this.flashcardList = flashcardList;
1625
}
1726

27+
/**
28+
* Executes a command and provides it with the appropriate context.
29+
* This context consists of a scanner for handling input and a
30+
* FlashcardList to execute actions on.
31+
*
32+
* @param command The command that shall be executed.
33+
*/
1834
public void executeCommand(FlashcardCommand command) {
1935
command.execute(scanner, flashcardList);
2036
}

src/main/java/seedu/duke/flashcard/command/CreateFlashcardCommand.java

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,19 @@
77

88
import java.util.Scanner;
99

10+
/**
11+
* This command allows creating a new flashcard by inputting its front and
12+
* back text.
13+
*/
1014
public class CreateFlashcardCommand extends FlashcardCommand {
15+
/**
16+
* Creates a new flashcard.
17+
* The user is asked to input the front and back text of the new
18+
* flashcard, and then it is added to the flashcardList.
19+
*
20+
* @param scanner Scanner that allows handling user input.
21+
* @param flashcardList Which flashcards to perform actions on.
22+
*/
1123
public void execute(Scanner scanner, FlashcardList flashcardList) {
1224
System.out.print(" Enter the front page text: ");
1325
String frontPageText = scanner.nextLine();

src/main/java/seedu/duke/flashcard/command/DeleteAllFlashcardsCommand.java

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,16 @@
44

55
import java.util.Scanner;
66

7+
/**
8+
* This command allows deleting all current flashcards.
9+
*/
710
public class DeleteAllFlashcardsCommand extends FlashcardCommand {
11+
/**
12+
* Deletes all flashcards from the flashcardList.
13+
*
14+
* @param scanner Scanner that allows handling user input.
15+
* @param flashcardList Which flashcards to perform actions on.
16+
*/
817
public void execute(Scanner scanner, FlashcardList flashcardList) {
918
flashcardList.deleteAllFlashcards();
1019

src/main/java/seedu/duke/flashcard/command/FlashcardCommand.java

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,19 @@
66

77
import java.util.Scanner;
88

9+
/**
10+
* Abstract class that provides the interface for executing commands by using
11+
* a Scanner for input and a FlashcardList to perform actions on as command
12+
* execution context.
13+
*/
914
public abstract class FlashcardCommand {
15+
/**
16+
* Executes a command, given the appropriate context.
17+
* This context consists of a scanner for handling input and a
18+
* FlashcardList to execute actions on.
19+
*
20+
* @param scanner Scanner that allows handling user input.
21+
* @param flashcardList Which flashcards to perform actions on.
22+
*/
1023
public abstract void execute(Scanner scanner, FlashcardList flashcardList);
1124
}

src/main/java/seedu/duke/flashcard/command/ListFlashcardsCommand.java

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,18 @@
77

88
import java.util.Scanner;
99

10+
/**
11+
* This command allows listing all current flashcards.
12+
*/
1013
public class ListFlashcardsCommand extends FlashcardCommand {
14+
/**
15+
* Prints out a list of all current flashcards.
16+
* Handles the scenario that there are no flashcards by printing an
17+
* appropriate "You dont't have any flashcards yet!" message.
18+
*
19+
* @param scanner Scanner that allows handling user input.
20+
* @param flashcardList Which flashcards to perform actions on.
21+
*/
1122
public void execute(Scanner scanner, FlashcardList flashcardList) {
1223
if (flashcardList.isEmpty()) {
1324
System.out.println(" You dont't have any flashcards yet! ");

0 commit comments

Comments
 (0)