Skip to content

Commit 5111380

Browse files
authored
Merge pull request nus-cs2113-AY2324S1#5 from AY2324S1-CS2113-F11-3/master
Update
2 parents b60ffc3 + 7931262 commit 5111380

18 files changed

+360
-45
lines changed

data/flashcards/flashcard.txt

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,2 @@
1-
d | a | - | - | -
2-
dfdf | dfdf | - | - | -
3-
dfdf | asdfdf | - | - | -
4-
ddf | dfdf | - | - | -
5-
hello | bye | - | - | -
6-
hello | bye | - | - | -
7-
end program | hello | - | - | -
8-
hello | world | - | - | -
1+
ddd | dfdf | - | - | -
2+
ddff | a | - | - | -

docs/UserGuide.md

Lines changed: 61 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -2,33 +2,83 @@
22

33
## Introduction
44

5-
{Give a product intro}
5+
TaskLinker is a CLI-tool for helping students memorize flashcards and track
6+
their flashcard and generell academic progress in the courses they are taking.
67

78
## Quick Start
89

9-
{Give steps to get started quickly}
10-
1110
1. Ensure that you have Java 11 or above installed.
12-
1. Down the latest version of `Duke` from [here](http://link.to/duke).
11+
1. Down the latest jar from [the latest release on GitHub]
12+
(https://github.com/AY2324S1-CS2113-F11-3/tp/releases).
13+
1. Run the jar via `java -jar duke.jar`
14+
15+
## General explanation of flashcards
16+
17+
## Features
1318

14-
## Features
19+
### Listing all flashcards: `list flashcards`
1520

16-
{Give detailed description of each feature}
21+
Prints out a list of all flashcards.
22+
23+
Format: `list flashcards`
1724

1825
### Adding a todo: `todo`
1926
Adds a new item to the list of todo items.
2027

2128
Format: `todo n/TODO_NAME d/DEADLINE`
2229

2330
* The `DEADLINE` can be in a natural language format.
24-
* The `TODO_NAME` cannot contain punctuation.
31+
* The `TODO_NAME` cannot contain punctuation.
2532

26-
Example of usage:
33+
Example of usage:
2734

2835
`todo n/Write the rest of the User Guide d/next week`
2936

3037
`todo n/Refactor the User Guide to remove passive voice d/13/04/2020`
3138

39+
### Creating a new flashcard: `create flashcard`
40+
41+
Starts the process of adding a new flashcard.
42+
43+
After entering this command, you are prompted to first input the front page
44+
text (once you have typed it out, submit it by pressing <ENTER>) and then the
45+
back page text (once you have typed it out, submit it by pressing <ENTER>) of
46+
your new flashcard.
47+
48+
After you've done this, a success message will be printed out. This
49+
indicates that a new flashcard has been successfully created and saved.
50+
51+
Format: `create flashcard`
52+
53+
### Reviewing your flashcards: `review flashcards`
54+
55+
Starts the process of reviewing flashcard.
56+
57+
After entering this command, you are prompted to select your exact review
58+
mode from 3 choices:
59+
60+
- `random mode`: Randomly selects flashcards to review
61+
- `spaced repetition mode`: Which flashcards are shown depends on how well
62+
you previously knew them. Flashcards which you couldn't remember well are
63+
shown more often, while flashcards which you remembered well are shown
64+
less often.
65+
- `review by tag mode`: Randomly selects flashcards with a certain tag to review
66+
67+
Input `a` to choose `random mode`, input `b` to choose `spaced repetition
68+
mode` and input `c` to choose `review by tag mode`.
69+
70+
Once you've selected a review mode, the actual review begins: the front page
71+
of a flashcard is shown to you. You should now try and think of the answer
72+
(the text on the back page of the flashcard); and once you're ready, press
73+
<ENTER> to compare it to the actual back page.
74+
75+
Now, the process repeats and the next flashcard is shown to you.
76+
77+
If you want to quit the review process, simply input `q` or `quit` instead
78+
of pressing <ENTER> to reveal the back page.
79+
80+
Format: `create flashcard`
81+
3282
## FAQ
3383

3484
**Q**: How do I transfer my data to another computer?
@@ -37,6 +87,6 @@ Example of usage:
3787

3888
## Command Summary
3989

40-
{Give a 'cheat sheet' of commands here}
41-
42-
* Add todo `todo n/TODO_NAME d/DEADLINE`
90+
* List all flashcards: `list flashcards`
91+
* Create a new flashcard: `create flashcard`
92+
* Review your flashcards: `review flashcards`

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

Lines changed: 23 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,13 +28,34 @@ private void run() {
2828

2929
if (fc.isResponsible(input)) {
3030
fc.processInput(input);
31-
3231
} else if (cm.isResponsible(input)) {
3332
cm.processInput(input);
33+
} else if (input.startsWith("help")) {
34+
printHelp();
3435
} else {
3536
System.out.println(" Invalid command! Please try again.");
3637
}
3738
}
3839

3940
}
40-
}
41+
42+
private void printHelp() {
43+
System.out.println(" If you need help, please consult our " +
44+
"user guide at https://ay2324s1-cs2113-f11-3.github" +
45+
".io/tp/UserGuide.html");
46+
System.out.println();
47+
System.out.println(" Here is a quick overview over all available " +
48+
"commands: ");
49+
50+
String[] commandFormats = new String[] {
51+
"list flashcards",
52+
"create flashcard",
53+
"review flashcards",
54+
"help",
55+
};
56+
57+
for (String commandFormat : commandFormats) {
58+
System.out.println(" - " + commandFormat);
59+
}
60+
}
61+
}

src/main/java/seedu/duke/calendar/CalendarManager.java

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,6 @@
44

55
import seedu.duke.calendar.command.EventCommand;
66
import seedu.duke.calendar.command.UnknownCommand;
7-
import seedu.duke.calendar.Event;
8-
import seedu.duke.flashcard.FlashcardStorage;
97

108
import java.io.FileNotFoundException;
119
import java.util.ArrayList;

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

Lines changed: 27 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -8,22 +8,35 @@
88
import java.util.ArrayList;
99

1010
public class Flashcard {
11+
private static int globalMaxId = 1;
1112
private String frontText;
1213
private String backText;
13-
private ArrayList<String> tags;
1414
private ArrayList<FlashcardReview> reviews;
1515
private LocalDateTime lastReviewOn;
16-
17-
16+
private int id;
1817

1918
public Flashcard(String frontText, String backText) {
2019
this.frontText = frontText;
2120
this.backText = backText;
2221

23-
tags = new ArrayList<>();
2422
reviews = new ArrayList<>();
2523

2624
lastReviewOn = null;
25+
26+
globalMaxId += 1;
27+
id = globalMaxId;
28+
}
29+
30+
public static void calculateAndUpdateGlobalMaxId(FlashcardList flashcardList) {
31+
int currentMax = 1;
32+
33+
for (Flashcard flashcard : flashcardList.getFlashcards()){
34+
if (flashcard.getId() > currentMax) {
35+
currentMax = flashcard.getId();
36+
}
37+
}
38+
39+
globalMaxId = currentMax + 1;
2740
}
2841

2942
public void setLastReviewOn(LocalDateTime lastReviewOn) {
@@ -34,14 +47,22 @@ public String getFrontText() {
3447
return frontText;
3548
}
3649

50+
public int getId() {
51+
return id;
52+
}
53+
3754
public String getBackText() {
3855
return backText;
3956
}
4057

4158
public String toString() {
4259
return "front text: " + frontText + System.lineSeparator()
4360
+ "back text: " + backText + System.lineSeparator()
44-
+ "tags: " + tags.toString() + System.lineSeparator()
45-
+ "next review due on: " + lastReviewOn + System.lineSeparator();
61+
+ "next review due on: " + lastReviewOn + System.lineSeparator()
62+
+ "id: " + id + System.lineSeparator();
63+
}
64+
65+
public void addReview(FlashcardReview flashcardReview) {
66+
reviews.add(flashcardReview);
4667
}
4768
}

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

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@
66
import seedu.duke.flashcard.command.CreateFlashcardCommand;
77
import seedu.duke.flashcard.command.ListFlashcardsCommand;
88
import seedu.duke.flashcard.command.StartReviewCommand;
9+
import seedu.duke.flashcard.command.DeleteAllFlashcardsCommand;
10+
import seedu.duke.flashcard.command.DeleteFlashcardCommand;
911
import seedu.duke.flashcard.command.UnknownCommand;
1012

1113
public class FlashcardCommandParser {
@@ -17,7 +19,11 @@ public FlashcardCommand parseInput(String input) {
1719
} else if (input.startsWith("list flashcards")) {
1820
return new ListFlashcardsCommand();
1921
} else if (input.startsWith("review flashcards")) {
20-
return new StartReviewCommand();
22+
return new StartReviewCommand(input);
23+
} else if (input.startsWith("delete all flashcards")) {
24+
return new DeleteAllFlashcardsCommand();
25+
} else if (input.startsWith("delete flashcard")) {
26+
return new DeleteFlashcardCommand(input);
2127
}
2228

2329
return new UnknownCommand();

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@ public class FlashcardComponent {
1212
private FlashcardCommandParser parser;
1313
private FlashcardList flashcardList;
1414
private FlashcardUi ui;
15-
1615
private FlashcardStorage storage;
1716

1817

@@ -32,6 +31,7 @@ public FlashcardComponent() {
3231
}
3332

3433
//@@author wendelinwemhoener
34+
Flashcard.calculateAndUpdateGlobalMaxId(flashcardList);
3535
ui = new FlashcardUi(flashcardList);
3636
}
3737

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

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,33 @@ public int getSize(){
2121
}
2222

2323

24+
//@@author wendelinwemhoener
2425
public void add(Flashcard flashcard) {
2526
flashcards.add(flashcard);
2627
}
28+
29+
public void deleteAllFlashcards() {
30+
flashcards.clear();
31+
}
32+
33+
public boolean isEmpty() {
34+
return flashcards.isEmpty();
35+
}
36+
37+
public boolean deleteFlashcardById(int flashcardId) {
38+
int indexToDeleteAt = -1;
39+
40+
for (int i = 0; i < flashcards.size(); i++) {
41+
if (flashcards.get(i).getId() == flashcardId) {
42+
indexToDeleteAt = i;
43+
}
44+
}
45+
46+
if (indexToDeleteAt == -1) {
47+
return false;
48+
} else {
49+
flashcards.remove(indexToDeleteAt);
50+
return true;
51+
}
52+
}
2753
}

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

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@
66
import java.io.IOException;
77
import java.util.ArrayList;
88
import java.util.Scanner;
9+
import java.util.logging.Level;
10+
import java.util.logging.Logger;
911

1012
/**
1113
* storage for flashcards
@@ -14,10 +16,12 @@
1416
public class FlashcardStorage {
1517
// simply implemented for save & load first
1618

19+
private static Logger flashlogger; // for logging
1720
protected String path;
1821

1922
public FlashcardStorage(String path){
2023
this.path = path;
24+
flashlogger = Logger.getLogger("flash");
2125
}
2226

2327

@@ -34,7 +38,9 @@ public boolean isStorageAvailable(){
3438
*/
3539
private Flashcard loadFlashcard(String[] tokens){
3640

37-
assert tokens.length == 5: "Token length should be 5";
41+
assert tokens.length == 5 : "Token length should be 5";
42+
43+
//flashlogger.log(Level.INFO, "token length is", tokens.length);
3844

3945
String frontText = tokens[0].trim();
4046
String backText = tokens[1].trim();
@@ -45,6 +51,8 @@ private Flashcard loadFlashcard(String[] tokens){
4551

4652
Flashcard flashcard = new Flashcard(frontText, backText);
4753

54+
//flashlogger.log(Level.INFO, "added flashcard");
55+
4856
for(String tag:tags){
4957
if (tag.trim().equals("-")) {
5058
break;
@@ -76,6 +84,9 @@ private Flashcard loadFlashcard(String[] tokens){
7684
* @throws FileNotFoundException
7785
*/
7886
public FlashcardList loadFlashcards() throws FileNotFoundException{
87+
88+
flashlogger.log(Level.INFO, "loading flashcard");
89+
7990
FlashcardList flashcardList = new FlashcardList(new ArrayList<>());
8091
File f = new File (this.path);
8192
Scanner s = new Scanner(f);
@@ -105,7 +116,8 @@ public void saveFlashcards(ArrayList<Flashcard> flashcardList) {
105116
}
106117
fw.close();
107118
} catch (IOException e){
108-
System.out.println("Failed to save.");
119+
//System.out.println("Failed to save.");
120+
flashlogger.log(Level.WARNING, "problem: failed to save");
109121
}
110122
}
111123

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
package seedu.duke.flashcard.command;
2+
3+
import seedu.duke.flashcard.FlashcardList;
4+
5+
import java.util.Scanner;
6+
7+
public class DeleteAllFlashcardsCommand extends FlashcardCommand {
8+
public void execute(Scanner scanner, FlashcardList flashcardList) {
9+
flashcardList.deleteAllFlashcards();
10+
11+
System.out.println(" All your flashcards have been successfully " +
12+
"deleted .");
13+
}
14+
}

0 commit comments

Comments
 (0)