Skip to content

Commit e71b620

Browse files
Start implementing flashcard functionality
1 parent 7f101cf commit e71b620

12 files changed

+207
-13
lines changed

src/main/java/seedu/duke/Duke.java

Lines changed: 26 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,34 @@
11
package seedu.duke;
22

3+
import seedu.duke.flashcard.Flashcard;
4+
import seedu.duke.flashcard.FlashcardCommandParser;
5+
import seedu.duke.flashcard.FlashcardComponent;
6+
import seedu.duke.flashcard.FlashcardList;
7+
8+
import java.util.ArrayList;
39
import java.util.Scanner;
410

511
public class Duke {
6-
/**
7-
* Main entry-point for the java.duke.Duke application.
8-
*/
12+
public Duke() {}
13+
914
public static void main(String[] args) {
10-
String logo = " ____ _ \n"
11-
+ "| _ \\ _ _| | _____ \n"
12-
+ "| | | | | | | |/ / _ \\\n"
13-
+ "| |_| | |_| | < __/\n"
14-
+ "|____/ \\__,_|_|\\_\\___|\n";
15-
System.out.println("Hello from\n" + logo);
16-
System.out.println("What is your name?");
17-
18-
Scanner in = new Scanner(System.in);
19-
System.out.println("Hello " + in.nextLine());
15+
new Duke().run();
16+
}
17+
18+
private void run() {
19+
FlashcardComponent fc = new FlashcardComponent(new ArrayList<Flashcard>());
20+
21+
Scanner scanner = new Scanner(System.in);
22+
String input;
23+
boolean shouldTerminate = false;
24+
25+
while (!shouldTerminate) {
26+
input = scanner.nextLine();
27+
28+
if (fc.isResponsible(input)) {
29+
fc.processInput(input);
30+
}
31+
}
32+
2033
}
2134
}
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
package seedu.duke.flashcard;
2+
3+
import java.time.LocalDateTime;
4+
import java.util.ArrayList;
5+
import java.util.Arrays;
6+
7+
public class Flashcard {
8+
private String frontText;
9+
private String backText;
10+
private ArrayList<String> tags;
11+
private ArrayList<FlashcardReview> reviews;
12+
private LocalDateTime nextReviewOn;
13+
14+
public Flashcard(String frontText, String backText) {
15+
this.frontText = frontText;
16+
this.backText = backText;
17+
18+
tags = new ArrayList<>();
19+
reviews = new ArrayList<>();
20+
21+
nextReviewOn = null;
22+
}
23+
24+
public String toString() {
25+
return "-".repeat(80) + System.lineSeparator()
26+
+ "front text: " + frontText + System.lineSeparator()
27+
+ "back text: " + backText + System.lineSeparator()
28+
+ "tags: " + tags.toString() + System.lineSeparator()
29+
+ "next review due on: " + nextReviewOn + System.lineSeparator()
30+
+ "-".repeat(80);
31+
}
32+
}
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
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+
import seedu.duke.flashcard.command.UnknownCommand;
7+
8+
public class FlashcardCommandParser {
9+
public FlashcardCommand parseInput(String input) {
10+
if (input.startsWith("create flashcard")) {
11+
return new CreateFlashcardCommand();
12+
} else if (input.startsWith("list flashcards")) {
13+
return new ListFlashcardsCommand();
14+
}
15+
16+
return new UnknownCommand();
17+
}
18+
}
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
package seedu.duke.flashcard;
2+
3+
import seedu.duke.flashcard.command.FlashcardCommand;
4+
import seedu.duke.flashcard.command.UnknownCommand;
5+
6+
import java.util.ArrayList;
7+
8+
public class FlashcardComponent {
9+
private FlashcardCommandParser parser;
10+
private FlashcardList flashcardList;
11+
private FlashcardUi ui;
12+
13+
public FlashcardComponent(ArrayList<Flashcard> flashcards) {
14+
parser = new FlashcardCommandParser();
15+
flashcardList = new FlashcardList(flashcards);
16+
ui = new FlashcardUi(flashcardList);
17+
}
18+
19+
public boolean isResponsible(String input) {
20+
FlashcardCommand command = parser.parseInput(input);
21+
22+
if (command instanceof UnknownCommand) {
23+
return false;
24+
} else {
25+
return true;
26+
}
27+
}
28+
29+
public void processInput(String input) {
30+
FlashcardCommand command = parser.parseInput(input);
31+
ui.executeCommand(command);
32+
}
33+
}
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
package seedu.duke.flashcard;
2+
3+
public enum FlashcardDifficulty {
4+
EASY,
5+
GOOD,
6+
HARD,
7+
AGAIN
8+
}
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
package seedu.duke.flashcard;
2+
3+
import java.util.ArrayList;
4+
5+
public class FlashcardList {
6+
private ArrayList<Flashcard> flashcards;
7+
8+
public FlashcardList(ArrayList<Flashcard> flashcards) {
9+
this.flashcards = flashcards;
10+
}
11+
12+
public ArrayList<Flashcard> getFlashcards() {
13+
return flashcards;
14+
}
15+
16+
public void add(Flashcard flashcard) {
17+
flashcards.add(flashcard);
18+
}
19+
}
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
package seedu.duke.flashcard;
2+
3+
import java.time.LocalDateTime;
4+
5+
public class FlashcardReview {
6+
private LocalDateTime reviewDate;
7+
private FlashcardDifficulty reviewDifficulty;
8+
9+
public FlashcardReview(LocalDateTime reviewDate, FlashcardDifficulty reviewDifficulty) {
10+
this.reviewDate = reviewDate;
11+
this.reviewDifficulty = reviewDifficulty;
12+
}
13+
}
Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
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+
}
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
package seedu.duke.flashcard.command;
2+
3+
public class CreateFlashcardCommand extends FlashcardCommand {
4+
}
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
package seedu.duke.flashcard.command;
2+
3+
public class FlashcardCommand {
4+
}

0 commit comments

Comments
 (0)