Skip to content

Commit

Permalink
Level-2
Browse files Browse the repository at this point in the history
Completed Level 2:
Add, List
  • Loading branch information
gachia committed Aug 21, 2019
1 parent b6920e0 commit eeb23ea
Showing 1 changed file with 20 additions and 4 deletions.
24 changes: 20 additions & 4 deletions src/main/java/Duke.java
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import java.util.Scanner;
import java.util.ArrayList;

public class Duke {
public static void main(String[] args) {
Expand All @@ -8,16 +9,31 @@ public static void main(String[] args) {
+ "| |_| | |_| | < __/\n"
+ "|____/ \\__,_|_|\\_\\___|\n";
System.out.println("Hello from\n" + logo);
final String lineSpace = "_______________________________";
String startMessage = lineSpace + "\nHello! I'm Duke\nWhat can I do for you?" + lineSpace;
final String lineSpace = "_______________________________\n";
String startMessage = lineSpace + "Hello! I'm Duke\nWhat can I do for you?\n" + lineSpace;
System.out.println(startMessage);
Scanner sc = new Scanner(System.in);
ArrayList<String> list = new ArrayList();
while(sc.hasNext()){
String userInput = sc.nextLine();
if(userInput.equals("bye")){
System.out.println(lineSpace + "\nBye. Hope to see you again soon!\n" + lineSpace);
System.out.println(lineSpace + "Bye. Hope to see you again soon!\n" + lineSpace);
break;
}
System.out.println(lineSpace + "\n" + userInput + "\n" + lineSpace);
switch(userInput) {
case "list":
System.out.print(lineSpace);
for(int i=0; i < list.size(); i++){
System.out.println(i+1 + ". " + list.get(i));
}
System.out.print(lineSpace);
break;
default:
list.add(userInput);
System.out.println(lineSpace + "added: " + userInput + "\n" + lineSpace);
//Level-1 code
//System.out.println(lineSpace + "\n" + userInput + "\n" + lineSpace);
}
}

}
Expand Down

0 comments on commit eeb23ea

Please sign in to comment.