-
Notifications
You must be signed in to change notification settings - Fork 0
/
Greeter.java
43 lines (32 loc) · 1.18 KB
/
Greeter.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
////////// Instructions //////////
///// If /////
// Write a program that greets the user by name and then asks them to make a choice between two options.
// Respond differently to each choice.
import java.util.Scanner;
public class Greeter {
public static void main(String[] args) {
System.out.println("Welcome to the greeter!\n");
try {
Thread.sleep(1000);
}
catch (InterruptedException e) {
e.printStackTrace();
}
Scanner nameInput = new Scanner(System.in);
System.out.println("\nWhat is your name?");
String name = nameInput.nextLine();
// Greeter
System.out.printf("\nHello, %s! How has your day been today?\n1: Good\n2: Bad\n", name);
Scanner responseInput = new Scanner(System.in);
int response = responseInput.nextInt();
if (response == 1) {
System.out.println("\nThat's awesome! Have a great rest of your day, and make sure to do something fun!");
}
else if (response == 2) {
System.out.println("\nWe all have bad days sometimes, I hope your day gets better though.");
}
else {
System.out.println("Please respond only with integers 1 or 2.\nRun this program again.");
}
}
}