-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathSimpleChatBot.java
39 lines (31 loc) · 1.21 KB
/
SimpleChatBot.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
import java.util.Scanner;
public class SimpleChatBot {
public static void main(String[] args) {
Scanner scanner = new Scanner(System.in);
String userInput;
String response;
System.out.println("Como posso ajudar você hoje?");
while (true) {
System.out.print("Você: ");
userInput = scanner.nextLine().toLowerCase();
if (userInput.equals("sair")) {
System.out.println("ChatBot: Adeus! Tenha um ótimo dia!");
break;
}
response = getResponse(userInput);
System.out.println("ChatBot: " + response);
}
scanner.close();
}
private static String getResponse(String input) {
if (input.contains("olá") || input.contains("oi")) {
return "Olá! Como posso ajudar você?";
} else if (input.contains("clima") || input.contains("tempo")) {
return "O clima está ótimo.";
} else if (input.contains("obrigado") || input.contains("valeu")) {
return "De nada! Se precisar de mais alguma coisa, é só falar.";
} else {
return "Desculpe, não entendi. Pode reformular sua pergunta?";
}
}
}