Skip to content

Commit 0f3b5fd

Browse files
Merge branch 'master' into add-assertions-and-javadoc
2 parents f7c2ea7 + 19aa81d commit 0f3b5fd

26 files changed

+145
-60
lines changed

data/events/event.txt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
hello | 2023-12-20T12:30:30 | 2023-12-20T12:30:30
22
EC3333 | 2023-12-20T12:30:30 | 2023-12-20T12:30:40
3-
Deadline | 2023-12-20T12:30:30 | 10 | 0
4-
More Deadline | 2023-12-20T12:30:30 | 20 | 0
3+
Deadline | 2023-12-20T12:30:30 | 10 | 1
4+
More Deadline | 2023-12-20T12:30:30 | 20 | 1

data/flashcards/flashcard.txt

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,9 @@
1-
14 | dfdf | a | 5
2-
15 | now | you can see me | 5
1+
3 | cs2113 | software enginnering | 3
2+
5 | Hello | Duke | 4
3+
7 | Hello | Duke | 4
4+
9 | id | checker | 6
5+
10 | id increases | correctly | 5
6+
11 | f | dfdf | 5
7+
12 | dfdf | | 5
8+
13 | 1 | j | 5
9+
14 | Hello | Duke | 5

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

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

33
package seedu.duke;
44

5+
import seedu.duke.calendar.Calendar;
56
import seedu.duke.calendar.CalendarManager;
67
import seedu.duke.flashcard.FlashcardComponent;
78

@@ -19,8 +20,9 @@ public static void main(String[] args) {
1920
* Starts a REPL session where commands are inputted and then processed.
2021
*/
2122
private void run() {
22-
FlashcardComponent fc = new FlashcardComponent();
23-
CalendarManager cm = new CalendarManager(new ArrayList<>());
23+
Calendar calendar = new Calendar();
24+
FlashcardComponent fc = new FlashcardComponent(calendar);
25+
CalendarManager cm = new CalendarManager(calendar, new ArrayList<>());
2426

2527
Scanner scanner = new Scanner(System.in);
2628
String input;

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

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,10 @@ public class Calendar {
99
*/
1010
EventList eventList;
1111

12-
public Calendar(EventList eventList) {
12+
public Calendar() {
13+
}
14+
15+
public void setEventList(EventList eventList) {
1316
this.eventList = eventList;
1417
}
1518

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

Lines changed: 16 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,21 @@
1-
//@@ kherlenbayasgalan & jingxizhu
1+
//@@author kherlenbayasgalan & Cheezeblokz
22

33
package seedu.duke.calendar;
44

5-
import seedu.duke.calendar.command.*;
5+
import seedu.duke.calendar.command.AddEventCommand;
6+
import seedu.duke.calendar.command.AddGoalEventCommand;
7+
import seedu.duke.calendar.command.DeleteEventCommand;
8+
import seedu.duke.calendar.command.EventCommand;
9+
import seedu.duke.calendar.command.FindEventCommand;
10+
import seedu.duke.calendar.command.DeleteAllEventsCommand;
11+
import seedu.duke.calendar.command.ListCalendarEventsCommand;
12+
import seedu.duke.calendar.command.UnknownCommand;
613

7-
import seedu.duke.calendar.Exceptions.AddEventException;
8-
import seedu.duke.calendar.Exceptions.DeleteEventException;
9-
import seedu.duke.calendar.Exceptions.DeleteAllException;
10-
import seedu.duke.calendar.Exceptions.FindEventException;
11-
import seedu.duke.calendar.Exceptions.ListEventException;
14+
import seedu.duke.calendar.exceptions.AddEventException;
15+
import seedu.duke.calendar.exceptions.DeleteEventException;
16+
import seedu.duke.calendar.exceptions.DeleteAllException;
17+
import seedu.duke.calendar.exceptions.FindEventException;
18+
import seedu.duke.calendar.exceptions.ListEventException;
1219

1320
import java.util.Scanner;
1421

@@ -70,13 +77,13 @@ public EventCommand parseInput(String input) {
7077
} else if (input.startsWith("add goal event")) {
7178
return new AddGoalEventCommand(input);
7279
} else if (input.startsWith("delete event")) {
73-
return new DeleteEventCommand();
80+
return new DeleteEventCommand(input);
7481
} else if (input.startsWith("list events")) {
7582
return new ListCalendarEventsCommand();
7683
} else if (input.startsWith("delete all events")) {
7784
return new DeleteAllEventsCommand();
7885
} else if (input.startsWith("find event")) {
79-
return new FindEventCommand();
86+
return new FindEventCommand(input);
8087
}
8188

8289
} catch (AddEventException exception) {

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

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ public class CalendarManager {
2525
* @param events is used to initialize the EventList.
2626
*/
2727

28-
public CalendarManager(ArrayList<Event> events) {
28+
public CalendarManager(Calendar calendar, ArrayList<Event> events) {
2929

3030
EventDirectory eventdirectory = new EventDirectory();
3131
eventdirectory.listEventFiles();
@@ -39,7 +39,8 @@ public CalendarManager(ArrayList<Event> events) {
3939
eventList = new EventList(events);
4040
}
4141

42-
calendar = new Calendar(eventList);
42+
calendar.setEventList(eventList);
43+
this.calendar = calendar;
4344
calendarUi = new CalendarUi(eventList);
4445
calendarCommandParser = new CalendarCommandParser();
4546
scanner = new Scanner(System.in);

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

Lines changed: 15 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33
package seedu.duke.calendar.command;
44

55
import java.time.LocalDateTime;
6-
import java.time.format.DateTimeFormatter;
76

87
import seedu.duke.calendar.Event;
98
import seedu.duke.calendar.EventList;
@@ -19,16 +18,19 @@ public AddEventCommand(String input) {
1918
this.input = input;
2019
beginnerCommandLength = 2;
2120
expertCommandLength = 5;
22-
syntaxString = "add event EVENT_NAME EVENT_START_DATE (in format yyyy-mm-ddThh:mm:ss) EVENT_END_DATE (in format yyyy-mm-ddThh:mm:ss)";
21+
syntaxString = "add event EVENT_NAME EVENT_START_DATE (in format yyyy-mm-ddThh:mm:ss) " +
22+
"EVENT_END_DATE (in format yyyy-mm-ddThh:mm:ss)";
2323
}
2424

2525
//@@author kherlenbayasgalan
2626
/**
27-
* The executeBeginnerMode method is used to add an event to the calendar. It has two parameters (Scanner, EventList).
28-
* The EventList is used to add an event to the list. The scanner is used to get the user's event name input.
29-
* The method first takes the event name, then through parseDateTimeInput, it gets an acceptable date/time
30-
* from the user. If the user inserts acceptable inputs, the event will be added. If the user doesn't,
31-
* either one of DateTimeParseException or Invalid input exception.
27+
* The executeBeginnerMode method is used to add an event to the calendar.
28+
* It has two parameters (Scanner, EventList). The EventList is used to add an
29+
* event to the list. The scanner is used to get the user's event name input.
30+
* The method first takes the event name, then through parseDateTimeInput,
31+
* it gets an acceptable date/time from the user. If the user inserts acceptable inputs,
32+
* the event will be added. If the user doesn't, either one of DateTimeParseException
33+
* or Invalid input exception.
3234
* @param scanner is used to get user's event name.
3335
* @param eventList is used to add an event to the list.
3436
*/
@@ -39,8 +41,10 @@ public void executeBeginnerMode(Scanner scanner, EventList eventList) {
3941
String eventName = scanner.nextLine();
4042

4143
// checks if the acceptable format is given by the user to prevent program crash
42-
LocalDateTime startTime = parseDateTimeInput(scanner, "When does it start? (yyyy-MM-ddTHH:mm:ss) (e.g., 2023-12-20T12:30:30): ");
43-
LocalDateTime endTime = parseDateTimeInput(scanner, "When does it end? (yyyy-MM-ddTHH:mm:ss) (e.g., 2023-12-20T12:30:30): ");
44+
LocalDateTime startTime = parseDateTimeInput(scanner,
45+
"When does it start? (yyyy-MM-ddTHH:mm:ss) (e.g., 2023-12-20T12:30:30): ");
46+
LocalDateTime endTime = parseDateTimeInput(scanner,
47+
"When does it end? (yyyy-MM-ddTHH:mm:ss) (e.g., 2023-12-20T12:30:30): ");
4448

4549
if (endTime.isAfter(startTime)) {
4650
Event event = new Event(eventName, startTime, endTime);
@@ -64,7 +68,8 @@ protected void executeExpertMode(Scanner scanner, EventList eventList) {
6468
eventList.addEvent(event);
6569
System.out.println(event + " has been added to your Calendar");
6670
} else {
67-
System.out.println(" End time is before or equal to the start time. Please enter the correct end time.");
71+
System.out.println(" End time is before or equal to the start time. " +
72+
"Please enter the correct end time.");
6873
}
6974
} catch (DateTimeParseException e) {
7075
System.out.println(" Invalid date and time format. Please try again.");

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

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,8 +23,10 @@ public void executeBeginnerMode(Scanner scanner, EventList eventList) {
2323
System.out.print("What's the goal event name?: ");
2424
String eventName = scanner.nextLine();
2525

26-
LocalDateTime endTime = parseDateTimeInput(scanner, "When does it end? (yyyy-MM-ddTHH:mm:ss) (e.g., 2023-12-20T12:30:30): ");
27-
int goal = parseIntegerInput(scanner, "How many flashcard to review by then?: ");
26+
LocalDateTime endTime = parseDateTimeInput(scanner,
27+
"When does it end? (yyyy-MM-ddTHH:mm:ss) (e.g., 2023-12-20T12:30:30): ");
28+
int goal = parseIntegerInput(scanner,
29+
"How many flashcard to review by then?: ");
2830

2931
if (endTime.isAfter(LocalDateTime.now())) {
3032
Event event = new Goal(eventName, endTime, goal, 0);

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

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

33
package seedu.duke.calendar.command;
44

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

Lines changed: 26 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,19 @@
1-
//@@author kherlenbayasgalan & Cheezeblokz
1+
//@@author kherlenbayasgalan
22

33
package seedu.duke.calendar.command;
44

55
import seedu.duke.calendar.EventList;
6-
import seedu.duke.calendar.Event;
76

87
import java.util.Scanner;
98

10-
public class DeleteEventCommand extends EventCommand{
9+
public class DeleteEventCommand extends DualEventCommand {
10+
11+
public DeleteEventCommand(String input) {
12+
this.input = input;
13+
beginnerCommandLength = 2;
14+
expertCommandLength = 3;
15+
syntaxString = "delete event EVENT_NAME";
16+
}
1117

1218
/**
1319
* The execute method is used to delete an specified event from the EventList.
@@ -18,7 +24,8 @@ public class DeleteEventCommand extends EventCommand{
1824
* @param eventList is used to delete the specified event from the EventList.
1925
*/
2026

21-
public void execute(Scanner scanner, EventList eventList) {
27+
@Override
28+
protected void executeBeginnerMode(Scanner scanner, EventList eventList) {
2229
int size;
2330

2431
System.out.print("Enter the event name: ");
@@ -31,4 +38,19 @@ public void execute(Scanner scanner, EventList eventList) {
3138
System.out.println(" " + eventName + " doesn't exist in your Calendar!");
3239
}
3340
}
41+
42+
//@@author Cheezeblokz
43+
44+
@Override
45+
protected void executeExpertMode(Scanner scanner, EventList eventList) {
46+
String[] commandParts = input.split(" ");
47+
String eventName = commandParts[2];
48+
49+
int size = eventList.deleteEvent(eventName);
50+
if (size > eventList.getSize()) {
51+
System.out.println(" " + eventName + " has been deleted from your Calendar!");
52+
} else if (size != 0 && size == eventList.getSize()) {
53+
System.out.println(" " + eventName + " doesn't exist in your Calendar!");
54+
}
55+
}
3456
}

0 commit comments

Comments
 (0)