forked from seeditsolution/javaprogram
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathChat.java
More file actions
33 lines (29 loc) · 1.09 KB
/
Copy pathChat.java
File metadata and controls
33 lines (29 loc) · 1.09 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
import java.util.Scanner;
class Chatbot {
public static void main(String[] args) {
Scanner scanner = new Scanner(System.in);
System.out.println("Hello! How can I assist you today?");
boolean running = true;
while (running) {
String userInput = scanner.nextLine().toLowerCase();
String response = getResponse(userInput);
System.out.println(response);
if (userInput.equals("bye")) {
running = false;
}
}
System.out.println("Goodbye! Have a great day!");
scanner.close();
}
public static String getResponse(String userInput) {
if (userInput.contains("hello") || userInput.contains("hi")) {
return "Hi there!";
} else if (userInput.contains("how are you")) {
return "I'm doing well, thank you!";
} else if (userInput.contains("weather")) {
return "I'm sorry, I don't have weather information.";
} else {
return "I'm sorry, I didn't understand that. Can you please rephrase?";
}
}
}