Skip to content

Commit 1381eef

Browse files
authored
Merge pull request nus-cs2113-AY2324S1#22 from Brian030601/master
Implement Calendar Command
2 parents b6dd7c8 + 1234198 commit 1381eef

File tree

9 files changed

+106
-11
lines changed

9 files changed

+106
-11
lines changed
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
package seedu.duke.calendar;
22

33
public class Calendar {
4-
EventStorage eventStorage;
4+
EventList eventList;
55
}

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

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
//@@author kherlenbayasgalan
2+
13
package seedu.duke.calendar;
24

35
import seedu.duke.calendar.command.AddEventCommand;

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

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,15 @@
1+
//@@author @@kherlenbayasgalan & @@ Jingxizhu
2+
13
package seedu.duke.calendar;
24

3-
import java.time.LocalDate;
5+
import java.time.LocalDateTime;
46

57
public class Event {
6-
String name;
7-
LocalDate from;
8-
LocalDate to;
8+
private String name;
9+
private LocalDateTime from;
10+
private LocalDateTime to;
911

10-
public Event(String name, LocalDate from, LocalDate to) {
12+
public Event(String name, LocalDateTime from, LocalDateTime to) {
1113
this.name = name;
1214
this.from = from;
1315
this.to = to;
@@ -21,19 +23,19 @@ public void setName(String name) {
2123
this.name = name;
2224
}
2325

24-
public LocalDate getFrom() {
26+
public LocalDateTime getFrom() {
2527
return from;
2628
}
2729

28-
public void setFrom(LocalDate from) {
30+
public void setFrom(LocalDateTime from) {
2931
this.from = from;
3032
}
3133

32-
public LocalDate getTo() {
34+
public LocalDateTime getTo() {
3335
return to;
3436
}
3537

36-
public void setTo(LocalDate to) {
38+
public void setTo(LocalDateTime to) {
3739
this.to = to;
3840
}
3941

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
package seedu.duke.calendar;
2+
3+
import seedu.duke.flashcard.Flashcard;
4+
5+
import java.time.LocalDate;
6+
import java.util.ArrayList;
7+
8+
public class EventList {
9+
private ArrayList<Event> eventList;
10+
11+
public EventList(ArrayList<Event> eventList) {
12+
this.eventList = eventList;
13+
}
14+
15+
public void addEvent(Event event) {
16+
eventList.add(event);
17+
}
18+
19+
public ArrayList<Event> getEvent() {
20+
return eventList;
21+
}
22+
23+
public boolean deleteEvent(String name) {
24+
for(Event event : eventList) {
25+
if (event.getName().equals(name)) {
26+
eventList.remove(event);
27+
return true;
28+
}
29+
}
30+
return false;
31+
}
32+
@Override
33+
public String toString() {
34+
return "EventStorage{" +
35+
"events=" + eventList +
36+
'}';
37+
}
38+
}
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,26 @@
1+
//@@ kherlenbayasgalan
2+
13
package seedu.duke.calendar.command;
24

5+
import seedu.duke.calendar.Event;
6+
import seedu.duke.calendar.EventList;
7+
8+
import java.util.Scanner;
9+
import java.time.LocalDateTime;
10+
311
public class AddEventCommand extends EventCommand{
12+
public void execute(Scanner scanner, EventList eventList) {
13+
System.out.println("What's the event?: ");
14+
String eventName = scanner.nextLine();
15+
System.out.println("When does it start?: ");
16+
LocalDateTime startTime = LocalDateTime.parse(scanner.nextLine());
17+
System.out.println("When does it end?: ");
18+
LocalDateTime endTime = LocalDateTime.parse(scanner.nextLine());
19+
20+
Event event = new Event(eventName, startTime, endTime);
21+
22+
eventList.addEvent(event);
423

24+
System.out.println("The event has been added to you calendar");
25+
}
526
}
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
package seedu.duke.calendar.command;
22

33
public class DeleteEventCommand extends EventCommand{
4+
45
}
Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,11 @@
1+
//@@author kherlenbayasgalan
2+
13
package seedu.duke.calendar.command;
24

3-
public abstract class EventCommand {
5+
import seedu.duke.calendar.EventList;
46

7+
import java.util.Scanner;
8+
9+
public abstract class EventCommand {
10+
//public abstract void execute(Scanner scanner, EventList eventList);
511
}
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,20 @@
1+
//@@author kherlenbayasgalan
2+
13
package seedu.duke.calendar.command;
24

5+
import seedu.duke.calendar.Event;
6+
import seedu.duke.calendar.EventList;
7+
8+
import java.util.Scanner;
9+
310
public class ListCalendarEventsCommand extends EventCommand{
11+
public void execute(Scanner scanner, EventList flashcardList) {
12+
System.out.println("Here is a list of all your events: ");
13+
14+
System.out.println("-".repeat(80));
15+
for (Flashcard flashcard : flashcardList.getFlashcards()) {
16+
System.out.print(flashcard);
17+
System.out.println("-".repeat(80));
18+
}
19+
}
420
}
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,13 @@
1+
//@@author kherlenbayasgalan
2+
13
package seedu.duke.calendar.command;
24

5+
import seedu.duke.calendar.EventList;
6+
7+
import java.util.Scanner;
8+
39
public class UnknownCommand extends EventCommand{
10+
public void execute(Scanner scanner, EventList eventList) {
11+
System.out.println("Unknown command! Please enter a valid command.");
12+
}
413
}

0 commit comments

Comments
 (0)