Skip to content

Commit 012d36d

Browse files
authored
Merge pull request nus-cs2113-AY2324S1#33 from Brian030601/master
Fix Calendar Add/List/Delete Issues
2 parents b346920 + 3e94866 commit 012d36d

File tree

6 files changed

+33
-11
lines changed

6 files changed

+33
-11
lines changed

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

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,11 @@
1+
//@@author wendelinwemhoener & kherlenbayasgalan
2+
13
package seedu.duke;
24

35
import seedu.duke.flashcard.Flashcard;
46
import seedu.duke.flashcard.FlashcardComponent;
57
import seedu.duke.calendar.CalendarManager;
8+
import seedu.duke.calendar.Event;
69

710
import java.util.ArrayList;
811
import java.util.Scanner;
@@ -17,7 +20,7 @@ public static void main(String[] args) {
1720
private void runCalendar() {
1821
System.out.println("Enter your command: ");
1922

20-
CalendarManager manager = new CalendarManager();
23+
CalendarManager manager = new CalendarManager(new ArrayList<Event>());
2124

2225
Scanner scanner = new Scanner(System.in);
2326
String input;

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

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,18 +4,22 @@
44

55
import seedu.duke.calendar.command.EventCommand;
66
import seedu.duke.calendar.command.UnknownCommand;
7+
import seedu.duke.calendar.Event;
78

9+
import java.util.ArrayList;
810
import java.util.Scanner;
911

1012
public class CalendarManager {
1113
Calendar calendar;
1214
CalendarUi calendarUi;
15+
EventList eventList;
1316
CalendarCommandParser calendarCommandParser;
1417
Scanner scanner;
1518

16-
public CalendarManager() {
19+
public CalendarManager(ArrayList<Event> events) {
20+
eventList = new EventList(events);
1721
calendar = new Calendar();
18-
calendarUi = new CalendarUi();
22+
calendarUi = new CalendarUi(eventList);
1923
calendarCommandParser = new CalendarCommandParser();
2024
scanner = new Scanner(System.in);
2125
}
@@ -27,11 +31,11 @@ public boolean validCommand(String input) {
2731
}
2832

2933
public void startCalendar(String input) {
30-
calendarUi.begin();
3134
EventCommand command = calendarCommandParser.parseInput(input);
3235
assert !(command instanceof seedu.duke.calendar.command.UnknownCommand) :
3336
"Command cannot be " + "unknown";
34-
calendarCommandParser.parseInput(input);
37+
calendarUi.executeCommand(command);
38+
//calendarCommandParser.parseInput(command);
3539
}
3640

3741
}
Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,19 @@
11
package seedu.duke.calendar;
22

3+
import seedu.duke.calendar.command.EventCommand;
4+
5+
import java.util.Scanner;
6+
37
public class CalendarUi {
4-
public void begin() {
5-
System.out.print("Enter User Command: ");
8+
private Scanner scanner;
9+
private EventList eventList;
10+
11+
public CalendarUi (EventList eventList) {
12+
scanner = new Scanner(System.in);
13+
this.eventList = eventList;
14+
}
15+
16+
public void executeCommand(EventCommand command) {
17+
command.execute(scanner, eventList);
618
}
719
}

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

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,17 +10,18 @@
1010

1111
public class AddEventCommand extends EventCommand{
1212
public void execute(Scanner scanner, EventList eventList) {
13-
System.out.println("What's the event?: ");
13+
System.out.print("What's the event?: ");
1414
String eventName = scanner.nextLine();
15-
System.out.println("When does it start? (yyyy-mm-ddThh:mm:ss) (eg. 2023-12-20T12:30:30): ");
15+
System.out.print("When does it start? (yyyy-mm-ddThh:mm:ss) (eg. 2023-12-20T12:30:30): ");
1616
LocalDateTime startTime = LocalDateTime.parse(scanner.nextLine());
17-
System.out.println("When does it end? (yyyy-mm-ddThh:mm:ss) (eg. 2023-12-20T12:30:30): ");
17+
System.out.print("When does it end? (yyyy-mm-ddThh:mm:ss) (eg. 2023-12-20T12:30:30): ");
1818
LocalDateTime endTime = LocalDateTime.parse(scanner.nextLine());
1919

2020
Event event = new Event(eventName, startTime, endTime);
2121

2222
eventList.addEvent(event);
2323

2424
System.out.println(event + " has been added to you calendar");
25+
System.out.print("Enter your command: ");
2526
}
2627
}

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,5 +13,6 @@ public void execute(Scanner scanner, EventList eventList) {
1313

1414
eventList.deleteEvent(eventName);
1515
System.out.println(eventName + " has been deleted from your Calendar!");
16+
System.out.print("Enter your command: ");
1617
}
1718
}

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

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,9 +13,10 @@ public void execute(Scanner scanner, EventList eventList) {
1313
printLine();
1414

1515
for (Event event : eventList.getEvent()) {
16-
System.out.print(event);
16+
System.out.println(event);
1717
printLine();
1818
}
19+
System.out.print("Enter your command: ");
1920
}
2021

2122
public void printLine() {

0 commit comments

Comments
 (0)