// Java Fortune teller import java.util.*; import java.awt.*; public class Fortune { public static void main(String[] args) { Random rand = new Random(); Scanner console = new Scanner(System.in); DrawingPanel panel = new DrawingPanel(300,300); System.out.println("The Great Espresso Bean Fortune Teller is at your service!"); System.out.print("You may type your first question now: "); String question = console.nextLine(); while (question.length()>0) { tellFortune(rand, question, panel); System.out.print("You may ask another question: "); question = console.nextLine(); } System.out.println("The Great Espresso Bean Fortune Teller has spoken. Good bye."); } public static void tellFortune(Random rand, String question, DrawingPanel panel) { Graphics g = panel.getGraphics(); System.out.println("You dare to ask \"" + question + "\"?!??"); System.out.print("I am pondering "); // print a period and draw some circles to keep the user entertained .... for (int i=1; i<=3; i++) { System.out.print(" ."); for (int j=0; j<26; j++) { Color c = new Color(0,0,10*j); g.setColor(c); g.fillOval(150-5*j,150-5*j,10*j,10*j); panel.sleep(100); // wait 1/10 second } } System.out.println(); int r = rand.nextInt(4); if (r==0) { System.out.println("It is certain."); } else if (r==1) { System.out.println("Signs point to yes."); } else if (r==2) { System.out.println("Definitely not!"); } else { System.out.println("Check back later ..."); } } }