Fortune.java

/**
 *  Apple Worldwide Developer Technical Support
 *
 *  Sample demonstrating AppleScript for Java.
 *
 *  by Michael Hopkins, Apple Developer Technical Support
 *
 *  File:   Fortune.java
 *
 *  Copyright ©1999 Apple Computer, Inc.
 *  All rights reserved.
 *
 *  4/99    v. 1.0  Shipped as 'Magic Oracle AppleScript for Java' sample.
 *
 *  You may incorporate this sample code into your applications without
 *  restriction, though the sample code has been provided "AS IS" and the
 *  responsibility for its operation is 100% yours.  However, what you are
 *  not permitted to do is to redistribute the source as "Apple Sample
 *  Code" after having made changes. If you're going to re-distribute the
 *  source, we require that you make it clear in the source that the code
 *  was descended from Apple Sample Code, but that you've made changes.
**/
 
import java.util.Vector;
import java.util.Random;
 
 
/**
 * A class by the Magic Oracle application used to retrieve string responses to questions
 * It is important that the order of the elements and the strings match the order and 
 * contents of the images used to display the fortunes
 * @version 1.0, April 9, 1999
 * @author Michael Hopkins, Worldwide Developer Technical Support, Apple Computer Inc.
 **/
 
public class Fortune extends java.lang.Object
{
    public Fortune()
    {
        fortunes.addElement( "Answer hazy, try back later." );  // image5
        fortunes.addElement( "Ask again later." );              // image6
        fortunes.addElement( "It is hard to say." );            // image7
        fortunes.addElement( "It doesn't look good." );         // image8
        fortunes.addElement( "My sources say No." );            // image9
        fortunes.addElement( "Probably not." );                 // image10
        fortunes.addElement( "Outlook not so good." );          // image11
        fortunes.addElement( "Don't count on it." );            // image12
        fortunes.addElement( "NO" );                            // image13
        fortunes.addElement( "Who cares?" );                    // image14
        fortunes.addElement( "It appears to be." );             // image15
        fortunes.addElement( "Signs point to yes." );           // image16
        fortunes.addElement( "YES." );                          // image17
        fortunes.addElement( "Count on it." );                  // image18
        fortunes.addElement( "Definately so." );                // image19
        fortunes.addElement( "It is the case." );               // image20
        fortunes.addElement( "It could be." );                  // image21
        fortunes.addElement( "Outlook good." );                 // image22
        fortunes.addElement( "Sources say yes." );              // image23
        fortunes.addElement( "Signs point to no." );            // image24
    }
    
    /**
     * Generates a response number between 1 and the number of responses 
     * (entry into reponse vector)
     * @return integer response number 
     */
    public int generateResponseNum()
    {
        double temp = generator.nextDouble();
        int size = fortunes.size();
        int result = (int) ((temp * 100) % size);
        response = (String) fortunes.elementAt( result );
        return result;
    }
    
    /**
     * Generates a response as a string based on the generated response number
     * @return String response as a string 
     */
    public String getResponse()
    {
        return response;
    }
    
    protected Vector fortunes = new Vector();
    protected Random generator= new Random();
    protected String response= "";
    
}