Skip to content

Commit f3d5405

Browse files
authored
Merge pull request nus-cs2113-AY2324S1#27 from Brian030601/master
Connect Calendar with Duke
2 parents 01c8382 + 9b9db6b commit f3d5405

File tree

6 files changed

+70
-8
lines changed

6 files changed

+70
-8
lines changed

data/flashcard.txt

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,3 +2,6 @@ d | a | - | - | -
22
dfdf | dfdf | - | - | -
33
dfdf | asdfdf | - | - | -
44
ddf | dfdf | - | - | -
5+
hello | bye | - | - | -
6+
hello | bye | - | - | -
7+
end program | hello | - | - | -

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

Lines changed: 48 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@
44

55
import seedu.duke.flashcard.Flashcard;
66
import seedu.duke.flashcard.FlashcardComponent;
7+
import seedu.duke.calendar.Event;
8+
import seedu.duke.calendar.CalendarManager;
79

810
import java.util.ArrayList;
911
import java.util.Scanner;
@@ -15,7 +17,36 @@ public static void main(String[] args) {
1517
new Duke().run();
1618
}
1719

18-
private void run() {
20+
private void runCalendar() {
21+
System.out.print("Enter your command: ");
22+
23+
CalendarManager manager = new CalendarManager();
24+
25+
Scanner scanner = new Scanner(System.in);
26+
String input;
27+
boolean isDone = false;
28+
29+
while (!isDone) {
30+
input = scanner.nextLine();
31+
32+
if (input.equals("end program")) {
33+
System.out.println("Bye bye");
34+
break;
35+
} else if (input.equals("flashcard")) {
36+
runFlashcard();
37+
} else if (manager.validCommand(input)) {
38+
manager.startCalendar(input);
39+
} else {
40+
System.out.println("Invalid command! Enter a valid command.");
41+
}
42+
43+
}
44+
45+
}
46+
47+
private void runFlashcard() {
48+
System.out.print("Enter your command: ");
49+
1950
FlashcardComponent fc = new FlashcardComponent(new ArrayList<Flashcard>());
2051

2152
Scanner scanner = new Scanner(System.in);
@@ -31,6 +62,22 @@ private void run() {
3162
System.out.println(" Invalid command! Sorry; please try again.");
3263
}
3364
}
65+
}
3466

67+
private void run() {
68+
String flashcardOrCalendar;
69+
Scanner scanner = new Scanner(System.in);
70+
71+
System.out.print("Do you choose flashcard or calendar? ");
72+
flashcardOrCalendar = scanner.nextLine();
73+
74+
if (flashcardOrCalendar.equals("flashcard")) {
75+
runFlashcard();
76+
} else if (flashcardOrCalendar.equals("calendar")) {
77+
runCalendar();
78+
} else {
79+
System.out.println("Invalid command! Sorry; please try again.");
80+
run();
81+
}
3582
}
3683
}

src/main/java/seedu/duke/calendar/Calendar.java

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,6 @@
22

33
package seedu.duke.calendar;
44

5-
6-
75
public class Calendar {
86
EventList eventList;
97
}

src/main/java/seedu/duke/calendar/CalendarCommandParser.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
//@@author kherlenbayasgalan
1+
//@@ kherlenbayasgalan & jingxizhu
22

33
package seedu.duke.calendar;
44

src/main/java/seedu/duke/calendar/CalendarManager.java

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,10 @@
1+
//@@ kherlenbayasgalan & jingxizhu
2+
13
package seedu.duke.calendar;
24

5+
import seedu.duke.calendar.command.EventCommand;
6+
import seedu.duke.calendar.command.UnknownCommand;
7+
38
import java.util.Scanner;
49

510
public class CalendarManager {
@@ -15,10 +20,18 @@ public CalendarManager() {
1520
scanner = new Scanner(System.in);
1621
}
1722

18-
public void start() {
23+
public boolean validCommand(String input) {
24+
EventCommand command = calendarCommandParser.parseInput(input);
25+
26+
return !(command instanceof UnknownCommand);
27+
}
28+
29+
public void startCalendar(String input) {
1930
calendarUi.begin();
20-
String userCommand = scanner.nextLine();
21-
calendarCommandParser.parseInput(userCommand);
31+
EventCommand command = calendarCommandParser.parseInput(input);
32+
assert !(command instanceof seedu.duke.calendar.command.UnknownCommand) :
33+
"Command cannot be " + "unknown";
34+
calendarCommandParser.parseInput(input);
2235
}
2336

2437
}

src/main/java/seedu/duke/calendar/command/EventCommand.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,8 @@
22

33
package seedu.duke.calendar.command;
44

5-
5+
import seedu.duke.calendar.EventList;
6+
import java.util.Scanner;
67

78
public abstract class EventCommand {
89
public abstract void execute(Scanner scanner, EventList eventList);

0 commit comments

Comments
 (0)