Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.util.Random;
- import java.util.Scanner;
- public class Script{
- private static final Random randomNum = new Random();
- private static Scanner userInput = new Scanner(System.in);
- private static int randomResponse = 1 + randomNum.nextInt(10);
- public static void main(String args[]){
- String userQuestion = "";
- System.out.println("Please ask the Magic 8-Ball a question, and it will give you a response.\n");
- System.out.print("Magic 8-ball...");
- userQuestion = userInput.nextLine();
- System.out.printf("\n%s", determineResponse());
- }
- private static String determineResponse(){
- String response = "";
- switch(randomResponse){
- case 1:
- response = "It is certain.";
- break;
- case 2:
- response = "Reply hazy, try again.";
- break;
- case 3:
- response = "Don't count on it.";
- break;
- case 4:
- response = "It is decidedly so";
- break;
- case 5:
- response = "Ask again later.";
- break;
- case 6:
- response = "My reply is no.";
- break;
- case 7:
- response = "Without a doubt.";
- break;
- case 8:
- response = "Better not tell you now";
- break;
- case 9:
- response = "Outlook not so good.";
- break;
- case 10:
- response = "Most likely.";
- break;
- }
- return response;
- }
- }
Add Comment
Please, Sign In to add comment