Skip to content

Commit

Permalink
Merge pull request nus-cs2113-AY2324S1#12 from wendelinwemhoener/impr…
Browse files Browse the repository at this point in the history
…ove-flashcard-support

Improve flashcard support
  • Loading branch information
wendelinwemhoener authored Oct 16, 2023
2 parents 83dcbf3 + eaa2901 commit 1793052
Show file tree
Hide file tree
Showing 22 changed files with 260 additions and 33 deletions.
1 change: 1 addition & 0 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -43,4 +43,5 @@ checkstyle {

run{
standardInput = System.in
enableAssertions = true
}
2 changes: 1 addition & 1 deletion docs/team/wendelinwemhoener.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# John Doe - Project Portfolio Page
# Wendelin Wemhoener - Project Portfolio Page

## Overview

Expand Down
6 changes: 6 additions & 0 deletions flashcard.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
dfdfdf | aaaaaaaaaaaaaaaaaaa | - | - | -
flash1 | dfdfdf | - | - | -
adfdf | dfdfdf | - | - | -
dfdfdf | dfdfdfdfdf | - | - | -
who is this | me | - | - | -
dfdfdfdaaaaaaaaaaaaa | dd | - | - | -
3 changes: 3 additions & 0 deletions src/main/java/seedu/duke/Duke.java
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
//@@author wendelinwemhoener

package seedu.duke;

import seedu.duke.flashcard.Flashcard;
Expand All @@ -19,6 +21,7 @@ private void run() {
Scanner scanner = new Scanner(System.in);
String input;
boolean shouldTerminate = false;

while (!shouldTerminate) {
input = scanner.nextLine();

Expand Down
18 changes: 12 additions & 6 deletions src/main/java/seedu/duke/flashcard/Flashcard.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
//@@author wendelinwemhoener

package seedu.duke.flashcard;

import seedu.duke.flashcard.review.FlashcardReview;

import java.time.LocalDateTime;
import java.util.ArrayList;

Expand All @@ -8,7 +12,11 @@ public class Flashcard {
private String backText;
private ArrayList<String> tags;
private ArrayList<FlashcardReview> reviews;
private LocalDateTime nextReviewOn;
private LocalDateTime lastReviewOn;

public void setLastReviewOn(LocalDateTime lastReviewOn) {
this.lastReviewOn = lastReviewOn;
}

public Flashcard(String frontText, String backText) {
this.frontText = frontText;
Expand All @@ -17,7 +25,7 @@ public Flashcard(String frontText, String backText) {
tags = new ArrayList<>();
reviews = new ArrayList<>();

nextReviewOn = null;
lastReviewOn = null;
}

public String getFrontText() {
Expand All @@ -29,11 +37,9 @@ public String getBackText() {
}

public String toString() {
return "-".repeat(80) + System.lineSeparator()
+ "front text: " + frontText + System.lineSeparator()
return "front text: " + frontText + System.lineSeparator()
+ "back text: " + backText + System.lineSeparator()
+ "tags: " + tags.toString() + System.lineSeparator()
+ "next review due on: " + nextReviewOn + System.lineSeparator()
+ "-".repeat(80);
+ "next review due on: " + lastReviewOn + System.lineSeparator();
}
}
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
//@@author wendelinwemhoener

package seedu.duke.flashcard;

import seedu.duke.flashcard.command.FlashcardCommand;
Expand All @@ -8,11 +10,13 @@

public class FlashcardCommandParser {
public FlashcardCommand parseInput(String input) {
assert input != null : "input is null";

if (input.startsWith("create flashcard")) {
return new CreateFlashcardCommand();
} else if (input.startsWith("list flashcards")) {
return new ListFlashcardsCommand();
} else if (input.startsWith("start review")) {
} else if (input.startsWith("review flashcards")) {
return new StartReviewCommand();
}

Expand Down
13 changes: 11 additions & 2 deletions src/main/java/seedu/duke/flashcard/FlashcardComponent.java
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
//@@author wendelinwemhoener

package seedu.duke.flashcard;

import seedu.duke.flashcard.command.FlashcardCommand;
Expand All @@ -16,6 +18,8 @@ public class FlashcardComponent {

public FlashcardComponent(ArrayList<Flashcard> flashcards) {
parser = new FlashcardCommandParser();

//@@author junhyeong0411
storage = new FlashcardStorage("./flashcard.txt");
try {
flashcardList = storage.loadFlashcards();
Expand All @@ -25,9 +29,8 @@ public FlashcardComponent(ArrayList<Flashcard> flashcards) {
flashcardList = new FlashcardList(flashcards);
}


//@@author wendelinwemhoener
ui = new FlashcardUi(flashcardList);

}

public boolean isResponsible(String input) {
Expand All @@ -42,9 +45,15 @@ public boolean isResponsible(String input) {

public void processInput(String input) {
FlashcardCommand command = parser.parseInput(input);
assert !(command instanceof UnknownCommand) : "Command cannot be " +
"unknown";

ui.executeCommand(command);

//@@author junhyeong0411
// save after every commands
storage.saveFlashcards(flashcardList.getFlashcards());

//@@author wendelinwemhoener
}
}
8 changes: 0 additions & 8 deletions src/main/java/seedu/duke/flashcard/FlashcardDifficulty.java

This file was deleted.

2 changes: 2 additions & 0 deletions src/main/java/seedu/duke/flashcard/FlashcardList.java
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
//@@author wendelinwemhoener

package seedu.duke.flashcard;

import java.util.ArrayList;
Expand Down
13 changes: 0 additions & 13 deletions src/main/java/seedu/duke/flashcard/FlashcardReview.java

This file was deleted.

2 changes: 2 additions & 0 deletions src/main/java/seedu/duke/flashcard/FlashcardUi.java
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
//@@author wendelinwemhoener

package seedu.duke.flashcard;

import seedu.duke.flashcard.command.FlashcardCommand;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
//@@author wendelinwemhoener

package seedu.duke.flashcard.command;

import seedu.duke.flashcard.Flashcard;
Expand All @@ -15,5 +17,8 @@ public void execute(Scanner scanner, FlashcardList flashcardList) {
Flashcard flashcard = new Flashcard(frontPageText, backPageText);

flashcardList.add(flashcard);

System.out.println(" Success! Flashcard has been added to your " +
"collection.");
}
}
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
//@@author wendelinwemhoener

package seedu.duke.flashcard.command;

import seedu.duke.flashcard.FlashcardList;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
//@@author wendelinwemhoener

package seedu.duke.flashcard.command;

import seedu.duke.flashcard.Flashcard;
Expand All @@ -7,8 +9,12 @@

public class ListFlashcardsCommand extends FlashcardCommand {
public void execute(Scanner scanner, FlashcardList flashcardList) {
System.out.println(" Here is a list of all your flashcards: ");

System.out.println("-".repeat(80));
for (Flashcard flashcard : flashcardList.getFlashcards()) {
System.out.println(flashcard);
System.out.print(flashcard);
System.out.println("-".repeat(80));
}
}
}
Original file line number Diff line number Diff line change
@@ -1,11 +1,63 @@
//@@author wendelinwemhoener

package seedu.duke.flashcard.command;

import seedu.duke.flashcard.FlashcardList;
import seedu.duke.flashcard.review.FlashcardReview;
import seedu.duke.flashcard.review.RandomReviewMode;
import seedu.duke.flashcard.review.ReviewByTagMode;
import seedu.duke.flashcard.review.ReviewMode;
import seedu.duke.flashcard.review.SpacedRepetitionReviewMode;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.Scanner;

public class StartReviewCommand extends FlashcardCommand {
private final ArrayList<String> choices = new ArrayList<>(Arrays.asList(
"a", "b", "c"));

private String getUserChoiceReviewMode(Scanner scanner) {
System.out.println(" How do you want to review your flashcards?");
System.out.println(" a) random mode");
System.out.println(" b) spaced repetition mode");
System.out.println(" c) review by tag mode");

return scanner.nextLine();
}

public void execute(Scanner scanner, FlashcardList flashcardList) {
System.out.println("");
String choice = getUserChoiceReviewMode(scanner);

if (!choices.contains(choice)) {
System.out.println(" Invalid choice! Your choice must be a, b " +
"or c!");
return;
}

ReviewMode reviewMode = createReviewMode(choice, flashcardList);

if (reviewMode instanceof RandomReviewMode) {
reviewMode.startReviewSession(scanner);
} else {
System.out.println("This review mode hasn't yet been implemented." +
" Sorry!");
}
}

private ReviewMode createReviewMode(String choice, FlashcardList flashcardList) {
ReviewMode reviewMode = null;

if (choice.equals("a")) {
reviewMode = new RandomReviewMode(flashcardList);
} else if (choice.equals("b")) {
reviewMode = new SpacedRepetitionReviewMode(flashcardList);
} else if (choice.equals("c")) {
reviewMode = new ReviewByTagMode(flashcardList);
}

assert reviewMode != null;

return reviewMode;
}
}
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
//@@author wendelinwemhoener

package seedu.duke.flashcard.command;

import seedu.duke.flashcard.FlashcardList;
Expand Down
15 changes: 15 additions & 0 deletions src/main/java/seedu/duke/flashcard/review/FlashcardReview.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
//@@author wendelinwemhoener

package seedu.duke.flashcard.review;

import java.time.LocalDateTime;

public class FlashcardReview {
private LocalDateTime reviewDate;
private ReviewDifficulty reviewDifficulty;

public FlashcardReview(LocalDateTime reviewDate, ReviewDifficulty reviewDifficulty) {
this.reviewDate = reviewDate;
this.reviewDifficulty = reviewDifficulty;
}
}
26 changes: 26 additions & 0 deletions src/main/java/seedu/duke/flashcard/review/RandomReviewMode.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
//@@author wendelinwemhoener

package seedu.duke.flashcard.review;

import seedu.duke.flashcard.Flashcard;
import seedu.duke.flashcard.FlashcardList;

import java.util.ArrayList;
import java.util.Random;

public class RandomReviewMode extends ReviewMode {
public RandomReviewMode(FlashcardList flashcardList) {
super(flashcardList);
}

public String getReviewModeName() {
return "random review mode";
}

protected Flashcard pickFlashcard() {
ArrayList<Flashcard> flashcards = flashcardList.getFlashcards();
Random random = new Random();

return flashcards.get(random.nextInt(flashcards.size()));
}
}
18 changes: 18 additions & 0 deletions src/main/java/seedu/duke/flashcard/review/ReviewByTagMode.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
package seedu.duke.flashcard.review;

import seedu.duke.flashcard.Flashcard;
import seedu.duke.flashcard.FlashcardList;

public class ReviewByTagMode extends ReviewMode {
public ReviewByTagMode(FlashcardList flashcardList) {
super(flashcardList);
}

public String getReviewModeName() {
return "review by tag mode";
}

protected Flashcard pickFlashcard() {
return null;
}
}
10 changes: 10 additions & 0 deletions src/main/java/seedu/duke/flashcard/review/ReviewDifficulty.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
//@@author wendelinwemhoener

package seedu.duke.flashcard.review;

public enum ReviewDifficulty {
EASY,
GOOD,
HARD,
AGAIN
}
Loading

0 comments on commit 1793052

Please sign in to comment.