|
| 1 | +//@@author Cheezeblokz |
1 | 2 | package seedu.duke.calendar.command;
|
2 | 3 |
|
3 | 4 | import seedu.duke.calendar.Event;
|
4 | 5 | import seedu.duke.calendar.EventList;
|
5 | 6 | import seedu.duke.calendar.Goal;
|
6 | 7 |
|
7 | 8 | import java.time.LocalDateTime;
|
8 |
| -import java.time.format.DateTimeFormatter; |
9 | 9 | import java.time.format.DateTimeParseException;
|
10 | 10 | import java.util.Scanner;
|
11 | 11 |
|
12 |
| -public class AddGoalEventCommand extends EventCommand{ |
| 12 | +public class AddGoalEventCommand extends DualEventCommand{ |
13 | 13 |
|
14 |
| - //@@author kherlenbayasgalan-reused |
15 |
| - |
16 |
| - /** |
17 |
| - * The execute method is used to add an event goal to the calendar. It has two parameters (Scanner, EventList). |
18 |
| - * The EventList is used to add an event to the list. The scanner is used to get the user's event name input. |
19 |
| - * The method first takes the event name, then through parseDateTimeInput, it gets an acceptable date/time |
20 |
| - * from the user. If the user inserts acceptable inputs, the event goal will be added. If the user doesn't, |
21 |
| - * either one of DateTimeParseException or Invalid input exception. |
22 |
| - * @param scanner is used to get user's event name. |
23 |
| - * @param eventList is used to add an event to the list. |
24 |
| - */ |
| 14 | + public AddGoalEventCommand(String input) { |
| 15 | + this.input = input; |
| 16 | + beginnerCommandLength = 3; |
| 17 | + expertCommandLength = 6; |
| 18 | + syntaxString = "add goal event GOAL_NAME GOAL_END_DATE (in format yyyy-mm-ddThh:mm:ss) FLASHCARD_GOAL_NUMBER"; |
| 19 | + } |
25 | 20 |
|
26 |
| - public void execute(Scanner scanner, EventList eventList) { |
| 21 | + @Override |
| 22 | + public void executeBeginnerMode(Scanner scanner, EventList eventList) { |
27 | 23 | System.out.print("What's the goal event name?: ");
|
28 | 24 | String eventName = scanner.nextLine();
|
29 | 25 |
|
30 |
| - // checks if the acceptable format is given by the user to prevent program crash |
31 | 26 | LocalDateTime endTime = parseDateTimeInput(scanner, "When does it end? (yyyy-MM-ddTHH:mm:ss) (e.g., 2023-12-20T12:30:30): ");
|
32 | 27 | int goal = parseIntegerInput(scanner, "How many flashcard to review by then?: ");
|
33 | 28 |
|
34 |
| - Event event = new Goal(eventName, endTime, goal, 0); |
35 |
| - eventList.addEvent(event); |
36 |
| - System.out.println(event + " has been added to your Calendar"); |
| 29 | + if (endTime.isAfter(LocalDateTime.now())) { |
| 30 | + Event event = new Goal(eventName, endTime, goal, 0); |
| 31 | + eventList.addEvent(event); |
| 32 | + System.out.println(event + " has been added to your Calendar"); |
| 33 | + } else { |
| 34 | + System.out.println(" End time is before the current time. Please enter the correct end time."); |
| 35 | + } |
37 | 36 | }
|
38 | 37 |
|
39 | 38 | //@@author Cheezeblokz
|
| 39 | + @Override |
| 40 | + protected void executeExpertMode(Scanner scanner, EventList eventList) { |
| 41 | + String[] commandParts = input.split(" "); |
| 42 | + String eventName = commandParts[3]; |
| 43 | + try { |
| 44 | + LocalDateTime endTime = LocalDateTime.parse(commandParts[4]); |
| 45 | + int goal = Integer.parseInt(commandParts[5]); |
| 46 | + if (endTime.isAfter(LocalDateTime.now())) { |
| 47 | + Event event = new Goal(eventName, endTime, goal, 0); |
| 48 | + eventList.addEvent(event); |
| 49 | + System.out.println(event + " has been added to your Calendar"); |
| 50 | + } else { |
| 51 | + System.out.println(" End time is before the current time. Please enter the correct end time."); |
| 52 | + } |
| 53 | + } catch (DateTimeParseException e) { |
| 54 | + System.out.println(" Invalid date and time format. Please try again."); |
| 55 | + } catch (NumberFormatException e) { |
| 56 | + System.out.println(" Invalid integer input. Please try again."); |
| 57 | + } |
| 58 | + } |
40 | 59 |
|
41 | 60 | private int parseIntegerInput(Scanner scanner, String prompt) {
|
42 | 61 | while (true) {
|
|
0 commit comments