1- import java .io .*;
21import java .util .Scanner ;
32import java .util .ArrayList ;
43import java .util .List ;
@@ -7,7 +6,7 @@ public class Duke {
76
87 Scanner sc = new Scanner (System .in );
98
10- public static void main (String [] args ) throws DukeException , IOException {
9+ public static void main (String [] args ) {
1110 String logo = " ____ _ \n "
1211 + "| _ \\ _ _| | _____ \n "
1312 + "| | | | | | | |/ / _ \\ \n "
@@ -19,16 +18,16 @@ public static void main(String[] args) throws DukeException, IOException {
1918 duke .chatDuke ();
2019 }
2120
22- public void chatDuke () throws IOException {
21+ public void chatDuke () {
2322
24- Save save = new Save ();
25- List <Task > allTasks = save .loadTxtFile ();
23+ List <Task > allTasks = new ArrayList <>();
2624
2725 this .printGreetingMessage ();
2826
2927 boolean saidBye = false ;
3028 while (!saidBye ) {
3129 String command = sc .nextLine ();
30+
3231 try {
3332 if (command .equals ("list" )) {
3433 this .printCommandList (allTasks );
@@ -44,24 +43,21 @@ public void chatDuke() throws IOException {
4443 allTasks .size ());
4544 allTasks .set (taskIndex , todo );
4645 todo .markAsDone ();
47- save .saveListToFile (command , todo , allTasks );
4846 } else if (oldTask .getTaskType ().equals ("[D]" )) {
4947 Deadline deadline = new Deadline (oldTask .getTaskNumber (),
5048 true , oldTask .getTask (),
5149 oldTask .getDeadline (), allTasks .size ());
5250 allTasks .set (taskIndex , deadline );
5351 deadline .markAsDone ();
54- save .saveListToFile (command , deadline , allTasks );
5552 } else if (oldTask .getTaskType ().equals ("[E]" )) {
5653 Event event = new Event (oldTask .getTaskNumber (),
5754 true , oldTask .getTask (),
5855 oldTask .getEventStartTime (),
5956 oldTask .getEventEndTime (), allTasks .size ());
6057 allTasks .set (taskIndex , event );
6158 event .markAsDone ();
62- save .saveListToFile (command , event , allTasks );
6359 }
64- }else if (command .startsWith ("unmark" )) {
60+ } else if (command .startsWith ("unmark" )) {
6561 missingIndexException (command );
6662 invalidIndexException (command , allTasks .size ());
6763 String [] str = command .split (" " );
@@ -73,22 +69,19 @@ public void chatDuke() throws IOException {
7369 allTasks .size ());
7470 allTasks .set (taskIndex , todo );
7571 todo .unmarkAsUndone ();
76- save .saveListToFile (command , todo , allTasks );
7772 } else if (oldTask .getTaskType ().equals ("[D]" )) {
7873 Deadline deadline = new Deadline (oldTask .getTaskNumber (),
7974 false , oldTask .getTask (),
8075 oldTask .getDeadline (), allTasks .size ());
8176 allTasks .set (taskIndex , deadline );
8277 deadline .unmarkAsUndone ();
83- save .saveListToFile (command , deadline , allTasks );
8478 } else if (oldTask .getTaskType ().equals ("[E]" )) {
8579 Event event = new Event (oldTask .getTaskNumber (),
8680 false , oldTask .getTask (),
8781 oldTask .getEventStartTime (),
8882 oldTask .getEventEndTime (), allTasks .size ());
8983 allTasks .set (taskIndex , event );
9084 event .unmarkAsUndone ();
91- save .saveListToFile (command , event , allTasks );
9285 }
9386 } else if (command .startsWith ("todo" )) {
9487 emptyCommandException (command );
@@ -98,7 +91,6 @@ public void chatDuke() throws IOException {
9891 taskName , allTasks .size () + 1 );
9992 allTasks .add (todo );
10093 todo .printToDoTask ();
101- save .saveListToFile (command , todo , allTasks );
10294 } else if (command .startsWith ("deadline" )) {
10395 emptyCommandException (command );
10496 missingTimingException (command );
@@ -109,7 +101,6 @@ public void chatDuke() throws IOException {
109101 taskName , taskDeadline , allTasks .size () + 1 );
110102 allTasks .add (deadline );
111103 deadline .printDeadlineTask ();
112- save .saveListToFile (command , deadline , allTasks );
113104 } else if (command .startsWith ("event" )) {
114105 emptyCommandException (command );
115106 missingTimingException (command );
@@ -122,16 +113,14 @@ public void chatDuke() throws IOException {
122113 taskName , eventStartTime , eventEndTime , allTasks .size () + 1 );
123114 allTasks .add (event );
124115 event .printEventTask ();
125- save .saveListToFile (command , event , allTasks );
126116 } else if (command .startsWith ("delete" )) {
127117 missingIndexException (command );
128118 invalidIndexException (command , allTasks .size ());
129119 String [] str = command .split (" " );
130120 int taskIndex = Integer .parseInt (str [1 ]) - 1 ;
131121 Task task = allTasks .get (taskIndex );
132- task .printDelete (allTasks );
122+ task .printDelete ();
133123 allTasks .remove (taskIndex );
134- save .saveListToFile (command , task , allTasks );
135124 } else if (command .equals ("bye" )){
136125 saidBye = true ;
137126 this .printByeMessage ();
@@ -144,8 +133,6 @@ public void chatDuke() throws IOException {
144133 System .out .println ("\t ____________________________________________________________" +
145134 "\n \t ☹ OOPS!!! The task index to delete or un/mark a task cannot be a non-integer." +
146135 "\n \t ____________________________________________________________" );
147- } catch (IOException e ) {
148- throw new RuntimeException (e );
149136 }
150137 }
151138 }
@@ -218,19 +205,18 @@ public void missingTimingException(String command) throws DukeException {
218205 }
219206
220207 public void missingIndexException (String command ) throws DukeException {
221- switch (command ) {
222- case "mark" :
223- throw new DukeException ("\t ____________________________________________________________" +
224- "\n \t ☹ OOPS!!! The task index to mark a task as done cannot be empty." +
225- "\n \t ____________________________________________________________" );
226- case "unmark" :
227- throw new DukeException ("\t ____________________________________________________________" +
228- "\n \t ☹ OOPS!!! The task index to unmark a task as not done cannot be empty." +
229- "\n \t ____________________________________________________________" );
230- case "delete" :
231- throw new DukeException ("\t ____________________________________________________________" +
232- "\n \t ☹ OOPS!!! The task index to delete a task as not done cannot be empty." +
233- "\n \t ____________________________________________________________" );
208+ if (command .equals ("mark" )) {
209+ throw new DukeException ("\t ____________________________________________________________" +
210+ "\n \t ☹ OOPS!!! The task index to mark a task as done cannot be empty." +
211+ "\n \t ____________________________________________________________" );
212+ } else if (command .equals ("unmark" )) {
213+ throw new DukeException ("\t ____________________________________________________________" +
214+ "\n \t ☹ OOPS!!! The task index to unmark a task as not done cannot be empty." +
215+ "\n \t ____________________________________________________________" );
216+ } else if (command .equals ("delete" )) {
217+ throw new DukeException ("\t ____________________________________________________________" +
218+ "\n \t ☹ OOPS!!! The task index to delete a task as not done cannot be empty." +
219+ "\n \t ____________________________________________________________" );
234220 }
235221 }
236222
0 commit comments