forked from nus-cs2113-AY2324S1/tp
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request nus-cs2113-AY2324S1#5 from wendelinwemhoener/add-f…
…lashcard-support Add flashcard support
- Loading branch information
Showing
13 changed files
with
232 additions
and
13 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,21 +1,32 @@ | ||
package seedu.duke; | ||
|
||
import seedu.duke.flashcard.Flashcard; | ||
import seedu.duke.flashcard.FlashcardComponent; | ||
|
||
import java.util.ArrayList; | ||
import java.util.Scanner; | ||
|
||
public class Duke { | ||
/** | ||
* Main entry-point for the java.duke.Duke application. | ||
*/ | ||
public Duke() {} | ||
|
||
public static void main(String[] args) { | ||
String logo = " ____ _ \n" | ||
+ "| _ \\ _ _| | _____ \n" | ||
+ "| | | | | | | |/ / _ \\\n" | ||
+ "| |_| | |_| | < __/\n" | ||
+ "|____/ \\__,_|_|\\_\\___|\n"; | ||
System.out.println("Hello from\n" + logo); | ||
System.out.println("What is your name?"); | ||
|
||
Scanner in = new Scanner(System.in); | ||
System.out.println("Hello " + in.nextLine()); | ||
new Duke().run(); | ||
} | ||
|
||
private void run() { | ||
FlashcardComponent fc = new FlashcardComponent(new ArrayList<Flashcard>()); | ||
|
||
Scanner scanner = new Scanner(System.in); | ||
String input; | ||
boolean shouldTerminate = false; | ||
|
||
while (!shouldTerminate) { | ||
input = scanner.nextLine(); | ||
|
||
if (fc.isResponsible(input)) { | ||
fc.processInput(input); | ||
} | ||
} | ||
|
||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
package seedu.duke.flashcard; | ||
|
||
import java.time.LocalDateTime; | ||
import java.util.ArrayList; | ||
|
||
public class Flashcard { | ||
private String frontText; | ||
private String backText; | ||
private ArrayList<String> tags; | ||
private ArrayList<FlashcardReview> reviews; | ||
private LocalDateTime nextReviewOn; | ||
|
||
public Flashcard(String frontText, String backText) { | ||
this.frontText = frontText; | ||
this.backText = backText; | ||
|
||
tags = new ArrayList<>(); | ||
reviews = new ArrayList<>(); | ||
|
||
nextReviewOn = null; | ||
} | ||
|
||
public String toString() { | ||
return "-".repeat(80) + System.lineSeparator() | ||
+ "front text: " + frontText + System.lineSeparator() | ||
+ "back text: " + backText + System.lineSeparator() | ||
+ "tags: " + tags.toString() + System.lineSeparator() | ||
+ "next review due on: " + nextReviewOn + System.lineSeparator() | ||
+ "-".repeat(80); | ||
} | ||
} |
21 changes: 21 additions & 0 deletions
21
src/main/java/seedu/duke/flashcard/FlashcardCommandParser.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
package seedu.duke.flashcard; | ||
|
||
import seedu.duke.flashcard.command.FlashcardCommand; | ||
import seedu.duke.flashcard.command.CreateFlashcardCommand; | ||
import seedu.duke.flashcard.command.ListFlashcardsCommand; | ||
import seedu.duke.flashcard.command.StartReviewCommand; | ||
import seedu.duke.flashcard.command.UnknownCommand; | ||
|
||
public class FlashcardCommandParser { | ||
public FlashcardCommand parseInput(String input) { | ||
if (input.startsWith("create flashcard")) { | ||
return new CreateFlashcardCommand(); | ||
} else if (input.startsWith("list flashcards")) { | ||
return new ListFlashcardsCommand(); | ||
} else if (input.startsWith("start review")) { | ||
return new StartReviewCommand(); | ||
} | ||
|
||
return new UnknownCommand(); | ||
} | ||
} |
33 changes: 33 additions & 0 deletions
33
src/main/java/seedu/duke/flashcard/FlashcardComponent.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
package seedu.duke.flashcard; | ||
|
||
import seedu.duke.flashcard.command.FlashcardCommand; | ||
import seedu.duke.flashcard.command.UnknownCommand; | ||
|
||
import java.util.ArrayList; | ||
|
||
public class FlashcardComponent { | ||
private FlashcardCommandParser parser; | ||
private FlashcardList flashcardList; | ||
private FlashcardUi ui; | ||
|
||
public FlashcardComponent(ArrayList<Flashcard> flashcards) { | ||
parser = new FlashcardCommandParser(); | ||
flashcardList = new FlashcardList(flashcards); | ||
ui = new FlashcardUi(flashcardList); | ||
} | ||
|
||
public boolean isResponsible(String input) { | ||
FlashcardCommand command = parser.parseInput(input); | ||
|
||
if (command instanceof UnknownCommand) { | ||
return false; | ||
} else { | ||
return true; | ||
} | ||
} | ||
|
||
public void processInput(String input) { | ||
FlashcardCommand command = parser.parseInput(input); | ||
ui.executeCommand(command); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
package seedu.duke.flashcard; | ||
|
||
public enum FlashcardDifficulty { | ||
EASY, | ||
GOOD, | ||
HARD, | ||
AGAIN | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
package seedu.duke.flashcard; | ||
|
||
import java.util.ArrayList; | ||
|
||
public class FlashcardList { | ||
private ArrayList<Flashcard> flashcards; | ||
|
||
public FlashcardList(ArrayList<Flashcard> flashcards) { | ||
this.flashcards = flashcards; | ||
} | ||
|
||
public ArrayList<Flashcard> getFlashcards() { | ||
return flashcards; | ||
} | ||
|
||
public void add(Flashcard flashcard) { | ||
flashcards.add(flashcard); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
package seedu.duke.flashcard; | ||
|
||
import java.time.LocalDateTime; | ||
|
||
public class FlashcardReview { | ||
private LocalDateTime reviewDate; | ||
private FlashcardDifficulty reviewDifficulty; | ||
|
||
public FlashcardReview(LocalDateTime reviewDate, FlashcardDifficulty reviewDifficulty) { | ||
this.reviewDate = reviewDate; | ||
this.reviewDifficulty = reviewDifficulty; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
package seedu.duke.flashcard; | ||
|
||
import seedu.duke.flashcard.command.FlashcardCommand; | ||
|
||
import java.util.Scanner; | ||
|
||
public class FlashcardUi { | ||
private Scanner scanner; | ||
private FlashcardList flashcardList; | ||
|
||
public FlashcardUi(FlashcardList flashcardList) { | ||
scanner = new Scanner(System.in); | ||
this.flashcardList = flashcardList; | ||
} | ||
|
||
public void executeCommand(FlashcardCommand command) { | ||
command.execute(scanner, flashcardList); | ||
} | ||
} |
19 changes: 19 additions & 0 deletions
19
src/main/java/seedu/duke/flashcard/command/CreateFlashcardCommand.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
package seedu.duke.flashcard.command; | ||
|
||
import seedu.duke.flashcard.Flashcard; | ||
import seedu.duke.flashcard.FlashcardList; | ||
|
||
import java.util.Scanner; | ||
|
||
public class CreateFlashcardCommand extends FlashcardCommand { | ||
public void execute(Scanner scanner, FlashcardList flashcardList) { | ||
System.out.print("Enter the front page text: "); | ||
String frontPageText = scanner.nextLine(); | ||
System.out.print("Enter the back page text: "); | ||
String backPageText = scanner.nextLine(); | ||
|
||
Flashcard flashcard = new Flashcard(frontPageText, backPageText); | ||
|
||
flashcardList.add(flashcard); | ||
} | ||
} |
9 changes: 9 additions & 0 deletions
9
src/main/java/seedu/duke/flashcard/command/FlashcardCommand.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
package seedu.duke.flashcard.command; | ||
|
||
import seedu.duke.flashcard.FlashcardList; | ||
|
||
import java.util.Scanner; | ||
|
||
public abstract class FlashcardCommand { | ||
public abstract void execute(Scanner scanner, FlashcardList flashcardList); | ||
} |
14 changes: 14 additions & 0 deletions
14
src/main/java/seedu/duke/flashcard/command/ListFlashcardsCommand.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
package seedu.duke.flashcard.command; | ||
|
||
import seedu.duke.flashcard.Flashcard; | ||
import seedu.duke.flashcard.FlashcardList; | ||
|
||
import java.util.Scanner; | ||
|
||
public class ListFlashcardsCommand extends FlashcardCommand { | ||
public void execute(Scanner scanner, FlashcardList flashcardList) { | ||
for (Flashcard flashcard : flashcardList.getFlashcards()) { | ||
System.out.println(flashcard); | ||
} | ||
} | ||
} |
11 changes: 11 additions & 0 deletions
11
src/main/java/seedu/duke/flashcard/command/StartReviewCommand.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
package seedu.duke.flashcard.command; | ||
|
||
import seedu.duke.flashcard.FlashcardList; | ||
|
||
import java.util.Scanner; | ||
|
||
public class StartReviewCommand extends FlashcardCommand { | ||
public void execute(Scanner scanner, FlashcardList flashcardList) { | ||
System.out.println(""); | ||
} | ||
} |
11 changes: 11 additions & 0 deletions
11
src/main/java/seedu/duke/flashcard/command/UnknownCommand.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
package seedu.duke.flashcard.command; | ||
|
||
import seedu.duke.flashcard.FlashcardList; | ||
|
||
import java.util.Scanner; | ||
|
||
public class UnknownCommand extends FlashcardCommand { | ||
public void execute(Scanner scanner, FlashcardList flashcardList) { | ||
System.out.println("Unknown command! Please try again."); | ||
} | ||
} |