Skip to content

Commit 8fe143a

Browse files
authored
Merge pull request nus-cs2113-AY2324S1#11 from AY2324S1-CS2113-F11-3/master
Update
2 parents 15de82c + f68a5b5 commit 8fe143a

24 files changed

+319
-98
lines changed

data/events/event.txt

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,2 @@
1-
submit v1.0 | 2023-10-29T23:59:59 | 2023-10-30T23:59:59
2-
eat dinner | 2023-12-20T19:00 | 2023-12-20T20:00
3-
Do HW | 2023-12-20T12:30:30 | 2023-12-20T12:30:30
1+
hello | 2023-12-20T12:30:30 | 2023-12-20T12:30:30
2+
EC3333 | 2023-12-20T12:30:30 | 2023-12-20T12:30:40

docs/README.md

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
1-
# Duke
1+
# TaskLinker
22

3-
{Give product intro here}
3+
TaskLinker is a CLI-tool for helping university students memorize flashcards
4+
and track their flashcard and general academic progress in the courses they are
5+
taking.
46

57
Useful links:
68
* [User Guide](UserGuide.md)

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

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ private void run() {
3131
fc.processInput(input);
3232
} else if (cm.isResponsible(input)) {
3333
cm.processInput(input);
34-
} else if (input.equals("exit program")) {
34+
} else if (input.equals("exit")) {
3535
System.out.println(" You are exiting TaskLinker! Bye!");
3636
break;
3737
} else if (input.startsWith("help")) {
@@ -61,6 +61,7 @@ private void printHelp() {
6161
"delete all events",
6262
"find event",
6363
"list events",
64+
"exit",
6465
};
6566

6667
for (String commandFormat : commandFormats) {

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

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

55
public class Calendar {
6+
/**
7+
* The class is here for integrating Flashcard goals with the Calendar.
8+
* Any other features related to the Calendar can be added here in the future.
9+
*/
10+
611
EventList eventList;
712
}

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

Lines changed: 79 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -10,20 +10,89 @@
1010
import seedu.duke.calendar.command.FindEventCommand;
1111
import seedu.duke.calendar.command.ListCalendarEventsCommand;
1212

13+
import seedu.duke.calendar.Exceptions.AddEventException;
14+
import seedu.duke.calendar.Exceptions.DeleteEventException;
15+
import seedu.duke.calendar.Exceptions.DeleteAllException;
16+
import seedu.duke.calendar.Exceptions.FindEventException;
17+
import seedu.duke.calendar.Exceptions.ListEventException;
18+
19+
import java.util.Scanner;
20+
1321
public class CalendarCommandParser {
22+
23+
/**
24+
* The manageException method is used to throw exceptions if those exceptions have
25+
* been encountered. Each if case handles different exception errors. The method
26+
* has one parameter (String userInput), which is used to check if the input has
27+
* anything else after it.
28+
* @param userInput is taken to check if the condition matches the exception.
29+
* @throws AddEventException is thrown if the user only inputs add and nothing else.
30+
* @throws DeleteEventException is thrown if the user only inputs delete all and nothing else.
31+
* @throws DeleteAllException is thrown if the user only inputs delete and nothing else.
32+
* @throws FindEventException is thrown if the user only inputs find and nothing else.
33+
* @throws ListEventException is thrown if the user only inputs list and nothing else.
34+
*/
35+
36+
public static void manageException(String userInput) throws AddEventException, DeleteEventException,
37+
DeleteAllException, FindEventException, ListEventException {
38+
39+
Scanner input = new Scanner(userInput);
40+
String command = input.next();
41+
42+
if (command.equals("add") && !input.hasNext()) {
43+
throw new AddEventException();
44+
}
45+
if (command.equals("delete all") && !input.hasNext()) {
46+
throw new DeleteAllException();
47+
}
48+
if (command.equals("delete") && !input.hasNext()) {
49+
throw new DeleteEventException();
50+
}
51+
if (command.equals("find") && !input.hasNext()) {
52+
throw new FindEventException();
53+
}
54+
if (command.equals("list") && !input.hasNext()) {
55+
throw new ListEventException();
56+
}
57+
}
58+
59+
/**
60+
* The parseInput method is used to catch any exceptions that could occur. The method
61+
* has one parameter (String input). The input is used for asserting that it is not null.
62+
* If any exceptions are caught, then the corresponding messages are displayed.
63+
* Last resort unknown command will run if the command is not recognized.
64+
* @param input is used to check whether input is null or not.
65+
* @return runs the commands
66+
*/
67+
1468
public EventCommand parseInput(String input) {
69+
// using asser to check whether the input is null.
1570
assert input != null : "input is null";
1671

17-
if (input.startsWith("add event")) {
18-
return new AddEventCommand(input);
19-
} else if (input.startsWith("delete event")) {
20-
return new DeleteEventCommand();
21-
} else if (input.startsWith("list events")) {
22-
return new ListCalendarEventsCommand();
23-
} else if (input.startsWith("delete all events")) {
24-
return new DeleteAllEventsCommand();
25-
} else if (input.startsWith("find event")) {
26-
return new FindEventCommand();
72+
try {
73+
manageException(input);
74+
if (input.startsWith("add event")) {
75+
return new AddEventCommand();
76+
} else if (input.startsWith("delete event")) {
77+
return new DeleteEventCommand();
78+
} else if (input.startsWith("list events")) {
79+
return new ListCalendarEventsCommand();
80+
} else if (input.startsWith("delete all events")) {
81+
return new DeleteAllEventsCommand();
82+
} else if (input.startsWith("find event")) {
83+
return new FindEventCommand();
84+
}
85+
86+
} catch (AddEventException exception) {
87+
System.out.println("☹ OOPS!!! The description of an add cannot be empty.");
88+
} catch (DeleteAllException exception) {
89+
System.out.println("☹ OOPS!!! The description of a delete all cannot be empty.");
90+
} catch (DeleteEventException exception) {
91+
System.out.println("☹ OOPS!!! The description of a delete cannot be empty.");
92+
} catch (FindEventException exception) {
93+
System.out.println("☹ OOPS!!! The description of an find cannot be empty.");
94+
} catch (ListEventException exception) {
95+
System.out.println("☹ OOPS!!! The description of a list cannot.");
2796
}
2897

2998
return new UnknownCommand();

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

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,12 @@ public class CalendarManager {
1818

1919
private EventStorage storage;
2020

21+
/**
22+
* The CalendarManager initializes the accesses to other classes.
23+
* It also loads events from the storage.
24+
* @param events is used to initialize the EventList.
25+
*/
26+
2127
public CalendarManager(ArrayList<Event> events) {
2228

2329
EventDirectory eventdirectory = new EventDirectory();
@@ -39,32 +45,46 @@ public CalendarManager(ArrayList<Event> events) {
3945

4046
}
4147

48+
// getStorage is used for getting the storage
4249
public EventStorage getStorage(){
4350
return this.storage;
4451
}
4552

53+
/**
54+
* validCommand is used for checking whether the command is valid, and
55+
* not an instance of UnknownCommand.
56+
* @param input is used for converting the input into command.
57+
* @return returns whether the command is instance of UnknownCommand or not.
58+
*/
59+
4660
public boolean validCommand(String input) {
4761
EventCommand command = calendarCommandParser.parseInput(input);
4862

4963
return !(command instanceof UnknownCommand);
5064
}
5165

66+
// isResponsible calls the validCommand method.
5267
public boolean isResponsible(String input) {
5368
return validCommand(input);
5469
}
5570

71+
// processInput is used for saving the events in the EventList.
5672
public void processInput(String input) {
5773
startCalendar(input);
5874

5975
storage.saveEvents(eventList.getEvent());
6076
}
6177

78+
/**
79+
* startCalender starts the Calendar features and uses the input as a command.
80+
* @param input is used for converting the input into command.
81+
*/
82+
6283
public void startCalendar(String input) {
6384
EventCommand command = calendarCommandParser.parseInput(input);
6485
assert !(command instanceof seedu.duke.calendar.command.UnknownCommand) :
6586
"Command cannot be " + "unknown";
6687
calendarUi.executeCommand(command);
6788
//calendarCommandParser.parseInput(command);
6889
}
69-
7090
}

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

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,11 +8,17 @@ public class CalendarUi {
88
private Scanner scanner;
99
private EventList eventList;
1010

11+
// CalendarUi is the constructor method for CalendarUi class.
1112
public CalendarUi (EventList eventList) {
1213
scanner = new Scanner(System.in);
1314
this.eventList = eventList;
1415
}
1516

17+
/**
18+
* executeCommand is used for starting the calendar part of the program.
19+
* @param command is used for relaying the command entered by the user.
20+
*/
21+
1622
public void executeCommand(EventCommand command) {
1723
command.execute(scanner, eventList);
1824
}

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

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,36 +9,44 @@ public class Event {
99
private LocalDateTime from;
1010
private LocalDateTime to;
1111

12+
// Event is a constructor method for Event class.
1213
public Event(String name, LocalDateTime from, LocalDateTime to) {
1314
this.name = name;
1415
this.from = from;
1516
this.to = to;
1617
}
1718

19+
// getName returns the name of the event.
1820
public String getName() {
1921
return name;
2022
}
2123

24+
// setName is used for setting the event name.
2225
public void setName(String name) {
2326
this.name = name;
2427
}
2528

29+
// getFrom is used for getting the start time of an Event.
2630
public LocalDateTime getFrom() {
2731
return from;
2832
}
2933

34+
// setFrom is used for setting the start time of an Event.
3035
public void setFrom(LocalDateTime from) {
3136
this.from = from;
3237
}
3338

39+
// getFrom is used for getting the end time of an Event.
3440
public LocalDateTime getTo() {
3541
return to;
3642
}
3743

44+
// setFrom is used for setting the end time of an Event.
3845
public void setTo(LocalDateTime to) {
3946
this.to = to;
4047
}
4148

49+
// toString is used for formatting the print version of an Event.
4250
@Override
4351
public String toString() {
4452
return "Event '" + name + '\'' +

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -85,8 +85,8 @@ public String defaultDirectory() {
8585
/**
8686
* return directory of flashcard txt file
8787
* for version 2
88-
* @param path
89-
* @return
88+
* @param path is used for storing file path
89+
* @return is used to get the path to the file
9090
*/
9191
public String eventDirectory(String path) {
9292
return this.path + path;

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

Lines changed: 20 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,40 +7,56 @@
77
public class EventList {
88
private ArrayList<Event> eventList;
99

10+
// EventList is a constructor method
1011
public EventList(ArrayList<Event> eventList) {
1112
this.eventList = eventList;
1213
}
1314

15+
// addEvent is used for adding an event to the EventList.
1416
public void addEvent(Event event) {
1517
eventList.add(event);
1618
}
1719

20+
// getEvent is used to get an event from the EventList.
1821
public ArrayList<Event> getEvent() {
1922
return eventList;
2023
}
2124

22-
// for logging
25+
// getSize is used for getting the size of EventList.
2326
public int getSize() {
2427
return eventList.size();
2528
}
2629

27-
public void findEvent(String keyword) {
30+
// findEvent is used for finding a specific event from the EventList.
31+
public int findEvent(String keyword) {
2832
int count = 0;
2933
for (Event event: eventList) {
3034
if (event.getName().contains(keyword)) {
3135
System.out.println((++count) + ". " + event);
3236
}
3337
}
38+
39+
return count;
3440
}
3541

36-
public void deleteEvent(String name) {
37-
eventList.removeIf(event -> event.getName().equals(name));
42+
// deleteEvent is used for deleting an event from the EventList
43+
public int deleteEvent(String name) {
44+
int size = eventList.size();
45+
if (size > 0) {
46+
eventList.removeIf(event -> event.getName().equals(name));
47+
} else {
48+
System.out.println("The Calendar is empty");
49+
}
50+
51+
return size;
3852
}
3953

54+
// deleteAllEvents is used for deleting all events in the EventList.
4055
public void deleteAllEvents() {
4156
eventList.clear();
4257
}
4358

59+
// toString formats the print version of EventList.
4460
@Override
4561
public String toString() {
4662
return "EventStorage{" +

0 commit comments

Comments
 (0)