/* * LuckTesterOmen.java * * Created on January 12, 2003, 4:31 PM */ package project1; /** The omen produced by a LuckTester oracle. * * @author dickey/143 02au */ public class LuckTesterOmen implements IOmen { private String evaluationMessage = ""; //String summarizing the result. private int value = -1; //# of trials before the requested string was found. /** Creates a new instance of LuckTesterOmen */ public LuckTesterOmen(int value, String message) { this.value = value; this.evaluationMessage = message; } /** Compare this omen with another omen to determine which is more favorable. * For this particular omen, lower values are better than higher values. * @param otherOmen another omen, assumed to be of the same type as this one. * @return An integer telling the result of the comparison: * returns a negative value if this omen is less favorable than the other; * returns 0 if the two omens are equally favorable; * returns a positive value if this omen is more favorable. */ public int compareTo(IOmen otherOmen) { LuckTesterOmen otherLTOmen = (LuckTesterOmen) otherOmen; assert this.value >= 0 && otherLTOmen.value >= 0; if (this.value > otherLTOmen.value) { return -1; } if (this.value == otherLTOmen.value) { return 0; } assert this.value < otherLTOmen.value; return 1; //end compareTo } /** Explain briefly the interpretation of the omen. * @return a string with no leading or trailing whitespace. The string * should be fairly short (say, < 40 characters). */ public String interpretBriefly() { return "[" + this.value + "] " + this.evaluationMessage; } /** Explain the interpretation of the omen. * @return a string with no leading or trailing whitespace. The string * may be of any length, but individual lines within the string * should not be longer than about 80 characters. It is perfectly * fine for this method to return the same value as interpretBriefly(), * if the full interpretation is quite short. It is perfectly fine * for this method to return the same value as toString(), if the * information is appropriate. */ public String interpretInDetail() { return this.interpretBriefly(); } public String toString() { String retString = ""; retString = "Luck Tester Omen: " + this.interpretInDetail(); return retString; } }