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