/* * RandCharsModel.java ------------------ starter code version -------------------- * * Created on February 5, 2003, 5:06 PM */ package randchars; import MDUtils.*; /** Maintain a list of randomly generated characters. * * @author dickey 2/2003 */ public class RandCharsModel implements IPublicInformation { ///------------- you will need to define some instance variables /** The first and last characters of the block of Unicode characters, * within which the random selection is made. */ char firstCharInRange, lastCharInRange; /** Object id -- incremented by 1 for each object. */ private static char OBid = 'a'; /** Creates a new instance of RandCharsModel. NOTE: comments modified 2/7/2003. * @param firstChar The first character of a range within which (inclusive) * the random characters will be generated. * @param lastChar The last character of the range. */ public RandCharsModel(char firstChar, char lastChar) { // ------------------------ do some stuff ---------------------- this.OBid ++; } /** Generate a random character, between the limits set earlier, * and remember it at the end of the list. */ public void randomlyAddChar() { //-------------------- implement this method -------------------- //end randomlyAddChar } /** Tells a small amount of author information. * @return a "short string" identifying the author(s) * of the class. * **** IF YOU DO NOT WISH TO BE PUBLICALLY IDENTIFIED, return a pseudonym or * code name. */ public String getAuthor() { return "anonymous"; } /** Return a preferred color for the object. Colors might be used by * clients to set a background color, a border color, etc. * @return A Color, or null if there is no preferred color. */ public java.awt.Color getColor() { return java.awt.Color.cyan; } /** Gives a URL to an image representing this class. * @return a string which is a full URL to a .jpg or .gif file. The * image is expected to in some way stand for or depict the class. It * is acceptable to return null. */ public String getImageURLString() { String[] images = {"http://www.cs.washington.edu/images/sptm133.jpg", "http://lazowska.cs.washington.edu/sieg/siegfrontsm.jpg", "http://www.cs.washington.edu/images/cse_logo_133.gif" }; int iCount = images.length; int index = (int) (images.length * Math.random()); assert index >= 0 && index < images.length; String istring = images[index]; //return istring; return "http://www.unicode.org/img/globe_iuc23.gif"; //return "C:\\DELL\\DOCS\\Bedirect.jpg"; } /** Return a "long string" describing the object or how to use it. */ public String getInstructions() { return null; } /** Tell the name of this class (or better, what this class represents). * @return A short string with the name of the oracle; there should be * no leading or trailing whitespace. The same value should be returned * for all objects of this type (a "static final" instance variable would * help to enforce this). * */ public String getName() { return "Ouija Character Generator"; } /** Return a "long string" describing this object. The description might * be the same for all objects of the type. */ public String getObjectDescription() { return "Ouija Board Character Generator. The characters will be " + "in the range from " + this.firstCharInRange + " (" + charUnicodeID (firstCharInRange)+ ")" + " to " + this.lastCharInRange + " (" + charUnicodeID(lastCharInRange) + ")"; } /** Generate a string identifying the unicode hex value and block of the char. * @return a string containing the identifying information, with no leading * or trailing spaces, and not containing the character itself. */ public static String charUnicodeID(char c) { String retString = "u" + Integer.toHexString((int) c) + " in Unicode " + Character.UnicodeBlock.of(c) + " block"; return retString; } /** Return a short string identifying this object. The object name should * be unique for each object instantiated. */ public String getObjectName() { return "Ouija Char Gen #" + OBid; } // end class RandCharsModel }