Skip to content

Commit 913d8dd

Browse files
committed
Level 1. Greet, Echo & Exit
1 parent fae28ab commit 913d8dd

File tree

1 file changed

+52
-6
lines changed

1 file changed

+52
-6
lines changed

src/main/java/Duke.java

Lines changed: 52 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,56 @@
1+
import java.util.Scanner;
2+
13
public class Duke {
24
public static void main(String[] args) {
3-
String logo = " ____ _ \n"
4-
+ "| _ \\ _ _| | _____ \n"
5-
+ "| | | | | | | |/ / _ \\\n"
6-
+ "| |_| | |_| | < __/\n"
7-
+ "|____/ \\__,_|_|\\_\\___|\n";
8-
System.out.println("Hello from\n" + logo);
5+
// Scanner object
6+
Scanner sc = new Scanner(System.in);
7+
8+
// greeting
9+
greet();
10+
11+
// take in user's command
12+
String command = sc.nextLine();
13+
14+
// continue processing user's command, as long as command is not bye
15+
while (!command.equals("bye")) {
16+
echo(command);
17+
command = sc.nextLine();
18+
}
19+
20+
// exit
21+
exit();
22+
}
23+
24+
// prints greeting to user
25+
public static void greet() {
26+
System.out.println(" ------------------------------------------------------------");
27+
28+
// logo obtained using https://www.kammerl.de/ascii/AsciiSignature.php
29+
String logo = " __ __ _ _ _ \n" +
30+
" | \\/ | | | | | | \n" +
31+
" | \\ / | |__ ___ | |_ | |_ __ \n" +
32+
" | |\\/| | '_ \\ / _ \\| __| _ | | '__|\n" +
33+
" | | | | |_) | (_) | |_ | |__| | | \n" +
34+
" |_| |_|_.__/ \\___/ \\__| \\____/|_| \n" +
35+
"\n";
36+
37+
System.out.println(logo);
38+
System.out.println(" Hello, I'm Mbot Jr!\n" +
39+
" How may I help you?");
40+
System.out.println(" ------------------------------------------------------------");
41+
}
42+
43+
// echos user's command
44+
public static void echo(String comm) {
45+
System.out.println(" ------------------------------------------------------------");
46+
System.out.println(" " + comm);
47+
System.out.println(" ------------------------------------------------------------");
48+
}
49+
50+
// exits
51+
public static void exit() {
52+
System.out.println(" ------------------------------------------------------------");
53+
System.out.println(" See you later!");
54+
System.out.println(" ------------------------------------------------------------");
955
}
1056
}

0 commit comments

Comments
 (0)