File tree Expand file tree Collapse file tree 7 files changed +75
-2
lines changed
Expand file tree Collapse file tree 7 files changed +75
-2
lines changed Original file line number Diff line number Diff line change @@ -61,7 +61,8 @@ public class CommandFactory {
6161 public static Command getCommand (String input , TaskList taskList ) throws Exception {
6262 String [] parts = input .split (" " , 2 );
6363 final String supportedCommands =
64- "- list\n - mark\n - unmark\n - find\n - delete\n - todo\n - deadline\n - event\n - undo\n - bye" ;
64+ "- list\n - mark\n - unmark\n - find\n - delete\n - todo\n - deadline\n - event\n - undo\n - bye\n \n "
65+ + "Date inputs are in the format of yyyy-MM-dd" ;
6566 switch (parts [0 ]) {
6667 case "list" :
6768 if (parts .length != 1 ) {
Original file line number Diff line number Diff line change @@ -25,9 +25,17 @@ public class MainWindow extends AnchorPane {
2525 private Image dukeImage = new
2626 Image (this .getClass ().getResourceAsStream ("/images/Cat.png" ));
2727
28+ /**
29+ * Initializes the Zbot GUI by setting up the dialog container and displaying an introductory message.
30+ * This method is called during the initialization of the main window.
31+ * It binds the scroll pane's vertical value property to the height of the dialog container
32+ * and adds a welcome message from Zbot to the dialog container.
33+ */
2834 @ FXML
2935 public void initializeZbot () {
3036 scrollPane .vvalueProperty ().bind (dialogContainer .heightProperty ());
37+ dialogContainer .getChildren ().add (DialogBox .getZbotDialog (
38+ "Hello! I'm ZoZo! How can I assist you today?" , dukeImage ));
3139 }
3240
3341 /** Injects the Zbot instance */
Original file line number Diff line number Diff line change @@ -43,6 +43,23 @@ public String getDeadline() {
4343 return this .deadline .format (inputFormatter );
4444 }
4545
46+ /**
47+ * Creates a copy of the current task.
48+ * This method is intended to return a new instance of the task with the same description and state.
49+ *
50+ * @return A new {@link Task} object with the same description and deadline as the current task.
51+ */
52+ @ Override
53+ public Task copy () {
54+ DeadlineTask taskCopy = new DeadlineTask (this .getDescription (), this .getDeadline ());
55+ if (this .getDoneStatus ()) {
56+ taskCopy .markDone ();
57+ } else {
58+ taskCopy .markUndone ();
59+ }
60+ return taskCopy ;
61+ }
62+
4663 /**
4764 * Returns a string representation of the {@code DeadlineTask}.
4865 * The string includes the task's description, completion status, and deadline.
Original file line number Diff line number Diff line change @@ -68,6 +68,23 @@ public String toDateString() {
6868 return this .toDate .format (outputFormatter );
6969 }
7070
71+ /**
72+ * Creates a copy of the current task.
73+ * This method is intended to return a new instance of the task with the same description and state.
74+ *
75+ * @return A new {@link Task} object with the same description and dates as the current task.
76+ */
77+ @ Override
78+ public Task copy () {
79+ EventTask taskCopy = new EventTask (this .getDescription (), this .getFromDate (), this .getToDate ());
80+ if (this .getDoneStatus ()) {
81+ taskCopy .markDone ();
82+ } else {
83+ taskCopy .markUndone ();
84+ }
85+ return taskCopy ;
86+ }
87+
7188 /**
7289 * Returns a string representation of the {@code EventTask}.
7390 * The string includes the task's description, completion status, and the event's date range.
Original file line number Diff line number Diff line change @@ -19,6 +19,15 @@ public Task(String description) {
1919 this .isDone = false ;
2020 }
2121
22+ /**
23+ * Creates a copy of the current task.
24+ * This method is intended to be overridden by subclasses of {@link Task}.
25+ * It should return a new instance of the task with the same description and relevant state.
26+ *
27+ * @return A new {@link Task} object with the same description and relevant state as the current task.
28+ */
29+ public abstract Task copy ();
30+
2231 /**
2332 * Marks the task as done.
2433 */
Original file line number Diff line number Diff line change @@ -160,7 +160,11 @@ public boolean restore() {
160160 *
161161 */
162162 private void saveStateForUndo () {
163- undoHistory .push (new ArrayList <>(taskList ));
163+ ArrayList <Task > taskListCopy = new ArrayList <>();
164+ for (Task task : taskList ) {
165+ taskListCopy .add (task .copy ());
166+ }
167+ undoHistory .push (taskListCopy );
164168 }
165169
166170 /**
Original file line number Diff line number Diff line change @@ -15,6 +15,23 @@ public ToDoTask(String description) {
1515 super (description );
1616 }
1717
18+ /**
19+ * Creates a copy of the current task.
20+ * This method is intended to return a new instance of the task with the same description and state.
21+ *
22+ * @return A new {@link Task} object with the same description as the current task.
23+ */
24+ @ Override
25+ public Task copy () {
26+ ToDoTask taskCopy = new ToDoTask (this .getDescription ());
27+ if (this .getDoneStatus ()) {
28+ taskCopy .markDone ();
29+ } else {
30+ taskCopy .markUndone ();
31+ }
32+ return taskCopy ;
33+ }
34+
1835 /**
1936 * Returns a string representation of the to-do task.
2037 * The format is "[T][status] description".
You can’t perform that action at this time.
0 commit comments