|
| 1 | +package seedu.duke.flashcard; |
| 2 | + |
| 3 | +import seedu.duke.flashcard.command.CreateFlashcardCommand; |
| 4 | +import seedu.duke.flashcard.command.FlashcardCommand; |
| 5 | +import seedu.duke.flashcard.command.ListFlashcardsCommand; |
| 6 | + |
| 7 | +import java.util.Scanner; |
| 8 | + |
| 9 | +public class FlashcardUi { |
| 10 | + private Scanner scanner; |
| 11 | + private FlashcardList flashcardList; |
| 12 | + |
| 13 | + public FlashcardUi(FlashcardList flashcardList) { |
| 14 | + scanner = new Scanner(System.in); |
| 15 | + this.flashcardList = flashcardList; |
| 16 | + } |
| 17 | + |
| 18 | + public void executeCommand(FlashcardCommand command) { |
| 19 | + if (command instanceof CreateFlashcardCommand) { |
| 20 | + executeCreateFlashcardCommand(); |
| 21 | + } else if (command instanceof ListFlashcardsCommand) { |
| 22 | + listFlashcards(); |
| 23 | + } |
| 24 | + } |
| 25 | + |
| 26 | + private void executeCreateFlashcardCommand() { |
| 27 | + System.out.print("Enter the front page text: "); |
| 28 | + String frontPageText = scanner.nextLine(); |
| 29 | + System.out.print("Enter the back page text: "); |
| 30 | + String backPageText = scanner.nextLine(); |
| 31 | + |
| 32 | + Flashcard flashcard = new Flashcard(frontPageText, backPageText); |
| 33 | + |
| 34 | + flashcardList.add(flashcard); |
| 35 | + } |
| 36 | + |
| 37 | + public void listFlashcards() { |
| 38 | + for (Flashcard flashcard : flashcardList.getFlashcards()) { |
| 39 | + System.out.println(flashcard); |
| 40 | + } |
| 41 | + } |
| 42 | +} |
0 commit comments