File tree Expand file tree Collapse file tree 7 files changed +53
-29
lines changed
src/main/java/seedu/duke/flashcard Expand file tree Collapse file tree 7 files changed +53
-29
lines changed Original file line number Diff line number Diff line change 1
1
package seedu .duke .flashcard ;
2
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 ;
3
+ import seedu .duke .flashcard .command .*;
7
4
8
5
public class FlashcardCommandParser {
9
6
public FlashcardCommand parseInput (String input ) {
10
7
if (input .startsWith ("create flashcard" )) {
11
8
return new CreateFlashcardCommand ();
12
9
} else if (input .startsWith ("list flashcards" )) {
13
10
return new ListFlashcardsCommand ();
11
+ } else if (input .startsWith ("start review" )) {
12
+ return new StartReviewCommand ();
14
13
}
15
14
16
15
return new UnknownCommand ();
Original file line number Diff line number Diff line change 1
1
package seedu .duke .flashcard ;
2
2
3
- import seedu .duke .flashcard .command .CreateFlashcardCommand ;
4
3
import seedu .duke .flashcard .command .FlashcardCommand ;
5
- import seedu .duke .flashcard .command .ListFlashcardsCommand ;
6
4
7
5
import java .util .Scanner ;
8
6
@@ -16,27 +14,6 @@ public FlashcardUi(FlashcardList flashcardList) {
16
14
}
17
15
18
16
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
- }
17
+ command .execute (scanner , flashcardList );
41
18
}
42
19
}
Original file line number Diff line number Diff line change 1
1
package seedu .duke .flashcard .command ;
2
2
3
+ import seedu .duke .flashcard .Flashcard ;
4
+ import seedu .duke .flashcard .FlashcardList ;
5
+
6
+ import java .util .Scanner ;
7
+
3
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
+ }
4
19
}
Original file line number Diff line number Diff line change 1
1
package seedu .duke .flashcard .command ;
2
2
3
- public class FlashcardCommand {
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 );
4
9
}
Original file line number Diff line number Diff line change 1
1
package seedu .duke .flashcard .command ;
2
2
3
+ import seedu .duke .flashcard .Flashcard ;
4
+ import seedu .duke .flashcard .FlashcardList ;
5
+
6
+ import java .util .Scanner ;
7
+
3
8
public class ListFlashcardsCommand extends FlashcardCommand {
9
+ public void execute (Scanner scanner , FlashcardList flashcardList ) {
10
+ for (Flashcard flashcard : flashcardList .getFlashcards ()) {
11
+ System .out .println (flashcard );
12
+ }
13
+ }
4
14
}
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 class StartReviewCommand extends FlashcardCommand {
8
+ public void execute (Scanner scanner , FlashcardList flashcardList ) {
9
+ System .out .println ("" );
10
+ }
11
+ }
Original file line number Diff line number Diff line change 1
1
package seedu .duke .flashcard .command ;
2
2
3
+ import seedu .duke .flashcard .FlashcardList ;
4
+
5
+ import java .util .Scanner ;
6
+
3
7
public class UnknownCommand extends FlashcardCommand {
8
+ public void execute (Scanner scanner , FlashcardList flashcardList ) {
9
+ System .out .println ("Unknown command! Please try again." );
10
+ }
4
11
}
You can’t perform that action at this time.
0 commit comments