1+ import duke .pack .Task ;
2+
13import java .util .Scanner ;
24import java .util .ArrayList ;
35
46public class Duke {
57 // ArrayList of tasks
6- private static ArrayList <String > arrList ;
8+ private static ArrayList <Task > arrList ;
79
810 public static void main (String [] args ) {
911 // Scanner object
@@ -19,12 +21,21 @@ public static void main(String[] args) {
1921
2022 // continue processing user's command, as long as command is not bye
2123 while (!command .equals ("bye" )) {
24+ String [] c = command .split (" " );
25+
2226 if (command .equals ("list" )) {
2327 // prints tasks in list if command is list
2428 printList ();
29+
30+ } else if (c [0 ].equals ("done" )){
31+ // mark the specified task as done
32+ int taskNum = Integer .parseInt (c [1 ]);
33+ arrList .get (taskNum - 1 ).markAsDone ();
34+
2535 } else {
2636 // add task to list
27- add (command );
37+ Task t = new Task (command );
38+ add (t );
2839 }
2940
3041 command = sc .nextLine ();
@@ -67,12 +78,12 @@ public static void echo(String comm) {
6778
6879 /**
6980 * adds user's command to arrList
70- * @param comm command given by user
81+ * @param t command given by user
7182 */
72- public static void add (String comm ) {
73- arrList .add (comm );
83+ public static void add (Task t ) {
84+ arrList .add (t );
7485 System .out .println (" ------------------------------------------------------------" );
75- System .out .println (" added: " + comm );
86+ System .out .println (" added: " + t );
7687 System .out .println (" ------------------------------------------------------------" );
7788 }
7889
@@ -81,6 +92,8 @@ public static void add(String comm) {
8192 */
8293 public static void printList () {
8394 System .out .println (" ------------------------------------------------------------" );
95+ System .out .println (" Here are your tasks:" );
96+
8497 for (int i = 1 ; i <= arrList .size (); i ++) {
8598 System .out .println (" " + i + ". " + arrList .get (i - 1 ));
8699 }
0 commit comments