Skip to content

Commit

Permalink
Merge pull request nus-cs2113-AY2324S1#5 from AY2324S1-CS2113-F11-3/m…
Browse files Browse the repository at this point in the history
…aster

Update
  • Loading branch information
Cheezeblokz authored Oct 26, 2023
2 parents b60ffc3 + 7931262 commit 5111380
Show file tree
Hide file tree
Showing 18 changed files with 360 additions and 45 deletions.
10 changes: 2 additions & 8 deletions data/flashcards/flashcard.txt
Original file line number Diff line number Diff line change
@@ -1,8 +1,2 @@
d | a | - | - | -
dfdf | dfdf | - | - | -
dfdf | asdfdf | - | - | -
ddf | dfdf | - | - | -
hello | bye | - | - | -
hello | bye | - | - | -
end program | hello | - | - | -
hello | world | - | - | -
ddd | dfdf | - | - | -
ddff | a | - | - | -
72 changes: 61 additions & 11 deletions docs/UserGuide.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,33 +2,83 @@

## 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

## Features
### Listing all flashcards: `list flashcards`

{Give detailed description of each feature}
Prints out a list of all flashcards.

Format: `list flashcards`

### Adding a todo: `todo`
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 <ENTER>) and then the
back page text (once you have typed it out, submit it by pressing <ENTER>) 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
<ENTER> 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 <ENTER> to reveal the back page.

Format: `create flashcard`

## FAQ

**Q**: How do I transfer my data to another computer?
Expand All @@ -37,6 +87,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`
25 changes: 23 additions & 2 deletions src/main/java/seedu/duke/Duke.java
Original file line number Diff line number Diff line change
Expand Up @@ -28,13 +28,34 @@ private void run() {

if (fc.isResponsible(input)) {
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);
}
}
}
2 changes: 0 additions & 2 deletions src/main/java/seedu/duke/calendar/CalendarManager.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
33 changes: 27 additions & 6 deletions src/main/java/seedu/duke/flashcard/Flashcard.java
Original file line number Diff line number Diff line change
Expand Up @@ -8,22 +8,35 @@
import java.util.ArrayList;

public class Flashcard {
private static int globalMaxId = 1;
private String frontText;
private String backText;
private ArrayList<String> tags;
private ArrayList<FlashcardReview> reviews;
private LocalDateTime lastReviewOn;


private int id;

public Flashcard(String frontText, String backText) {
this.frontText = frontText;
this.backText = backText;

tags = new ArrayList<>();
reviews = new ArrayList<>();

lastReviewOn = null;

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) {
Expand All @@ -34,14 +47,22 @@ public String getFrontText() {
return frontText;
}

public int getId() {
return id;
}

public String getBackText() {
return backText;
}

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) {
reviews.add(flashcardReview);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@
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.DeleteFlashcardCommand;
import seedu.duke.flashcard.command.UnknownCommand;

public class FlashcardCommandParser {
Expand All @@ -17,7 +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(input);
}

return new UnknownCommand();
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/seedu/duke/flashcard/FlashcardComponent.java
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ public class FlashcardComponent {
private FlashcardCommandParser parser;
private FlashcardList flashcardList;
private FlashcardUi ui;

private FlashcardStorage storage;


Expand All @@ -32,6 +31,7 @@ public FlashcardComponent() {
}

//@@author wendelinwemhoener
Flashcard.calculateAndUpdateGlobalMaxId(flashcardList);
ui = new FlashcardUi(flashcardList);
}

Expand Down
26 changes: 26 additions & 0 deletions src/main/java/seedu/duke/flashcard/FlashcardList.java
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,33 @@ public int getSize(){
}


//@@author wendelinwemhoener
public void add(Flashcard flashcard) {
flashcards.add(flashcard);
}

public void deleteAllFlashcards() {
flashcards.clear();
}

public boolean isEmpty() {
return flashcards.isEmpty();
}

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;
}
}
}
16 changes: 14 additions & 2 deletions src/main/java/seedu/duke/flashcard/FlashcardStorage.java
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@
import java.io.IOException;
import java.util.ArrayList;
import java.util.Scanner;
import java.util.logging.Level;
import java.util.logging.Logger;

/**
* storage for flashcards
Expand All @@ -14,10 +16,12 @@
public class FlashcardStorage {
// simply implemented for save & load first

private static Logger flashlogger; // for logging
protected String path;

public FlashcardStorage(String path){
this.path = path;
flashlogger = Logger.getLogger("flash");
}


Expand All @@ -34,7 +38,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();
Expand All @@ -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;
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -105,7 +116,8 @@ public void saveFlashcards(ArrayList<Flashcard> 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");
}
}

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
package seedu.duke.flashcard.command;

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 .");
}
}
Loading

0 comments on commit 5111380

Please sign in to comment.