public class Oracle
1:
2: import java.util.Scanner;
3:
4: public class Oracle
5: {
6: private String oldAnswer = "The answer is in your heart.";
7: private String newAnswer;
8: private String question;
9:
10: public void chat( )
11: {
12: System.out.print("I am the oracle. ");
13: System.out.println("I will answer any one-line question.");
14: Scanner keyboard = new Scanner(System.in);
15: String response;
16: do
17: {
18: answer( );
19: System.out.println("Do you wish to ask another question?");
20: response = keyboard.next( );
21: } while (response.equalsIgnoreCase("yes"));
22: System.out.println("The oracle will now rest.");
23: }
24:
25: private void answer( )
26: {
27: System.out.println("What is your question?");
28: Scanner keyboard = new Scanner(System.in);
29: question = keyboard.nextLine();
30: seekAdvice( );
31: System.out.println("You asked the question:");
32: System.out.println(" " + question);
33: System.out.println("Now, here is my answer:");
34: System.out.println(" " + oldAnswer);
35: update( );
36: }
37:
38: private void seekAdvice( )
39: {
40: System.out.println("Hmm, I need some help on that.");
41: System.out.println("Please give me one line of advice.");
42: Scanner keyboard = new Scanner(System.in);
43: newAnswer = keyboard.nextLine();
44: System.out.println("Thank you. That helped a lot.");
45: }
46:
47: private void update( )
48: {
49: oldAnswer = newAnswer;
50: }
51: }