1+ import java .io .FileNotFoundException ;
12import java .util .Scanner ;
23import java .util .ArrayList ;
4+ import java .io .IOException ;
5+
36
47public class Duke {
5- public static void main ( String [] args ) {
8+ public void run () throws IOException {
69 Scanner sc = new Scanner (System .in );
710 System .out .println ("Hello! I'm Duke\n " +"What can I do for you?" );
8- ArrayList <Task > listOfItems = new ArrayList < Task > ();
11+ ArrayList <Task > listOfItems = FileReader . loadTaskFromFile ();
912 String echo = sc .nextLine ();
1013 while (!echo .equals ("bye" )) {
1114 try {
@@ -34,7 +37,7 @@ else if (tempArray[0].equals("done")) {
3437 if (tempArray .length == 1 ) {
3538 throw new InvalidTodoException ();
3639 }
37- Todo newTodo = new Todo (echo .substring (5 ));
40+ Todo newTodo = new Todo (echo .substring (5 ), false );
3841 listOfItems .add (newTodo );
3942 System .out .println ("Got it. I've added this task:\n " + newTodo .toString () +
4043 "\n Now you have " + listOfItems .size () + " tasks in total" );
@@ -45,7 +48,7 @@ else if (tempArray[0].equals("deadline")) {
4548 throw new InvalidDeadlineException ();
4649 }
4750 String [] tempString = echo .substring (9 ).split (" /by" );
48- Deadline newDeadline = new Deadline (tempString [0 ], tempString [1 ]);
51+ Deadline newDeadline = new Deadline (tempString [0 ], false , tempString [1 ]);
4952 listOfItems .add (newDeadline );
5053 System .out .println ("Got it. I've added this task:\n " + newDeadline .toString ()
5154 + "\n Now you have " + listOfItems .size () + " tasks in total" );
@@ -56,7 +59,7 @@ else if (tempArray[0].equals("event")) {
5659 throw new InvalidEventException ();
5760 }
5861 String [] tempString = echo .substring (7 ).split (" /at" );
59- Event newEvent = new Event (tempString [0 ], tempString [1 ]);
62+ Event newEvent = new Event (tempString [0 ], false , tempString [1 ]);
6063 listOfItems .add (newEvent );
6164 System .out .println ("Got it. I've added this task:\n " + newEvent .toString ()
6265 + "\n Now you have " + listOfItems .size () + " tasks in total" );
@@ -71,6 +74,16 @@ else if (tempArray[0].equals("event")) {
7174 }
7275 echo = sc .nextLine ();
7376 }
77+ FileReader .writeToFile (listOfItems );
7478 System .out .println ("Bye. Hope to see you again soon!" );
7579 }
80+
81+ public static void main (String [] args ){
82+ try {
83+ Duke duke = new Duke ();
84+ duke .run ();
85+ } catch (IOException e ){
86+ System .out .println (e );
87+ }
88+ }
7689}
0 commit comments