// Arup Guha 
// Example of a first class for
// AP Computer Science Class
// 10/6/09

import java.util.*;

public class MagicEightBall {

	// My Magic Eight Ball consists of a Random object and four answer strings.
	// Note: We will improve this later when we learn about arrays.	
	private Random r;
	private String answer1;
	private String answer2;
	private String answer3;
	private String answer4;
	
	// My default constructor - the class gave me these default answers.
	public MagicEightBall() {
		r = new Random();
		answer1 = "YES";
		answer2 = "NO";
		answer3 = "TRY AGAIN";
		answer4 = "WATCH OUT FOR THE NINJA ATTACK!";
	}
	
	// This allows the user to set the four answers on the Magic Eight Ball.
	public MagicEightBall(String a1, String a2, String a3, String a4) {
		r = new Random();
		answer1 = a1;
		answer2 = a2;
		answer3 = a3;
		answer4 = a4;
	}
	
	// Returns the answer to a question.
	public String getAnswer() {
		
		// Create a random int in between 0 and 3, inclusive.
		int choice = Math.abs(r.nextInt())%4;
		
		// Based on this int, return the appropriate answer from the Eight Ball.
		if (choice == 0)
			return answer1;
		else if (choice == 1)
			return answer2;
		else if (choice == 3)
			return answer3;
		else
			return answer4;
	}
	
	public static void main(String[] args) {
		
		Scanner stdin = new Scanner(System.in);
		MagicEightBall mine;
		
		// Determine which type of Eight Ball will be created.
		System.out.println("Would you like the default Magic Eight Ball?");
		String answer = stdin.next();
		
		// We create our default Eight Ball, no user information needed.
		if (answer.toLowerCase().charAt(0) == 'y') {
			mine = new MagicEightBall();
		}
		
		// The user will help us customize her Magic Eight Ball.
		else {
			
			System.out.println("You have elected to create your own Magic Eight Ball.");
			System.out.println("It must have exactly four possible answers on it.");
			
			// Get each of the four possible answers from the user.
			System.out.println("What is the first answer, no spaces please?");
			String first = stdin.next();
			System.out.println("What is the second answer, no spaces please?");
			String second = stdin.next();
			System.out.println("What is the third answer, no spaces please?");
			String third = stdin.next();
			System.out.println("What is the fourth answer, no spaces please?");
			String fourth = stdin.next();
			
			// Now we are ready to build the customized Magic Eight Ball =)
			mine = new MagicEightBall(first, second, third, fourth);	
		}
		
		// Let's finally use it!
		System.out.println("Would you like to ask a question?");
		answer = stdin.next();
		
		// Continue so long as the user has queries.
		while (answer.toLowerCase().charAt(0) == 'y') {
			
			// Give the user time to think of a question before proceeding.
			System.out.println("Think of a question in your head to ask.");
			System.out.println("When you are done, type in done and hit the enter key.");
			stdin.next();
			
			// Give them their answer, ta da!!!
			System.out.println("Your answer is: "+mine.getAnswer());
			
			// Let's see if they want to ask another question.
			System.out.println("Would you like to ask another question?");
			answer = stdin.next();
		}
		
	}
	
}