diff --git a/src/main/java/seedu/duke/Duke.java b/src/main/java/seedu/duke/Duke.java index 5c74e68d59..f3c228c558 100644 --- a/src/main/java/seedu/duke/Duke.java +++ b/src/main/java/seedu/duke/Duke.java @@ -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()); + + Scanner scanner = new Scanner(System.in); + String input; + boolean shouldTerminate = false; + + while (!shouldTerminate) { + input = scanner.nextLine(); + + if (fc.isResponsible(input)) { + fc.processInput(input); + } + } + } } diff --git a/src/main/java/seedu/duke/flashcard/Flashcard.java b/src/main/java/seedu/duke/flashcard/Flashcard.java new file mode 100644 index 0000000000..240e9bf2ae --- /dev/null +++ b/src/main/java/seedu/duke/flashcard/Flashcard.java @@ -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 tags; + private ArrayList 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); + } +} diff --git a/src/main/java/seedu/duke/flashcard/FlashcardCommandParser.java b/src/main/java/seedu/duke/flashcard/FlashcardCommandParser.java new file mode 100644 index 0000000000..d71d62a9cf --- /dev/null +++ b/src/main/java/seedu/duke/flashcard/FlashcardCommandParser.java @@ -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(); + } +} diff --git a/src/main/java/seedu/duke/flashcard/FlashcardComponent.java b/src/main/java/seedu/duke/flashcard/FlashcardComponent.java new file mode 100644 index 0000000000..ed9b03ff34 --- /dev/null +++ b/src/main/java/seedu/duke/flashcard/FlashcardComponent.java @@ -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 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); + } +} diff --git a/src/main/java/seedu/duke/flashcard/FlashcardDifficulty.java b/src/main/java/seedu/duke/flashcard/FlashcardDifficulty.java new file mode 100644 index 0000000000..6737254840 --- /dev/null +++ b/src/main/java/seedu/duke/flashcard/FlashcardDifficulty.java @@ -0,0 +1,8 @@ +package seedu.duke.flashcard; + +public enum FlashcardDifficulty { + EASY, + GOOD, + HARD, + AGAIN +} diff --git a/src/main/java/seedu/duke/flashcard/FlashcardList.java b/src/main/java/seedu/duke/flashcard/FlashcardList.java new file mode 100644 index 0000000000..bc614f19ff --- /dev/null +++ b/src/main/java/seedu/duke/flashcard/FlashcardList.java @@ -0,0 +1,19 @@ +package seedu.duke.flashcard; + +import java.util.ArrayList; + +public class FlashcardList { + private ArrayList flashcards; + + public FlashcardList(ArrayList flashcards) { + this.flashcards = flashcards; + } + + public ArrayList getFlashcards() { + return flashcards; + } + + public void add(Flashcard flashcard) { + flashcards.add(flashcard); + } +} diff --git a/src/main/java/seedu/duke/flashcard/FlashcardReview.java b/src/main/java/seedu/duke/flashcard/FlashcardReview.java new file mode 100644 index 0000000000..f904f267af --- /dev/null +++ b/src/main/java/seedu/duke/flashcard/FlashcardReview.java @@ -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; + } +} diff --git a/src/main/java/seedu/duke/flashcard/FlashcardUi.java b/src/main/java/seedu/duke/flashcard/FlashcardUi.java new file mode 100644 index 0000000000..9da700b750 --- /dev/null +++ b/src/main/java/seedu/duke/flashcard/FlashcardUi.java @@ -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); + } +} diff --git a/src/main/java/seedu/duke/flashcard/command/CreateFlashcardCommand.java b/src/main/java/seedu/duke/flashcard/command/CreateFlashcardCommand.java new file mode 100644 index 0000000000..2b08632b13 --- /dev/null +++ b/src/main/java/seedu/duke/flashcard/command/CreateFlashcardCommand.java @@ -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); + } +} diff --git a/src/main/java/seedu/duke/flashcard/command/FlashcardCommand.java b/src/main/java/seedu/duke/flashcard/command/FlashcardCommand.java new file mode 100644 index 0000000000..60702de680 --- /dev/null +++ b/src/main/java/seedu/duke/flashcard/command/FlashcardCommand.java @@ -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); +} diff --git a/src/main/java/seedu/duke/flashcard/command/ListFlashcardsCommand.java b/src/main/java/seedu/duke/flashcard/command/ListFlashcardsCommand.java new file mode 100644 index 0000000000..67a0b6f044 --- /dev/null +++ b/src/main/java/seedu/duke/flashcard/command/ListFlashcardsCommand.java @@ -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); + } + } +} diff --git a/src/main/java/seedu/duke/flashcard/command/StartReviewCommand.java b/src/main/java/seedu/duke/flashcard/command/StartReviewCommand.java new file mode 100644 index 0000000000..e80a62a850 --- /dev/null +++ b/src/main/java/seedu/duke/flashcard/command/StartReviewCommand.java @@ -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(""); + } +} diff --git a/src/main/java/seedu/duke/flashcard/command/UnknownCommand.java b/src/main/java/seedu/duke/flashcard/command/UnknownCommand.java new file mode 100644 index 0000000000..aacfffa67b --- /dev/null +++ b/src/main/java/seedu/duke/flashcard/command/UnknownCommand.java @@ -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."); + } +}