-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathAIChatbot.java
More file actions
60 lines (41 loc) · 1.49 KB
/
Copy pathAIChatbot.java
File metadata and controls
60 lines (41 loc) · 1.49 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
import java.util.Scanner;
public class AIChatbot {
static String getResponse(String msg) {
switch (msg.toLowerCase().trim()) {
case "hello":
case "hi":
case "hey":
return "Hello! How are you?";
case "how are you":
return "I'm doing great! Thanks for asking.";
case "what is your name":
return "I'm a simple Java chatbot.";
case "what can you do":
return "I can respond to a few predefined messages.";
case "thank you":
case "thanks":
return "You're welcome!";
case "bye":
case "exit":
return "Goodbye! Have a great day.";
default:
return "Sorry, I don't understand that yet.";
}
}
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
System.out.println("========== JAVA CHATBOT ==========");
System.out.println("Type 'bye' or 'exit' to end the chat.");
while (true) {
System.out.print("\nYou: ");
String msg = sc.nextLine();
String response = getResponse(msg);
System.out.println("Bot: " + response);
if (msg.equalsIgnoreCase("bye") ||
msg.equalsIgnoreCase("exit")) {
break;
}
}
sc.close();
}
}