-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathChattyBot
More file actions
71 lines (62 loc) · 2.35 KB
/
ChattyBot
File metadata and controls
71 lines (62 loc) · 2.35 KB
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
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
package bot;
import java.util.Scanner;
public class SimpleBot {
final static Scanner scanner = new Scanner(System.in);
public static void main(String[] args) {
greet("Aid", "2020");
remindName();
guessAge();
count();
test();
}
static void greet(String assistantName, String birthYear) {
System.out.println("Hello! My name is " + assistantName + ".");
System.out.println("I was created in " + birthYear + ".");
System.out.println("Please, remind me your name.");
}
static void remindName() {
String name = scanner.nextLine();
System.out.println("What a great name you have, " + name + "!");
}
static void guessAge() {
System.out.println("Let me guess your age.");
System.out.println("Say me remainders of dividing your age by 3, 5 and 7.");
int rem3 = scanner.nextInt();
int rem5 = scanner.nextInt();
int rem7 = scanner.nextInt();
int age = (rem3 * 70 + rem5 * 21 + rem7 * 15) % 105;
System.out.println("Your age is " + age + "; that's a good time to start programming!");
}
static void count() {
System.out.println("Now I will prove to you that I can count to any number you want.");
int num = scanner.nextInt();
for (int i = 0; i <= num; i++) {
System.out.printf("%d!\n", i);
}
}
static void test() {
System.out.println("Let's test your programming knowledge.");
// write your code here
System.out.println("Select a correct example of the conditional statement.");
String a = "1. if (i < j) then System.out.print('Hello!');";
String b = "2. if {i < j} then System.out.print('Hello!');";
String c = "3. if (i < j) { System.out.print('Hello!'); }";
String d = "4. if i < j { System.out.print('Hello!'); }";
int answer = scanner.nextInt();
switch(answer) {
case 1:
System.out.println ("Please, try again.");
case 2:
System.out.println ("Please, try again.");
case 3:
end();
break;
case 4:
System.out.println ("Please, try again.");
default:
}
}
static void end() {
System.out.println("Congratulations, have a nice day!");
}
}