From 77a2404c02bc0d557fa5d3493d6e21fb17475c35 Mon Sep 17 00:00:00 2001 From: junhyeong0411 Date: Fri, 20 Oct 2023 15:50:33 +0900 Subject: [PATCH 01/17] delete assertion --- data/events/event.txt | 1 + src/main/java/seedu/duke/calendar/EventStorage.java | 2 -- src/main/java/seedu/duke/flashcard/FlashcardStorage.java | 1 - 3 files changed, 1 insertion(+), 3 deletions(-) diff --git a/data/events/event.txt b/data/events/event.txt index a66b88d2c9..e78e097630 100644 --- a/data/events/event.txt +++ b/data/events/event.txt @@ -1,2 +1,3 @@ submit v1.0 | 2023-10-29T23:59:59 | 2023-10-30T23:59:59 eat dinner | 2023-12-20T19:00 | 2023-12-20T20:00 +a | 2023-12-12T12:12:12 | 2023-12-12T12:12:13 diff --git a/src/main/java/seedu/duke/calendar/EventStorage.java b/src/main/java/seedu/duke/calendar/EventStorage.java index d71325441c..4449e0cbed 100644 --- a/src/main/java/seedu/duke/calendar/EventStorage.java +++ b/src/main/java/seedu/duke/calendar/EventStorage.java @@ -33,8 +33,6 @@ public boolean isStorageAvailable(){ */ private Event loadEvent(String[] tokens){ - assert tokens.length == 3: "Token length should be 3"; - String name = tokens[0].trim(); LocalDateTime from = LocalDateTime.parse(tokens[1].trim()); LocalDateTime to = LocalDateTime.parse(tokens[2].trim()); diff --git a/src/main/java/seedu/duke/flashcard/FlashcardStorage.java b/src/main/java/seedu/duke/flashcard/FlashcardStorage.java index 780b80ba79..a89b91931c 100644 --- a/src/main/java/seedu/duke/flashcard/FlashcardStorage.java +++ b/src/main/java/seedu/duke/flashcard/FlashcardStorage.java @@ -34,7 +34,6 @@ public boolean isStorageAvailable(){ */ private Flashcard loadFlashcard(String[] tokens){ - assert tokens.length == 5: "Token length should be 5"; String frontText = tokens[0].trim(); String backText = tokens[1].trim(); From fddc13494ec7055cb1119c9e64da9e39f3070b0c Mon Sep 17 00:00:00 2001 From: junhyeong0411 Date: Fri, 20 Oct 2023 16:08:38 +0900 Subject: [PATCH 02/17] re-add assertions --- src/main/java/seedu/duke/calendar/EventStorage.java | 2 ++ src/main/java/seedu/duke/flashcard/FlashcardStorage.java | 1 + 2 files changed, 3 insertions(+) diff --git a/src/main/java/seedu/duke/calendar/EventStorage.java b/src/main/java/seedu/duke/calendar/EventStorage.java index 4449e0cbed..1594d1c98a 100644 --- a/src/main/java/seedu/duke/calendar/EventStorage.java +++ b/src/main/java/seedu/duke/calendar/EventStorage.java @@ -33,6 +33,8 @@ public boolean isStorageAvailable(){ */ private Event loadEvent(String[] tokens){ + assert tokens.length == 3 : "Token length should be 3"; + String name = tokens[0].trim(); LocalDateTime from = LocalDateTime.parse(tokens[1].trim()); LocalDateTime to = LocalDateTime.parse(tokens[2].trim()); diff --git a/src/main/java/seedu/duke/flashcard/FlashcardStorage.java b/src/main/java/seedu/duke/flashcard/FlashcardStorage.java index a89b91931c..b0ef323267 100644 --- a/src/main/java/seedu/duke/flashcard/FlashcardStorage.java +++ b/src/main/java/seedu/duke/flashcard/FlashcardStorage.java @@ -34,6 +34,7 @@ public boolean isStorageAvailable(){ */ private Flashcard loadFlashcard(String[] tokens){ + assert tokens.length == 5 : "Token length should be 5"; String frontText = tokens[0].trim(); String backText = tokens[1].trim(); From 051176a40e4b50d6fcad9e71c3a2ca8d2022e97a Mon Sep 17 00:00:00 2001 From: junhyeong0411 Date: Fri, 20 Oct 2023 16:15:44 +0900 Subject: [PATCH 03/17] Adding loggers --- .../java/seedu/duke/flashcard/FlashcardStorage.java | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/src/main/java/seedu/duke/flashcard/FlashcardStorage.java b/src/main/java/seedu/duke/flashcard/FlashcardStorage.java index b0ef323267..005cdc296c 100644 --- a/src/main/java/seedu/duke/flashcard/FlashcardStorage.java +++ b/src/main/java/seedu/duke/flashcard/FlashcardStorage.java @@ -6,6 +6,7 @@ import java.io.IOException; import java.util.ArrayList; import java.util.Scanner; +import java.util.logging.*; /** * storage for flashcards @@ -18,8 +19,11 @@ public class FlashcardStorage { public FlashcardStorage(String path){ this.path = path; + flashlogger = Logger.getLogger("flash"); } + private static Logger flashlogger; // for logging + public boolean isStorageAvailable(){ File f = new File(this.path); @@ -36,6 +40,8 @@ private Flashcard loadFlashcard(String[] tokens){ assert tokens.length == 5 : "Token length should be 5"; + //flashlogger.log(Level.INFO, "token length is", tokens.length); + String frontText = tokens[0].trim(); String backText = tokens[1].trim(); String[] tags = tokens[2].trim().split("/"); @@ -45,6 +51,8 @@ private Flashcard loadFlashcard(String[] tokens){ Flashcard flashcard = new Flashcard(frontText, backText); + flashlogger.log(Level.INFO, "added flashcard"); + for(String tag:tags){ if (tag.trim().equals("-")) { break; @@ -76,6 +84,9 @@ private Flashcard loadFlashcard(String[] tokens){ * @throws FileNotFoundException */ public FlashcardList loadFlashcards() throws FileNotFoundException{ + + flashlogger.log(Level.INFO, "loading flashcard"); + FlashcardList flashcardList = new FlashcardList(new ArrayList<>()); File f = new File (this.path); Scanner s = new Scanner(f); From f2cf4665d4012966ab6c86e09b7076c203994d9b Mon Sep 17 00:00:00 2001 From: junhyeong0411 Date: Fri, 20 Oct 2023 16:16:34 +0900 Subject: [PATCH 04/17] Logging edited --- src/main/java/seedu/duke/flashcard/FlashcardStorage.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/java/seedu/duke/flashcard/FlashcardStorage.java b/src/main/java/seedu/duke/flashcard/FlashcardStorage.java index 005cdc296c..05977885fc 100644 --- a/src/main/java/seedu/duke/flashcard/FlashcardStorage.java +++ b/src/main/java/seedu/duke/flashcard/FlashcardStorage.java @@ -51,7 +51,7 @@ private Flashcard loadFlashcard(String[] tokens){ Flashcard flashcard = new Flashcard(frontText, backText); - flashlogger.log(Level.INFO, "added flashcard"); + //flashlogger.log(Level.INFO, "added flashcard"); for(String tag:tags){ if (tag.trim().equals("-")) { From fdc7f47d5aa8af3e4ab280ea545cc2838abb49ab Mon Sep 17 00:00:00 2001 From: junhyeong0411 Date: Fri, 20 Oct 2023 16:23:30 +0900 Subject: [PATCH 05/17] Logging edited 2 --- src/main/java/seedu/duke/flashcard/FlashcardStorage.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/java/seedu/duke/flashcard/FlashcardStorage.java b/src/main/java/seedu/duke/flashcard/FlashcardStorage.java index 05977885fc..4b56dc2b7d 100644 --- a/src/main/java/seedu/duke/flashcard/FlashcardStorage.java +++ b/src/main/java/seedu/duke/flashcard/FlashcardStorage.java @@ -85,7 +85,7 @@ private Flashcard loadFlashcard(String[] tokens){ */ public FlashcardList loadFlashcards() throws FileNotFoundException{ - flashlogger.log(Level.INFO, "loading flashcard"); + //flashlogger.log(Level.INFO, "loading flashcard"); FlashcardList flashcardList = new FlashcardList(new ArrayList<>()); File f = new File (this.path); From afff1d71d9f51c96c736c0f0dbaf440ad6d8f542 Mon Sep 17 00:00:00 2001 From: junhyeong0411 Date: Fri, 20 Oct 2023 16:30:03 +0900 Subject: [PATCH 06/17] Get back to no-assertion --- data/events/event.txt | 1 - src/main/java/seedu/duke/calendar/EventStorage.java | 2 +- .../java/seedu/duke/flashcard/FlashcardStorage.java | 13 +------------ 3 files changed, 2 insertions(+), 14 deletions(-) diff --git a/data/events/event.txt b/data/events/event.txt index e78e097630..a66b88d2c9 100644 --- a/data/events/event.txt +++ b/data/events/event.txt @@ -1,3 +1,2 @@ submit v1.0 | 2023-10-29T23:59:59 | 2023-10-30T23:59:59 eat dinner | 2023-12-20T19:00 | 2023-12-20T20:00 -a | 2023-12-12T12:12:12 | 2023-12-12T12:12:13 diff --git a/src/main/java/seedu/duke/calendar/EventStorage.java b/src/main/java/seedu/duke/calendar/EventStorage.java index 1594d1c98a..d71325441c 100644 --- a/src/main/java/seedu/duke/calendar/EventStorage.java +++ b/src/main/java/seedu/duke/calendar/EventStorage.java @@ -33,7 +33,7 @@ public boolean isStorageAvailable(){ */ private Event loadEvent(String[] tokens){ - assert tokens.length == 3 : "Token length should be 3"; + assert tokens.length == 3: "Token length should be 3"; String name = tokens[0].trim(); LocalDateTime from = LocalDateTime.parse(tokens[1].trim()); diff --git a/src/main/java/seedu/duke/flashcard/FlashcardStorage.java b/src/main/java/seedu/duke/flashcard/FlashcardStorage.java index 4b56dc2b7d..780b80ba79 100644 --- a/src/main/java/seedu/duke/flashcard/FlashcardStorage.java +++ b/src/main/java/seedu/duke/flashcard/FlashcardStorage.java @@ -6,7 +6,6 @@ import java.io.IOException; import java.util.ArrayList; import java.util.Scanner; -import java.util.logging.*; /** * storage for flashcards @@ -19,11 +18,8 @@ public class FlashcardStorage { public FlashcardStorage(String path){ this.path = path; - flashlogger = Logger.getLogger("flash"); } - private static Logger flashlogger; // for logging - public boolean isStorageAvailable(){ File f = new File(this.path); @@ -38,9 +34,7 @@ public boolean isStorageAvailable(){ */ private Flashcard loadFlashcard(String[] tokens){ - assert tokens.length == 5 : "Token length should be 5"; - - //flashlogger.log(Level.INFO, "token length is", tokens.length); + assert tokens.length == 5: "Token length should be 5"; String frontText = tokens[0].trim(); String backText = tokens[1].trim(); @@ -51,8 +45,6 @@ private Flashcard loadFlashcard(String[] tokens){ Flashcard flashcard = new Flashcard(frontText, backText); - //flashlogger.log(Level.INFO, "added flashcard"); - for(String tag:tags){ if (tag.trim().equals("-")) { break; @@ -84,9 +76,6 @@ private Flashcard loadFlashcard(String[] tokens){ * @throws FileNotFoundException */ public FlashcardList loadFlashcards() throws FileNotFoundException{ - - //flashlogger.log(Level.INFO, "loading flashcard"); - FlashcardList flashcardList = new FlashcardList(new ArrayList<>()); File f = new File (this.path); Scanner s = new Scanner(f); From d0c716e76a8422c7f0a0a7aecd5cbccad1725160 Mon Sep 17 00:00:00 2001 From: junhyeong0411 Date: Fri, 20 Oct 2023 16:39:29 +0900 Subject: [PATCH 07/17] Logging again --- .../java/seedu/duke/flashcard/FlashcardStorage.java | 12 +++++++++++- text-ui-test/ACTUAL.TXT | 9 +++++++-- 2 files changed, 18 insertions(+), 3 deletions(-) diff --git a/src/main/java/seedu/duke/flashcard/FlashcardStorage.java b/src/main/java/seedu/duke/flashcard/FlashcardStorage.java index 780b80ba79..bf065c5494 100644 --- a/src/main/java/seedu/duke/flashcard/FlashcardStorage.java +++ b/src/main/java/seedu/duke/flashcard/FlashcardStorage.java @@ -6,6 +6,7 @@ import java.io.IOException; import java.util.ArrayList; import java.util.Scanner; +import java.util.logging.*; /** * storage for flashcards @@ -15,9 +16,11 @@ public class FlashcardStorage { // simply implemented for save & load first protected String path; + private static Logger flashlogger; // for logging public FlashcardStorage(String path){ this.path = path; + flashlogger = Logger.getLogger("flash"); } @@ -34,7 +37,9 @@ public boolean isStorageAvailable(){ */ private Flashcard loadFlashcard(String[] tokens){ - assert tokens.length == 5: "Token length should be 5"; + assert tokens.length == 5 : "Token length should be 5"; + + //flashlogger.log(Level.INFO, "token length is", tokens.length); String frontText = tokens[0].trim(); String backText = tokens[1].trim(); @@ -45,6 +50,8 @@ private Flashcard loadFlashcard(String[] tokens){ Flashcard flashcard = new Flashcard(frontText, backText); + //flashlogger.log(Level.INFO, "added flashcard"); + for(String tag:tags){ if (tag.trim().equals("-")) { break; @@ -76,6 +83,9 @@ private Flashcard loadFlashcard(String[] tokens){ * @throws FileNotFoundException */ public FlashcardList loadFlashcards() throws FileNotFoundException{ + + flashlogger.log(Level.INFO, "loading flashcard"); + FlashcardList flashcardList = new FlashcardList(new ArrayList<>()); File f = new File (this.path); Scanner s = new Scanner(f); diff --git a/text-ui-test/ACTUAL.TXT b/text-ui-test/ACTUAL.TXT index 3cba380ccf..3631e57a32 100644 --- a/text-ui-test/ACTUAL.TXT +++ b/text-ui-test/ACTUAL.TXT @@ -1,2 +1,7 @@ -Do you choose flashcard or calendar? -Enter your command: + Failed to create directory +Failed to find files +Making New file for Flashcards + Failed to create directory +Failed to find files +Making new file for Events + Invalid command! Please try again. From 93549d43508cbfe510c1554d356baa2e8894aab8 Mon Sep 17 00:00:00 2001 From: Wendelin Wemhoener Date: Mon, 23 Oct 2023 01:55:21 +0800 Subject: [PATCH 08/17] Explain how to use flashcards in the UG --- data/flashcards/flashcard.txt | 17 +++---- docs/UserGuide.md | 74 +++++++++++++++++++++++++----- src/main/java/seedu/duke/Duke.java | 1 - 3 files changed, 72 insertions(+), 20 deletions(-) diff --git a/data/flashcards/flashcard.txt b/data/flashcards/flashcard.txt index e95f8a7c6e..f934b85e8a 100644 --- a/data/flashcards/flashcard.txt +++ b/data/flashcards/flashcard.txt @@ -1,8 +1,9 @@ -d | a | - | - | - -dfdf | dfdf | - | - | - -dfdf | asdfdf | - | - | - -ddf | dfdf | - | - | - -hello | bye | - | - | - -hello | bye | - | - | - -end program | hello | - | - | - -hello | world | - | - | - +d | a | - | - | - +dfdf | dfdf | - | - | - +dfdf | asdfdf | - | - | - +ddf | dfdf | - | - | - +hello | bye | - | - | - +hello | bye | - | - | - +end program | hello | - | - | - +hello | world | - | - | - +dfdf | dfdf | - | - | - diff --git a/docs/UserGuide.md b/docs/UserGuide.md index abd9fbe891..2dfe4d9756 100644 --- a/docs/UserGuide.md +++ b/docs/UserGuide.md @@ -2,18 +2,27 @@ ## Introduction -{Give a product intro} +TaskLinker is a CLI-tool for helping students memorize flashcards and track +their flashcard and generell academic progress in the courses they are taking. ## Quick Start -{Give steps to get started quickly} - 1. Ensure that you have Java 11 or above installed. -1. Down the latest version of `Duke` from [here](http://link.to/duke). +1. Down the latest jar from [the latest release on GitHub] + (https://github.com/AY2324S1-CS2113-F11-3/tp/releases). +1. Run the jar via `java -jar duke.jar` + +## General explanation of flashcards + + + +## Features + +### Listing all flashcards: `list flashcards` -## Features +Prints out a list of all flashcards. -{Give detailed description of each feature} +Format: `list flashcards` ### Adding a todo: `todo` Adds a new item to the list of todo items. @@ -21,14 +30,57 @@ Adds a new item to the list of todo items. Format: `todo n/TODO_NAME d/DEADLINE` * The `DEADLINE` can be in a natural language format. -* The `TODO_NAME` cannot contain punctuation. +* The `TODO_NAME` cannot contain punctuation. -Example of usage: +Example of usage: `todo n/Write the rest of the User Guide d/next week` `todo n/Refactor the User Guide to remove passive voice d/13/04/2020` +### Creating a new flashcard: `create flashcard` + +Starts the process of adding a new flashcard. + +After entering this command, you are prompted to first input the front page +text (once you have typed it out, submit it by pressing ) and then the +back page text (once you have typed it out, submit it by pressing ) of +your new flashcard. + +After you've done this, a success message will be printed out. This +indicates that a new flashcard has been successfully created and saved. + +Format: `create flashcard` + +### Reviewing your flashcards: `review flashcards` + +Starts the process of reviewing flashcard. + +After entering this command, you are prompted to select your exact review +mode from 3 choices: + +- `random mode`: Randomly selects flashcards to review +- `spaced repetition mode`: Which flashcards are shown depends on how well + you previously knew them. Flashcards which you couldn't remember well are + shown more often, while flashcards which you remembered well are shown + less often. +- `review by tag mode`: Randomly selects flashcards with a certain tag to review + +Input `a` to choose `random mode`, input `b` to choose `spaced repetition +mode` and input `c` to choose `review by tag mode`. + +Once you've selected a review mode, the actual review begins: the front page +of a flashcard is shown to you. You should now try and think of the answer +(the text on the back page of the flashcard); and once you're ready, press + to compare it to the actual back page. + +Now, the process repeats and the next flashcard is shown to you. + +If you want to quit the review process, simply input `q` or `quit` instead +of pressing to reveal the back page. + +Format: `create flashcard` + ## FAQ **Q**: How do I transfer my data to another computer? @@ -37,6 +89,6 @@ Example of usage: ## Command Summary -{Give a 'cheat sheet' of commands here} - -* Add todo `todo n/TODO_NAME d/DEADLINE` +* List all flashcards: `list flashcards` +* Create a new flashcard: `create flashcard` +* Review your flashcards: `review flashcards` diff --git a/src/main/java/seedu/duke/Duke.java b/src/main/java/seedu/duke/Duke.java index 2640517379..e52cfa49bd 100644 --- a/src/main/java/seedu/duke/Duke.java +++ b/src/main/java/seedu/duke/Duke.java @@ -28,7 +28,6 @@ private void run() { if (fc.isResponsible(input)) { fc.processInput(input); - } else if (cm.isResponsible(input)) { cm.processInput(input); } else { From f9406011e0e21093112ae35ffc2741104f66b746 Mon Sep 17 00:00:00 2001 From: Wendelin Wemhoener Date: Mon, 23 Oct 2023 02:16:41 +0800 Subject: [PATCH 09/17] Implement basic help command --- src/main/java/seedu/duke/Duke.java | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/src/main/java/seedu/duke/Duke.java b/src/main/java/seedu/duke/Duke.java index e52cfa49bd..5f147014f5 100644 --- a/src/main/java/seedu/duke/Duke.java +++ b/src/main/java/seedu/duke/Duke.java @@ -30,10 +30,32 @@ private void run() { fc.processInput(input); } else if (cm.isResponsible(input)) { cm.processInput(input); + } else if (input.startsWith("help")) { + printHelp(); } else { System.out.println(" Invalid command! Please try again."); } } } + + private void printHelp() { + System.out.println(" If you need help, please consult our " + + "user guide at https://ay2324s1-cs2113-f11-3.github" + + ".io/tp/UserGuide.html"); + System.out.println(); + System.out.println(" Here is a quick overview over all available " + + "commands: "); + + String[] commandFormats = new String[] { + "list flashcards", + "create flashcard", + "review flashcards", + "help", + }; + + for (String commandFormat : commandFormats) { + System.out.println(" - " + commandFormat); + } + } } \ No newline at end of file From ff87f96f03bf474152f7ec95080e3450f6046916 Mon Sep 17 00:00:00 2001 From: Wendelin Wemhoener Date: Mon, 23 Oct 2023 02:50:30 +0800 Subject: [PATCH 10/17] Allow rating the difficulty of a review --- .../java/seedu/duke/flashcard/Flashcard.java | 4 ++ .../duke/flashcard/FlashcardComponent.java | 1 - .../flashcard/command/StartReviewCommand.java | 4 +- .../flashcard/review/ReviewDifficulty.java | 5 +-- .../duke/flashcard/review/ReviewMode.java | 42 ++++++++++++++++++- 5 files changed, 49 insertions(+), 7 deletions(-) diff --git a/src/main/java/seedu/duke/flashcard/Flashcard.java b/src/main/java/seedu/duke/flashcard/Flashcard.java index 45c72a5666..ea68852d3b 100644 --- a/src/main/java/seedu/duke/flashcard/Flashcard.java +++ b/src/main/java/seedu/duke/flashcard/Flashcard.java @@ -44,4 +44,8 @@ public String toString() { + "tags: " + tags.toString() + System.lineSeparator() + "next review due on: " + lastReviewOn + System.lineSeparator(); } + + public void addReview(FlashcardReview flashcardReview) { + reviews.add(flashcardReview); + } } diff --git a/src/main/java/seedu/duke/flashcard/FlashcardComponent.java b/src/main/java/seedu/duke/flashcard/FlashcardComponent.java index 60d0e5d86f..b9422fcb23 100644 --- a/src/main/java/seedu/duke/flashcard/FlashcardComponent.java +++ b/src/main/java/seedu/duke/flashcard/FlashcardComponent.java @@ -12,7 +12,6 @@ public class FlashcardComponent { private FlashcardCommandParser parser; private FlashcardList flashcardList; private FlashcardUi ui; - private FlashcardStorage storage; diff --git a/src/main/java/seedu/duke/flashcard/command/StartReviewCommand.java b/src/main/java/seedu/duke/flashcard/command/StartReviewCommand.java index a024fe9848..d811969c92 100644 --- a/src/main/java/seedu/duke/flashcard/command/StartReviewCommand.java +++ b/src/main/java/seedu/duke/flashcard/command/StartReviewCommand.java @@ -28,14 +28,14 @@ private String getUserChoiceReviewMode(Scanner scanner) { public void execute(Scanner scanner, FlashcardList flashcardList) { String choice = getUserChoiceReviewMode(scanner); - while (!choices.contains(choice)) { + while (!choices.contains(choice.toLowerCase())) { System.out.println(" Invalid choice! Your choice must be a, b " + "or c! Please try again."); choice = getUserChoiceReviewMode(scanner); } - ReviewMode reviewMode = createReviewMode(choice, flashcardList); + ReviewMode reviewMode = createReviewMode(choice.toLowerCase(), flashcardList); if (reviewMode instanceof RandomReviewMode) { reviewMode.startReviewSession(scanner); diff --git a/src/main/java/seedu/duke/flashcard/review/ReviewDifficulty.java b/src/main/java/seedu/duke/flashcard/review/ReviewDifficulty.java index 36eaa54bbb..ded27fb269 100644 --- a/src/main/java/seedu/duke/flashcard/review/ReviewDifficulty.java +++ b/src/main/java/seedu/duke/flashcard/review/ReviewDifficulty.java @@ -4,7 +4,6 @@ public enum ReviewDifficulty { EASY, - GOOD, - HARD, - AGAIN + MODERATE, + HARD } diff --git a/src/main/java/seedu/duke/flashcard/review/ReviewMode.java b/src/main/java/seedu/duke/flashcard/review/ReviewMode.java index f1cd8ba482..85647c0ae2 100644 --- a/src/main/java/seedu/duke/flashcard/review/ReviewMode.java +++ b/src/main/java/seedu/duke/flashcard/review/ReviewMode.java @@ -6,6 +6,8 @@ import seedu.duke.flashcard.FlashcardList; import java.time.LocalDateTime; +import java.util.ArrayList; +import java.util.Arrays; import java.util.Scanner; public abstract class ReviewMode { @@ -28,7 +30,7 @@ public void startReviewSession(Scanner scanner) { printFlashcardFrontTextPrompt(flashcardToReview); String input = scanner.nextLine(); - boolean shouldTerminate = input.equals("quit") || input.equals("q"); + boolean shouldTerminate = input.startsWith("quit") || input.equals("q"); if (shouldTerminate) { break; } @@ -36,6 +38,8 @@ public void startReviewSession(Scanner scanner) { System.out.println(" The actual back text is: " + flashcardToReview.getBackText()); System.out.println(); + letUserRateReviewDifficulty(scanner, flashcardToReview); + flashcardToReview.setLastReviewOn(LocalDateTime.now()); } @@ -55,4 +59,40 @@ protected void printFlashcardFrontTextPrompt(Flashcard flashcardToReview) { "compare it, or enter 'q'/'quit' to end this " + "review session]"); } + + protected void letUserRateReviewDifficulty(Scanner scanner, + Flashcard flashcard) { + System.out.println(" How hard was it to remeber the back page of " + + "this flashcard?"); + System.out.println(" Press if it was easy, if it was " + + "moderately challenging or if it was quite hard."); + + final ArrayList choices = new ArrayList<>(Arrays.asList( + "e", "m", "h")); + String choice = scanner.nextLine(); + + while (!choices.contains(choice)) { + System.out.println(" Invalid choice! Your choice must be e, m " + + "or h! Please try again."); + + choice = scanner.nextLine(); + } + + ReviewDifficulty reviewDifficulty; + switch (choice.toLowerCase()) { + case "e": + reviewDifficulty = ReviewDifficulty.EASY; + break; + case "m": + reviewDifficulty = ReviewDifficulty.MODERATE; + break; + default: + reviewDifficulty = ReviewDifficulty.HARD; + break; + } + + FlashcardReview flashcardReview = + new FlashcardReview(LocalDateTime.now(), reviewDifficulty); + flashcard.addReview(flashcardReview); + } } From bf3d2334c2cf4fe7e7619b10c7ba80621fca8489 Mon Sep 17 00:00:00 2001 From: Wendelin Wemhoener Date: Mon, 23 Oct 2023 13:45:27 +0800 Subject: [PATCH 11/17] Add ability to delete all flashcards --- data/flashcards/flashcard.txt | 10 +--------- docs/UserGuide.md | 2 -- src/main/java/seedu/duke/flashcard/Flashcard.java | 10 +++++++--- .../duke/flashcard/FlashcardCommandParser.java | 3 +++ .../java/seedu/duke/flashcard/FlashcardList.java | 5 +++++ .../command/DeleteAllFlashcardsCommand.java | 15 +++++++++++++++ 6 files changed, 31 insertions(+), 14 deletions(-) create mode 100644 src/main/java/seedu/duke/flashcard/command/DeleteAllFlashcardsCommand.java diff --git a/data/flashcards/flashcard.txt b/data/flashcards/flashcard.txt index f934b85e8a..3718354c52 100644 --- a/data/flashcards/flashcard.txt +++ b/data/flashcards/flashcard.txt @@ -1,9 +1 @@ -d | a | - | - | - -dfdf | dfdf | - | - | - -dfdf | asdfdf | - | - | - -ddf | dfdf | - | - | - -hello | bye | - | - | - -hello | bye | - | - | - -end program | hello | - | - | - -hello | world | - | - | - -dfdf | dfdf | - | - | - +text | anser | - | - | - diff --git a/docs/UserGuide.md b/docs/UserGuide.md index 2dfe4d9756..946cb4f9bf 100644 --- a/docs/UserGuide.md +++ b/docs/UserGuide.md @@ -14,8 +14,6 @@ their flashcard and generell academic progress in the courses they are taking. ## General explanation of flashcards - - ## Features ### Listing all flashcards: `list flashcards` diff --git a/src/main/java/seedu/duke/flashcard/Flashcard.java b/src/main/java/seedu/duke/flashcard/Flashcard.java index ea68852d3b..ccf38cd3a0 100644 --- a/src/main/java/seedu/duke/flashcard/Flashcard.java +++ b/src/main/java/seedu/duke/flashcard/Flashcard.java @@ -8,13 +8,13 @@ import java.util.ArrayList; public class Flashcard { + private static int current_max_id = 1; private String frontText; private String backText; private ArrayList tags; private ArrayList reviews; private LocalDateTime lastReviewOn; - - + private int id; public Flashcard(String frontText, String backText) { this.frontText = frontText; @@ -24,6 +24,9 @@ public Flashcard(String frontText, String backText) { reviews = new ArrayList<>(); lastReviewOn = null; + + current_max_id += 1; + id = current_max_id; } public void setLastReviewOn(LocalDateTime lastReviewOn) { @@ -42,7 +45,8 @@ public String toString() { return "front text: " + frontText + System.lineSeparator() + "back text: " + backText + System.lineSeparator() + "tags: " + tags.toString() + System.lineSeparator() - + "next review due on: " + lastReviewOn + System.lineSeparator(); + + "next review due on: " + lastReviewOn + System.lineSeparator() + + "id: " + id + System.lineSeparator(); } public void addReview(FlashcardReview flashcardReview) { diff --git a/src/main/java/seedu/duke/flashcard/FlashcardCommandParser.java b/src/main/java/seedu/duke/flashcard/FlashcardCommandParser.java index 3714be31e7..0b5c3b5ffa 100644 --- a/src/main/java/seedu/duke/flashcard/FlashcardCommandParser.java +++ b/src/main/java/seedu/duke/flashcard/FlashcardCommandParser.java @@ -6,6 +6,7 @@ import seedu.duke.flashcard.command.CreateFlashcardCommand; import seedu.duke.flashcard.command.ListFlashcardsCommand; import seedu.duke.flashcard.command.StartReviewCommand; +import seedu.duke.flashcard.command.DeleteAllFlashcardsCommand; import seedu.duke.flashcard.command.UnknownCommand; public class FlashcardCommandParser { @@ -18,6 +19,8 @@ public FlashcardCommand parseInput(String input) { return new ListFlashcardsCommand(); } else if (input.startsWith("review flashcards")) { return new StartReviewCommand(); + } else if (input.startsWith("delete all flashcards")) { + return new DeleteAllFlashcardsCommand(); } return new UnknownCommand(); diff --git a/src/main/java/seedu/duke/flashcard/FlashcardList.java b/src/main/java/seedu/duke/flashcard/FlashcardList.java index cce69c2d36..b2f1a11179 100644 --- a/src/main/java/seedu/duke/flashcard/FlashcardList.java +++ b/src/main/java/seedu/duke/flashcard/FlashcardList.java @@ -21,7 +21,12 @@ public int getSize(){ } + //@@author wendelinwemhoener public void add(Flashcard flashcard) { flashcards.add(flashcard); } + + public void deleteAllFlashcards() { + flashcards.clear(); + } } diff --git a/src/main/java/seedu/duke/flashcard/command/DeleteAllFlashcardsCommand.java b/src/main/java/seedu/duke/flashcard/command/DeleteAllFlashcardsCommand.java new file mode 100644 index 0000000000..5084311d6e --- /dev/null +++ b/src/main/java/seedu/duke/flashcard/command/DeleteAllFlashcardsCommand.java @@ -0,0 +1,15 @@ +package seedu.duke.flashcard.command; + +import seedu.duke.flashcard.Flashcard; +import seedu.duke.flashcard.FlashcardList; + +import java.util.Scanner; + +public class DeleteAllFlashcardsCommand extends FlashcardCommand { + public void execute(Scanner scanner, FlashcardList flashcardList) { + flashcardList.deleteAllFlashcards(); + + System.out.println(" All your flashcards have been successfully " + + "deleted ."); + } +} From 4158e2755549c1dc6d5521ca27c4f60303ce9372 Mon Sep 17 00:00:00 2001 From: Wendelin Wemhoener Date: Wed, 25 Oct 2023 02:10:11 +0800 Subject: [PATCH 12/17] Implement delete single flashcard feature --- data/flashcards/flashcard.txt | 2 +- .../java/seedu/duke/flashcard/Flashcard.java | 10 ++++-- .../flashcard/FlashcardCommandParser.java | 3 ++ .../seedu/duke/flashcard/FlashcardList.java | 17 ++++++++++ .../command/DeleteAllFlashcardsCommand.java | 1 - .../command/DeleteFlashcardCommand.java | 34 +++++++++++++++++++ 6 files changed, 62 insertions(+), 5 deletions(-) create mode 100644 src/main/java/seedu/duke/flashcard/command/DeleteFlashcardCommand.java diff --git a/data/flashcards/flashcard.txt b/data/flashcards/flashcard.txt index 3718354c52..978d515f3d 100644 --- a/data/flashcards/flashcard.txt +++ b/data/flashcards/flashcard.txt @@ -1 +1 @@ -text | anser | - | - | - +dd | a | - | - | - diff --git a/src/main/java/seedu/duke/flashcard/Flashcard.java b/src/main/java/seedu/duke/flashcard/Flashcard.java index ccf38cd3a0..20c81ff0f8 100644 --- a/src/main/java/seedu/duke/flashcard/Flashcard.java +++ b/src/main/java/seedu/duke/flashcard/Flashcard.java @@ -8,7 +8,7 @@ import java.util.ArrayList; public class Flashcard { - private static int current_max_id = 1; + private static int currentMaxId = 1; private String frontText; private String backText; private ArrayList tags; @@ -25,8 +25,8 @@ public Flashcard(String frontText, String backText) { lastReviewOn = null; - current_max_id += 1; - id = current_max_id; + currentMaxId += 1; + id = currentMaxId; } public void setLastReviewOn(LocalDateTime lastReviewOn) { @@ -37,6 +37,10 @@ public String getFrontText() { return frontText; } + public int getId() { + return id; + } + public String getBackText() { return backText; } diff --git a/src/main/java/seedu/duke/flashcard/FlashcardCommandParser.java b/src/main/java/seedu/duke/flashcard/FlashcardCommandParser.java index 0b5c3b5ffa..c03015926f 100644 --- a/src/main/java/seedu/duke/flashcard/FlashcardCommandParser.java +++ b/src/main/java/seedu/duke/flashcard/FlashcardCommandParser.java @@ -7,6 +7,7 @@ import seedu.duke.flashcard.command.ListFlashcardsCommand; import seedu.duke.flashcard.command.StartReviewCommand; import seedu.duke.flashcard.command.DeleteAllFlashcardsCommand; +import seedu.duke.flashcard.command.DeleteFlashcardCommand; import seedu.duke.flashcard.command.UnknownCommand; public class FlashcardCommandParser { @@ -21,6 +22,8 @@ public FlashcardCommand parseInput(String input) { return new StartReviewCommand(); } else if (input.startsWith("delete all flashcards")) { return new DeleteAllFlashcardsCommand(); + } else if (input.startsWith("delete flashcard")) { + return new DeleteFlashcardCommand(); } return new UnknownCommand(); diff --git a/src/main/java/seedu/duke/flashcard/FlashcardList.java b/src/main/java/seedu/duke/flashcard/FlashcardList.java index b2f1a11179..ce34d3a55d 100644 --- a/src/main/java/seedu/duke/flashcard/FlashcardList.java +++ b/src/main/java/seedu/duke/flashcard/FlashcardList.java @@ -29,4 +29,21 @@ public void add(Flashcard flashcard) { public void deleteAllFlashcards() { flashcards.clear(); } + + public boolean deleteFlashcardById(int flashcardId) { + int indexToDeleteAt = -1; + + for (int i = 0; i < flashcards.size(); i++) { + if (flashcards.get(i).getId() == flashcardId) { + indexToDeleteAt = i; + } + } + + if (indexToDeleteAt == -1) { + return false; + } else { + flashcards.remove(indexToDeleteAt); + return true; + } + } } diff --git a/src/main/java/seedu/duke/flashcard/command/DeleteAllFlashcardsCommand.java b/src/main/java/seedu/duke/flashcard/command/DeleteAllFlashcardsCommand.java index 5084311d6e..4fb4de3383 100644 --- a/src/main/java/seedu/duke/flashcard/command/DeleteAllFlashcardsCommand.java +++ b/src/main/java/seedu/duke/flashcard/command/DeleteAllFlashcardsCommand.java @@ -1,6 +1,5 @@ package seedu.duke.flashcard.command; -import seedu.duke.flashcard.Flashcard; import seedu.duke.flashcard.FlashcardList; import java.util.Scanner; diff --git a/src/main/java/seedu/duke/flashcard/command/DeleteFlashcardCommand.java b/src/main/java/seedu/duke/flashcard/command/DeleteFlashcardCommand.java new file mode 100644 index 0000000000..fee6401058 --- /dev/null +++ b/src/main/java/seedu/duke/flashcard/command/DeleteFlashcardCommand.java @@ -0,0 +1,34 @@ +package seedu.duke.flashcard.command; + +import seedu.duke.flashcard.FlashcardList; + +import java.util.Scanner; + +public class DeleteFlashcardCommand extends FlashcardCommand { + public void execute(Scanner scanner, FlashcardList flashcardList) { + System.out.println(" Enter id of the flashcard you want to delete:" + + " "); + + String input = scanner.nextLine(); + int flashcardId; + + try { + flashcardId = Integer.parseInt(input); + } catch (NumberFormatException e) { + System.out.println(" Invalid input! Id must be an integer"); + return; + } + + boolean deletionWasSuccessful = + flashcardList.deleteFlashcardById(flashcardId); + + if (deletionWasSuccessful) { + System.out.println(" Flashcard with id " + flashcardId + " has been " + + "successfully deleted."); + } else { + System.out.println(" Couldn't find a flashcard with id " + flashcardId); + System.out.println(" No deletion has been performed. Please " + + "try again with a valid id."); + } + } +} \ No newline at end of file From c5ad99d1776f8c86699759c29003279c0055898d Mon Sep 17 00:00:00 2001 From: Wendelin Wemhoener Date: Wed, 25 Oct 2023 02:19:28 +0800 Subject: [PATCH 13/17] Handle empty flashcardlist when listing flashcards --- data/flashcards/flashcard.txt | 1 - src/main/java/seedu/duke/flashcard/FlashcardList.java | 4 ++++ .../seedu/duke/flashcard/command/ListFlashcardsCommand.java | 5 +++++ 3 files changed, 9 insertions(+), 1 deletion(-) diff --git a/data/flashcards/flashcard.txt b/data/flashcards/flashcard.txt index 978d515f3d..e69de29bb2 100644 --- a/data/flashcards/flashcard.txt +++ b/data/flashcards/flashcard.txt @@ -1 +0,0 @@ -dd | a | - | - | - diff --git a/src/main/java/seedu/duke/flashcard/FlashcardList.java b/src/main/java/seedu/duke/flashcard/FlashcardList.java index ce34d3a55d..b4d909c91c 100644 --- a/src/main/java/seedu/duke/flashcard/FlashcardList.java +++ b/src/main/java/seedu/duke/flashcard/FlashcardList.java @@ -30,6 +30,10 @@ public void deleteAllFlashcards() { flashcards.clear(); } + public boolean isEmpty() { + return flashcards.isEmpty(); + } + public boolean deleteFlashcardById(int flashcardId) { int indexToDeleteAt = -1; diff --git a/src/main/java/seedu/duke/flashcard/command/ListFlashcardsCommand.java b/src/main/java/seedu/duke/flashcard/command/ListFlashcardsCommand.java index d70eba6cac..aa4f35117b 100644 --- a/src/main/java/seedu/duke/flashcard/command/ListFlashcardsCommand.java +++ b/src/main/java/seedu/duke/flashcard/command/ListFlashcardsCommand.java @@ -9,6 +9,11 @@ public class ListFlashcardsCommand extends FlashcardCommand { public void execute(Scanner scanner, FlashcardList flashcardList) { + if (flashcardList.isEmpty()) { + System.out.println(" You dont't have any flashcards yet! "); + return; + } + System.out.println(" Here is a list of all your flashcards: "); System.out.println(); From a1f94ee9aa703813e0744a97621f4c44bde962ad Mon Sep 17 00:00:00 2001 From: Wendelin Wemhoener Date: Wed, 25 Oct 2023 02:37:42 +0800 Subject: [PATCH 14/17] Implement calculating global flashcard id --- data/flashcards/flashcard.txt | 1 + .../java/seedu/duke/flashcard/Flashcard.java | 18 +++++++++++++++--- .../duke/flashcard/FlashcardComponent.java | 1 + 3 files changed, 17 insertions(+), 3 deletions(-) diff --git a/data/flashcards/flashcard.txt b/data/flashcards/flashcard.txt index e69de29bb2..791a74256d 100644 --- a/data/flashcards/flashcard.txt +++ b/data/flashcards/flashcard.txt @@ -0,0 +1 @@ +dfdf | f | - | - | - diff --git a/src/main/java/seedu/duke/flashcard/Flashcard.java b/src/main/java/seedu/duke/flashcard/Flashcard.java index 20c81ff0f8..191690844c 100644 --- a/src/main/java/seedu/duke/flashcard/Flashcard.java +++ b/src/main/java/seedu/duke/flashcard/Flashcard.java @@ -8,7 +8,7 @@ import java.util.ArrayList; public class Flashcard { - private static int currentMaxId = 1; + private static int globalMaxId = 1; private String frontText; private String backText; private ArrayList tags; @@ -25,8 +25,20 @@ public Flashcard(String frontText, String backText) { lastReviewOn = null; - currentMaxId += 1; - id = currentMaxId; + globalMaxId += 1; + id = globalMaxId; + } + + public static void calculateAndUpdateGlobalMaxId(FlashcardList flashcardList) { + int currentMax = 1; + + for (Flashcard flashcard : flashcardList.getFlashcards()){ + if (flashcard.getId() > currentMax) { + currentMax = flashcard.getId(); + } + } + + globalMaxId = currentMax + 1; } public void setLastReviewOn(LocalDateTime lastReviewOn) { diff --git a/src/main/java/seedu/duke/flashcard/FlashcardComponent.java b/src/main/java/seedu/duke/flashcard/FlashcardComponent.java index b9422fcb23..004dddbfbd 100644 --- a/src/main/java/seedu/duke/flashcard/FlashcardComponent.java +++ b/src/main/java/seedu/duke/flashcard/FlashcardComponent.java @@ -31,6 +31,7 @@ public FlashcardComponent() { } //@@author wendelinwemhoener + Flashcard.calculateAndUpdateGlobalMaxId(flashcardList); ui = new FlashcardUi(flashcardList); } From 8d899093642a6c22ea743b90b9b980902b7d2677 Mon Sep 17 00:00:00 2001 From: junhyeong0411 Date: Thu, 26 Oct 2023 04:13:16 +0900 Subject: [PATCH 15/17] Making Java CI test pass --- src/main/java/seedu/duke/Duke.java | 10 +++++----- src/main/java/seedu/duke/calendar/CalendarManager.java | 2 -- .../java/seedu/duke/flashcard/FlashcardStorage.java | 10 ++++++---- .../duke/flashcard/command/DeleteFlashcardCommand.java | 2 +- src/test/java/seedu/duke/DukeTest.java | 2 -- 5 files changed, 12 insertions(+), 14 deletions(-) diff --git a/src/main/java/seedu/duke/Duke.java b/src/main/java/seedu/duke/Duke.java index 5f147014f5..bdb913c923 100644 --- a/src/main/java/seedu/duke/Duke.java +++ b/src/main/java/seedu/duke/Duke.java @@ -48,14 +48,14 @@ private void printHelp() { "commands: "); String[] commandFormats = new String[] { - "list flashcards", - "create flashcard", - "review flashcards", - "help", + "list flashcards", + "create flashcard", + "review flashcards", + "help", }; for (String commandFormat : commandFormats) { System.out.println(" - " + commandFormat); } } -} \ No newline at end of file +} diff --git a/src/main/java/seedu/duke/calendar/CalendarManager.java b/src/main/java/seedu/duke/calendar/CalendarManager.java index 34eaa21ad1..6e1a7db435 100644 --- a/src/main/java/seedu/duke/calendar/CalendarManager.java +++ b/src/main/java/seedu/duke/calendar/CalendarManager.java @@ -4,8 +4,6 @@ import seedu.duke.calendar.command.EventCommand; import seedu.duke.calendar.command.UnknownCommand; -import seedu.duke.calendar.Event; -import seedu.duke.flashcard.FlashcardStorage; import java.io.FileNotFoundException; import java.util.ArrayList; diff --git a/src/main/java/seedu/duke/flashcard/FlashcardStorage.java b/src/main/java/seedu/duke/flashcard/FlashcardStorage.java index bf065c5494..1d2c1dd8b1 100644 --- a/src/main/java/seedu/duke/flashcard/FlashcardStorage.java +++ b/src/main/java/seedu/duke/flashcard/FlashcardStorage.java @@ -6,7 +6,8 @@ import java.io.IOException; import java.util.ArrayList; import java.util.Scanner; -import java.util.logging.*; +import java.util.logging.Level; +import java.util.logging.Logger; /** * storage for flashcards @@ -16,7 +17,7 @@ public class FlashcardStorage { // simply implemented for save & load first protected String path; - private static Logger flashlogger; // for logging + static private Logger flashlogger; // for logging public FlashcardStorage(String path){ this.path = path; @@ -39,7 +40,7 @@ private Flashcard loadFlashcard(String[] tokens){ assert tokens.length == 5 : "Token length should be 5"; - //flashlogger.log(Level.INFO, "token length is", tokens.length); + //flashlogger.log(Level.INFO, "token length is", tokens.length); String frontText = tokens[0].trim(); String backText = tokens[1].trim(); @@ -115,7 +116,8 @@ public void saveFlashcards(ArrayList flashcardList) { } fw.close(); } catch (IOException e){ - System.out.println("Failed to save."); + //System.out.println("Failed to save."); + flashlogger.log(Level.WARNING, "problem: failed to save"); } } diff --git a/src/main/java/seedu/duke/flashcard/command/DeleteFlashcardCommand.java b/src/main/java/seedu/duke/flashcard/command/DeleteFlashcardCommand.java index fee6401058..2432f2ce88 100644 --- a/src/main/java/seedu/duke/flashcard/command/DeleteFlashcardCommand.java +++ b/src/main/java/seedu/duke/flashcard/command/DeleteFlashcardCommand.java @@ -31,4 +31,4 @@ public void execute(Scanner scanner, FlashcardList flashcardList) { "try again with a valid id."); } } -} \ No newline at end of file +} diff --git a/src/test/java/seedu/duke/DukeTest.java b/src/test/java/seedu/duke/DukeTest.java index 3f9f8bf927..2748e0373c 100644 --- a/src/test/java/seedu/duke/DukeTest.java +++ b/src/test/java/seedu/duke/DukeTest.java @@ -7,8 +7,6 @@ import seedu.duke.flashcard.FlashcardComponent; import seedu.duke.flashcard.FlashcardStorage; -import java.util.ArrayList; - class DukeTest { @Test public void sampleTest() { From 20104be19278321a020c4d81703af96787f0c4d4 Mon Sep 17 00:00:00 2001 From: junhyeong0411 Date: Thu, 26 Oct 2023 04:16:13 +0900 Subject: [PATCH 16/17] Making Java CI test pass (again) --- src/main/java/seedu/duke/flashcard/FlashcardStorage.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/java/seedu/duke/flashcard/FlashcardStorage.java b/src/main/java/seedu/duke/flashcard/FlashcardStorage.java index 1d2c1dd8b1..d74154c3cd 100644 --- a/src/main/java/seedu/duke/flashcard/FlashcardStorage.java +++ b/src/main/java/seedu/duke/flashcard/FlashcardStorage.java @@ -16,8 +16,8 @@ public class FlashcardStorage { // simply implemented for save & load first + private static Logger flashlogger; // for logging protected String path; - static private Logger flashlogger; // for logging public FlashcardStorage(String path){ this.path = path; From f9dbd3ebe7f5ced63fa60e2b5853f177bf55d0a2 Mon Sep 17 00:00:00 2001 From: Wendelin Wemhoener Date: Thu, 26 Oct 2023 13:43:35 +0800 Subject: [PATCH 17/17] Add expert mode for deleting and reviewing --- data/flashcards/flashcard.txt | 3 +- .../java/seedu/duke/flashcard/Flashcard.java | 3 -- .../flashcard/FlashcardCommandParser.java | 4 +- .../command/DeleteFlashcardCommand.java | 30 +++++++++++++- .../command/DualFlashcardCommand.java | 29 +++++++++++++ .../flashcard/command/StartReviewCommand.java | 41 ++++++++++++++++++- 6 files changed, 100 insertions(+), 10 deletions(-) create mode 100644 src/main/java/seedu/duke/flashcard/command/DualFlashcardCommand.java diff --git a/data/flashcards/flashcard.txt b/data/flashcards/flashcard.txt index 791a74256d..e0e9e10c3e 100644 --- a/data/flashcards/flashcard.txt +++ b/data/flashcards/flashcard.txt @@ -1 +1,2 @@ -dfdf | f | - | - | - +ddd | dfdf | - | - | - +ddff | a | - | - | - diff --git a/src/main/java/seedu/duke/flashcard/Flashcard.java b/src/main/java/seedu/duke/flashcard/Flashcard.java index 191690844c..ed620d2a8d 100644 --- a/src/main/java/seedu/duke/flashcard/Flashcard.java +++ b/src/main/java/seedu/duke/flashcard/Flashcard.java @@ -11,7 +11,6 @@ public class Flashcard { private static int globalMaxId = 1; private String frontText; private String backText; - private ArrayList tags; private ArrayList reviews; private LocalDateTime lastReviewOn; private int id; @@ -20,7 +19,6 @@ public Flashcard(String frontText, String backText) { this.frontText = frontText; this.backText = backText; - tags = new ArrayList<>(); reviews = new ArrayList<>(); lastReviewOn = null; @@ -60,7 +58,6 @@ public String getBackText() { public String toString() { return "front text: " + frontText + System.lineSeparator() + "back text: " + backText + System.lineSeparator() - + "tags: " + tags.toString() + System.lineSeparator() + "next review due on: " + lastReviewOn + System.lineSeparator() + "id: " + id + System.lineSeparator(); } diff --git a/src/main/java/seedu/duke/flashcard/FlashcardCommandParser.java b/src/main/java/seedu/duke/flashcard/FlashcardCommandParser.java index c03015926f..e9a7b6f39c 100644 --- a/src/main/java/seedu/duke/flashcard/FlashcardCommandParser.java +++ b/src/main/java/seedu/duke/flashcard/FlashcardCommandParser.java @@ -19,11 +19,11 @@ public FlashcardCommand parseInput(String input) { } else if (input.startsWith("list flashcards")) { return new ListFlashcardsCommand(); } else if (input.startsWith("review flashcards")) { - return new StartReviewCommand(); + return new StartReviewCommand(input); } else if (input.startsWith("delete all flashcards")) { return new DeleteAllFlashcardsCommand(); } else if (input.startsWith("delete flashcard")) { - return new DeleteFlashcardCommand(); + return new DeleteFlashcardCommand(input); } return new UnknownCommand(); diff --git a/src/main/java/seedu/duke/flashcard/command/DeleteFlashcardCommand.java b/src/main/java/seedu/duke/flashcard/command/DeleteFlashcardCommand.java index 2432f2ce88..6d12b96cb1 100644 --- a/src/main/java/seedu/duke/flashcard/command/DeleteFlashcardCommand.java +++ b/src/main/java/seedu/duke/flashcard/command/DeleteFlashcardCommand.java @@ -4,8 +4,18 @@ import java.util.Scanner; -public class DeleteFlashcardCommand extends FlashcardCommand { - public void execute(Scanner scanner, FlashcardList flashcardList) { +public class DeleteFlashcardCommand extends DualFlashcardCommand { + private String input = null; + + public DeleteFlashcardCommand(String input) { + this.input = input; + beginnerCommandLength = 2; + expertCommandLength = 3; + syntaxString = "delete flashcard FLASHCARD_ID"; + } + + protected void executeBeginnerMode(Scanner scanner, + FlashcardList flashcardList) { System.out.println(" Enter id of the flashcard you want to delete:" + " "); @@ -19,6 +29,22 @@ public void execute(Scanner scanner, FlashcardList flashcardList) { return; } + deleteFlashcardById(flashcardId, flashcardList); + } + + protected void executeExpertMode(Scanner scanner, + FlashcardList flashcardList) { + String[] commandParts = input.split(" "); + + try { + int flashcardId = Integer.parseInt(commandParts[2]); + deleteFlashcardById(flashcardId, flashcardList); + } catch (NumberFormatException e) { + System.out.println(" Invalid id! Id must be an integer"); + } + } + + private void deleteFlashcardById(int flashcardId, FlashcardList flashcardList) { boolean deletionWasSuccessful = flashcardList.deleteFlashcardById(flashcardId); diff --git a/src/main/java/seedu/duke/flashcard/command/DualFlashcardCommand.java b/src/main/java/seedu/duke/flashcard/command/DualFlashcardCommand.java new file mode 100644 index 0000000000..8d2bb119bd --- /dev/null +++ b/src/main/java/seedu/duke/flashcard/command/DualFlashcardCommand.java @@ -0,0 +1,29 @@ +package seedu.duke.flashcard.command; + +import seedu.duke.flashcard.FlashcardList; + +import java.util.Scanner; + +public abstract class DualFlashcardCommand extends FlashcardCommand { + protected int beginnerCommandLength; + protected int expertCommandLength; + protected String input; + protected String syntaxString; + + protected abstract void executeBeginnerMode(Scanner scanner, FlashcardList flashcardList); + + protected abstract void executeExpertMode(Scanner scanner, + FlashcardList flashcardList); + + public void execute(Scanner scanner, FlashcardList flashcardList) { + String[] commandParts = input.split(" "); + if (commandParts.length == beginnerCommandLength) { + executeBeginnerMode(scanner, flashcardList); + } else if (commandParts.length == expertCommandLength) { + executeExpertMode(scanner, flashcardList); + } else { + System.out.println(" Invalid syntax! The syntax is '" + syntaxString + "'"); + System.out.println(" Please try again."); + } + } +} diff --git a/src/main/java/seedu/duke/flashcard/command/StartReviewCommand.java b/src/main/java/seedu/duke/flashcard/command/StartReviewCommand.java index d811969c92..3bea59c6aa 100644 --- a/src/main/java/seedu/duke/flashcard/command/StartReviewCommand.java +++ b/src/main/java/seedu/duke/flashcard/command/StartReviewCommand.java @@ -12,10 +12,17 @@ import java.util.Arrays; import java.util.Scanner; -public class StartReviewCommand extends FlashcardCommand { +public class StartReviewCommand extends DualFlashcardCommand { private final ArrayList choices = new ArrayList<>(Arrays.asList( "a", "b", "c")); + public StartReviewCommand(String input) { + this.input = input; + beginnerCommandLength = 2; + expertCommandLength = 3; + syntaxString = "review flashcards REVIEW_MODE"; + } + private String getUserChoiceReviewMode(Scanner scanner) { System.out.println(" How do you want to review your flashcards?"); System.out.println(" a) random mode"); @@ -25,7 +32,8 @@ private String getUserChoiceReviewMode(Scanner scanner) { return scanner.nextLine(); } - public void execute(Scanner scanner, FlashcardList flashcardList) { + protected void executeBeginnerMode(Scanner scanner, + FlashcardList flashcardList) { String choice = getUserChoiceReviewMode(scanner); while (!choices.contains(choice.toLowerCase())) { @@ -35,6 +43,35 @@ public void execute(Scanner scanner, FlashcardList flashcardList) { choice = getUserChoiceReviewMode(scanner); } + startReview(scanner, flashcardList, choice); + } + + protected void executeExpertMode(Scanner scanner, + FlashcardList flashcardList) { + String[] commandParts = input.split(" "); + + try { + String choice = commandParts[2].toLowerCase(); + + if (!choices.contains(choice)) { + System.out.println(" Invalid choice! Your choice must be a, b " + + "or c! Please try again."); + return; + } + + startReview(scanner, flashcardList, choice); + } catch (IndexOutOfBoundsException e) { + System.out.println(" Invalid syntax! The syntax is 'review " + + "flashcards REVIEW_MODE'"); + System.out.println(" Please try again."); + } + + + } + + private void startReview(Scanner scanner, + FlashcardList flashcardList, + String choice) { ReviewMode reviewMode = createReviewMode(choice.toLowerCase(), flashcardList); if (reviewMode instanceof RandomReviewMode) {