Skip to content

Commit 8ab034c

Browse files
committed
- Implemented dual input command for delete event and find event
1 parent 146311d commit 8ab034c

File tree

7 files changed

+71
-21
lines changed

7 files changed

+71
-21
lines changed

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

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

33
package seedu.duke.calendar;
44

@@ -70,13 +70,13 @@ public EventCommand parseInput(String input) {
7070
} else if (input.startsWith("add goal event")) {
7171
return new AddGoalEventCommand(input);
7272
} else if (input.startsWith("delete event")) {
73-
return new DeleteEventCommand();
73+
return new DeleteEventCommand(input);
7474
} else if (input.startsWith("list events")) {
7575
return new ListCalendarEventsCommand();
7676
} else if (input.startsWith("delete all events")) {
7777
return new DeleteAllEventsCommand();
7878
} else if (input.startsWith("find event")) {
79-
return new FindEventCommand();
79+
return new FindEventCommand(input);
8080
}
8181

8282
} catch (AddEventException exception) {

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

Lines changed: 0 additions & 1 deletion
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;

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

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

33
package seedu.duke.calendar.command;
44

@@ -7,18 +7,26 @@
77

88
import java.util.Scanner;
99

10-
public class DeleteEventCommand extends EventCommand{
10+
public class DeleteEventCommand extends DualEventCommand {
1111

12-
/**
13-
* The execute method is used to delete an specified event from the EventList.
14-
* It takes two parameters (Scanner , EventList). The method takes in the event name,
15-
* then calls the deleteEvent function to search and delete the event.
16-
* If the event is not in the EventList, then "event doesn't exist" message will be displayed.
17-
* @param scanner is used to get user's desired event to be deleted.
18-
* @param eventList is used to delete the specified event from the EventList.
19-
*/
12+
public DeleteEventCommand(String input) {
13+
this.input = input;
14+
beginnerCommandLength = 2;
15+
expertCommandLength = 3;
16+
syntaxString = "delete event EVENT_NAME";
17+
}
2018

21-
public void execute(Scanner scanner, EventList eventList) {
19+
/**
20+
* The execute method is used to delete an specified event from the EventList.
21+
* It takes two parameters (Scanner , EventList). The method takes in the event name,
22+
* then calls the deleteEvent function to search and delete the event.
23+
* If the event is not in the EventList, then "event doesn't exist" message will be displayed.
24+
* @param scanner is used to get user's desired event to be deleted.
25+
* @param eventList is used to delete the specified event from the EventList.
26+
*/
27+
28+
@Override
29+
protected void executeBeginnerMode(Scanner scanner, EventList eventList) {
2230
int size;
2331

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

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

Lines changed: 31 additions & 3 deletions
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

@@ -7,8 +7,18 @@
77

88
import java.util.Scanner;
99

10-
public class FindEventCommand extends EventCommand {
10+
public class FindEventCommand extends DualEventCommand {
1111

12+
//@@author Cheezeblokz
13+
14+
public FindEventCommand(String input) {
15+
this.input = input;
16+
beginnerCommandLength = 2;
17+
expertCommandLength = 3;
18+
syntaxString = "find event EVENT_NAME";
19+
}
20+
21+
//@@author kherlenbayasgalan
1222
/**
1323
* The execute method is to search and find an event from the EventList. The method has two
1424
* parameters (Scanner , EventList). Scanner takes the name of the event that the user
@@ -18,7 +28,8 @@ public class FindEventCommand extends EventCommand {
1828
* @param eventList is used to access EventList and find the specified event.
1929
*/
2030

21-
public void execute(Scanner scanner, EventList eventList) {
31+
@Override
32+
protected void executeBeginnerMode(Scanner scanner, EventList eventList) {
2233
System.out.print("What event are you looking for?: ");
2334
String eventName = scanner.nextLine();
2435

@@ -30,4 +41,21 @@ public void execute(Scanner scanner, EventList eventList) {
3041
System.out.println(" No such event found");
3142
}
3243
}
44+
45+
46+
//@@author Cheezeblokz
47+
48+
@Override
49+
protected void executeExpertMode(Scanner scanner, EventList eventList) {
50+
String[] commandParts = input.split(" ");
51+
String eventName = commandParts[2];
52+
53+
int count = eventList.findEvent(eventName);
54+
55+
if (count > 0) {
56+
System.out.println(" These events have been found");
57+
} else {
58+
System.out.println(" No such event found");
59+
}
60+
}
3361
}

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

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

33
package seedu.duke.calendar.command;
44

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

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

33
package seedu.duke.calendar.command;
44

0 commit comments

Comments
 (0)