Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.util.Scanner;
- import java.util.List;
- import java.util.ArrayList;
- public class ChatInput
- {
- /*This is simulated "Chatbot" program that is very primative.
- *Use this as an example and template for making your own Chatbot.*/
- private static Scanner input = new Scanner(System.in);
- private static Scanner input2 = new Scanner(System.in);
- private static Scanner input3 = new Scanner(System.in);
- private static Scanner input4 = new Scanner(System.in);
- private static Scanner input5 = new Scanner(System.in);
- private static Scanner input6 = new Scanner(System.in);
- private static Scanner input7 = new Scanner(System.in);
- private static String response = "";
- private static String response2 = "";
- private static String response3 = "";
- private static String response4 = "";
- private static String response5 = "";
- private static int response6 = 0;
- private static String response7 = "";
- private static int index;
- private static int index2;
- private static List<String> riddleList = new ArrayList<String>();
- private static List<String> answerList = new ArrayList<String>();
- private static int guess;
- public static void randomStuff ()
- { if(response2.indexOf("yes") >=0 || response2.indexOf("yea") >=0 || response2.indexOf("yeah") >=0)
- {
- System.out.println("Who is your best friend?");
- response3 = input3.nextLine();
- System.out.println("Tell me more about " + response3);
- }
- else if (response2.indexOf("games") >=0)
- {
- System.out.println("What kind of games do you like to play?");
- response3 = input3.nextLine();
- System.out.println("What else do you do for fun?");
- }
- else if (response2.indexOf("movies") >=0)
- {
- System.out.println("What is your favorite movie?");
- response3 = input3.nextLine();
- System.out.println("I like that movie too! My favorite is Good Will Hunting");
- }
- else if (response2.indexOf("play") >=0)
- {
- System.out.println("What sports do you play?");
- response3 = input3.nextLine();
- System.out.println("What is your favorite professional sport?");
- response4 = input4.nextLine();
- System.out.println("Who is your favorite player?");
- response5 = input5.nextLine();
- System.out.println("Mine too! We have a lot in common, great talking with you. Let's chat again soon!");
- }
- else if (response2.indexOf("shop") >=0)
- {
- System.out.println("I'm not a big fan of shopping but my finance likes to shop!");
- }
- else if (response2.indexOf("sleep") >=0)
- {
- System.out.println("Me too! Sleeping is very important, great for recovery of the mind and body!");
- System.out.println("How many hours of sleep do you get each night?");
- response6 = input6.nextInt();
- if (response6 <= 6)
- {
- System.out.println("That's not enough sleep!");
- }
- else if (response6 == 6 || response6 ==7)
- {
- System.out.println("That's a decent amount but you should try to get 8 or more hours each night");
- }
- else if (response6 >= 8)
- {
- System.out.println("That's excellent, you must be well rested!");
- }
- else
- System.out.println("Did you enter a number?? i.e. 1-10??");
- }
- else
- {
- System.out.println("Great let's talk some more! Tell me about your family.");
- }
- }//ends method
- public static void getQuestion()
- {
- riddleList.add("What can you catch but not throw?");
- riddleList.add("The more you take, the more you leave behind. What am I?");
- riddleList.add("What belongs to you, but other people use it more than you?");
- riddleList.add("What has many keys, but can't even open a single door?");
- riddleList.add("What is more useful when it is broken?");
- String question = riddleList.get(index);
- System.out.println(question);
- }
- public static void getAnswer()
- {
- answerList.add("a cold");
- answerList.add("footsteps");
- answerList.add("your name");
- answerList.add("a piano");
- answerList.add("an egg");
- String answer = answerList.get(index);
- System.out.println(answer);
- }
- public static void main (String[] args)
- {
- index = (int)(Math.random()*6);
- index2 = (int)(Math.random()*10);
- int guess = 3;
- /*Each input variable creates a line in the console that allows
- *the program to "scan" +it or be read.
- *Each response is then stored in a variable, many of which have been
- *named with some variation of response. */
- System.out.println("Please use all lowercase letter's in your responses.");
- //The users response will be stored int the response variable
- System.out.println("Welcome, I'm Chatbot! What's your name?");
- response = input.nextLine();
- System.out.println("Hello, " + response + ", would you like to play a game?");
- response2 = input2.nextLine();
- /*You can use as many complex conditionals as you like,
- *the more you use the more comprehensive you program might be.
- *Notice the complex conditional looks for the String no, bad, terrible, or sick.
- *If one or more of those words is found the "chatbot" will respond by saying "Why so negative..."*/
- /*You can use nested conditionals and loops to make your chatbot more extensive */
- if (response2.indexOf("no") >=0 || response2.indexOf("no thank you") >=0 || response2.indexOf("nah") >=0)
- {
- System.out.println("Are you sure?") ;
- System.out.println("The game will be very fun!");
- response3 = input.nextLine();
- if (response3.indexOf("no") >=0 || response3.indexOf("no thank you") >=0 || response3.indexOf("yes") >=0)
- {
- System.out.println("Okay, have a good day " + response);
- }
- }
- else if (response2.indexOf("yes") >=0 || response2.indexOf("yea") >=0 || response2.indexOf("yeah") >=0 || response2.indexOf("sure") >=0 || response2.indexOf("ok") >=0 || response2.indexOf("okay")>=0 || response2.indexOf("alright")>=0)
- {
- System.out.println("There are a few rules before we begin. You must follow them for our game to run as smoothly as possible.");
- System.out.println("Rule 1: Use all lowercase letters in your responses.");
- System.out.println("Rule 2: You have three guesses.");
- System.out.println("Rule 3: Have fun!!!.");
- System.out.println("Are you ready?");
- response3 = input2.nextLine();
- if(response3.indexOf("yes") >=0 || response3.indexOf("yea") >=0 || response3.indexOf("yeah") >=0 || response3.indexOf("sure") >=0 || response3.indexOf("ok") >=0 || response3.indexOf("okay")>=0 || response3.indexOf("alright")>=0)
- {
- getQuestion();
- response3 = input2.nextLine();
- if(response3.equals(answerList.get(index)))
- {
- System.out.println("Correct!");
- }
- else
- {
- while(guess < 3)
- {
- if(guess == 2)
- {
- System.out.println("You have 2 guesses left.");
- }
- else if(guess == 1)
- {
- System.out.println("You have 1 guesses left.");
- }
- else
- {
- System.out.println("You lost AHAHHA");
- }
- }
- }
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement