File tree Expand file tree Collapse file tree 13 files changed +232
-13
lines changed Expand file tree Collapse file tree 13 files changed +232
-13
lines changed Original file line number Diff line number Diff line change 1
1
package seedu .duke ;
2
2
3
+ import seedu .duke .flashcard .Flashcard ;
4
+ import seedu .duke .flashcard .FlashcardComponent ;
5
+
6
+ import java .util .ArrayList ;
3
7
import java .util .Scanner ;
4
8
5
9
public class Duke {
6
- /**
7
- * Main entry-point for the java.duke.Duke application.
8
- */
10
+ public Duke () {}
11
+
9
12
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 ());
13
+ new Duke ().run ();
14
+ }
15
+
16
+ private void run () {
17
+ FlashcardComponent fc = new FlashcardComponent (new ArrayList <Flashcard >());
18
+
19
+ Scanner scanner = new Scanner (System .in );
20
+ String input ;
21
+ boolean shouldTerminate = false ;
22
+
23
+ while (!shouldTerminate ) {
24
+ input = scanner .nextLine ();
25
+
26
+ if (fc .isResponsible (input )) {
27
+ fc .processInput (input );
28
+ }
29
+ }
30
+
20
31
}
21
32
}
Original file line number Diff line number Diff line change
1
+ package seedu .duke .flashcard ;
2
+
3
+ import java .time .LocalDateTime ;
4
+ import java .util .ArrayList ;
5
+
6
+ public class Flashcard {
7
+ private String frontText ;
8
+ private String backText ;
9
+ private ArrayList <String > tags ;
10
+ private ArrayList <FlashcardReview > reviews ;
11
+ private LocalDateTime nextReviewOn ;
12
+
13
+ public Flashcard (String frontText , String backText ) {
14
+ this .frontText = frontText ;
15
+ this .backText = backText ;
16
+
17
+ tags = new ArrayList <>();
18
+ reviews = new ArrayList <>();
19
+
20
+ nextReviewOn = null ;
21
+ }
22
+
23
+ public String toString () {
24
+ return "-" .repeat (80 ) + System .lineSeparator ()
25
+ + "front text: " + frontText + System .lineSeparator ()
26
+ + "back text: " + backText + System .lineSeparator ()
27
+ + "tags: " + tags .toString () + System .lineSeparator ()
28
+ + "next review due on: " + nextReviewOn + System .lineSeparator ()
29
+ + "-" .repeat (80 );
30
+ }
31
+ }
Original file line number Diff line number Diff line change
1
+ package seedu .duke .flashcard ;
2
+
3
+ import seedu .duke .flashcard .command .FlashcardCommand ;
4
+ import seedu .duke .flashcard .command .CreateFlashcardCommand ;
5
+ import seedu .duke .flashcard .command .ListFlashcardsCommand ;
6
+ import seedu .duke .flashcard .command .StartReviewCommand ;
7
+ import seedu .duke .flashcard .command .UnknownCommand ;
8
+
9
+ public class FlashcardCommandParser {
10
+ public FlashcardCommand parseInput (String input ) {
11
+ if (input .startsWith ("create flashcard" )) {
12
+ return new CreateFlashcardCommand ();
13
+ } else if (input .startsWith ("list flashcards" )) {
14
+ return new ListFlashcardsCommand ();
15
+ } else if (input .startsWith ("start review" )) {
16
+ return new StartReviewCommand ();
17
+ }
18
+
19
+ return new UnknownCommand ();
20
+ }
21
+ }
Original file line number Diff line number Diff line change
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
+ }
Original file line number Diff line number Diff line change
1
+ package seedu .duke .flashcard ;
2
+
3
+ public enum FlashcardDifficulty {
4
+ EASY ,
5
+ GOOD ,
6
+ HARD ,
7
+ AGAIN
8
+ }
Original file line number Diff line number Diff line change
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
+ }
Original file line number Diff line number Diff line change
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
+ }
Original file line number Diff line number Diff line change
1
+ package seedu .duke .flashcard ;
2
+
3
+ import seedu .duke .flashcard .command .FlashcardCommand ;
4
+
5
+ import java .util .Scanner ;
6
+
7
+ public class FlashcardUi {
8
+ private Scanner scanner ;
9
+ private FlashcardList flashcardList ;
10
+
11
+ public FlashcardUi (FlashcardList flashcardList ) {
12
+ scanner = new Scanner (System .in );
13
+ this .flashcardList = flashcardList ;
14
+ }
15
+
16
+ public void executeCommand (FlashcardCommand command ) {
17
+ command .execute (scanner , flashcardList );
18
+ }
19
+ }
Original file line number Diff line number Diff line change
1
+ package seedu .duke .flashcard .command ;
2
+
3
+ import seedu .duke .flashcard .Flashcard ;
4
+ import seedu .duke .flashcard .FlashcardList ;
5
+
6
+ import java .util .Scanner ;
7
+
8
+ public class CreateFlashcardCommand extends FlashcardCommand {
9
+ public void execute (Scanner scanner , FlashcardList flashcardList ) {
10
+ System .out .print ("Enter the front page text: " );
11
+ String frontPageText = scanner .nextLine ();
12
+ System .out .print ("Enter the back page text: " );
13
+ String backPageText = scanner .nextLine ();
14
+
15
+ Flashcard flashcard = new Flashcard (frontPageText , backPageText );
16
+
17
+ flashcardList .add (flashcard );
18
+ }
19
+ }
Original file line number Diff line number Diff line change
1
+ package seedu .duke .flashcard .command ;
2
+
3
+ import seedu .duke .flashcard .FlashcardList ;
4
+
5
+ import java .util .Scanner ;
6
+
7
+ public abstract class FlashcardCommand {
8
+ public abstract void execute (Scanner scanner , FlashcardList flashcardList );
9
+ }
You can’t perform that action at this time.
0 commit comments