22import java .util .ArrayList ;
33
44public class Duke {
5+ // ArrayList of tasks
6+ private static ArrayList <String > arrList ;
7+
58 public static void main (String [] args ) {
69 // Scanner object
710 Scanner sc = new Scanner (System .in );
811
12+ arrList = new ArrayList <>();
13+
914 // greeting
1015 greet ();
1116
@@ -14,7 +19,14 @@ public static void main(String[] args) {
1419
1520 // continue processing user's command, as long as command is not bye
1621 while (!command .equals ("bye" )) {
17- echo (command );
22+ if (command .equals ("list" )) {
23+ // prints tasks in list if command is list
24+ printList ();
25+ } else {
26+ // add task to list
27+ add (command );
28+ }
29+
1830 command = sc .nextLine ();
1931 }
2032
@@ -53,6 +65,28 @@ public static void echo(String comm) {
5365 System .out .println (" ------------------------------------------------------------" );
5466 }
5567
68+ /**
69+ * adds user's command to arrList
70+ * @param comm command given by user
71+ */
72+ public static void add (String comm ) {
73+ arrList .add (comm );
74+ System .out .println (" ------------------------------------------------------------" );
75+ System .out .println (" added: " + comm );
76+ System .out .println (" ------------------------------------------------------------" );
77+ }
78+
79+ /**
80+ * prints list of tasks user has added
81+ */
82+ public static void printList () {
83+ System .out .println (" ------------------------------------------------------------" );
84+ for (int i = 1 ; i <= arrList .size (); i ++) {
85+ System .out .println (" " + i + ". " + arrList .get (i - 1 ));
86+ }
87+ System .out .println (" ------------------------------------------------------------" );
88+ }
89+
5690 /**
5791 * exits
5892 */
0 commit comments