001: /*
002: * Copyright (c) 2007, Sun Microsystems, Inc.
003: * All rights reserved.
004: *
005: * Redistribution and use in source and binary forms, with or without
006: * modification, are permitted provided that the following conditions are met:
007: *
008: * * Redistributions of source code must retain the above copyright notice,
009: * this list of conditions and the following disclaimer.
010: * * Redistributions in binary form must reproduce the above copyright
011: * notice, this list of conditions and the following disclaimer in
012: * the documentation and/or other materials provided with the distribution.
013: * * Neither the name of Sun Microsystems, Inc. nor the names of its
014: * contributors may be used to endorse or promote products derived
015: * from this software without specific prior written permission.
016: *
017: * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
018: * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
019: * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
020: * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
021: * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
022: * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED
023: * TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
024: * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
025: * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
026: * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
027: * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
028: */
029:
030: /* Anagram Game Application */
031:
032: package com.toy.anagrams.lib;
033:
034: /**
035: * Logic for the Anagram Game application.
036: */
037: public final class WordLibrary {
038:
039: private static final String[] WORD_LIST = { "abstraction",
040: "ambiguous", "arithmetic", "backslash", "bitmap",
041: "circumstance", "combination", "consequently",
042: "consortium", "decrementing", "dependency", "disambiguate",
043: "dynamic", "encapsulation", "equivalent", "expression",
044: "facilitate", "fragment", "hexadecimal", "implementation",
045: "indistinguishable", "inheritance", "internet", "java",
046: "localization", "microprocessor", "navigation",
047: "optimization", "parameter", "patrick", "pickle",
048: "polymorphic", "rigorously", "simultaneously",
049: "specification", "structure", "lexical", "likewise",
050: "management", "manipulate", "mathematics", "hotjava",
051: "vertex", "unsigned", "traditional" };
052:
053: private static final String[] SCRAMBLED_WORD_LIST = {
054: "batsartcoin", "maibuguos", "ratimhteci", "abkclssha",
055: "ibmtpa", "iccrmutsnaec", "ocbmnitaoni", "ocsnqeeutnyl",
056: "ocsnroitmu", "edrcmeneitgn", "edepdnneyc", "idasbmgiauet",
057: "ydanicm", "neacsplutaoni", "qeiuaveltn", "xerpseisno",
058: "aficilatet", "rfgaemtn", "ehaxedicalm", "milpmeneatitno",
059: "niidtsniugsiahleb", "niehiratcen", "nietnret", "ajav",
060: "olacilazitno", "imrcpoorecssro", "anivagitno",
061: "poitimazitno", "aparemert", "aprtcki", "ipkcel",
062: "opylomprich", "irogorsuyl", "isumtlnaoesuyl",
063: "psceficitaoni", "tsurtcreu", "elixalc", "ilekiwse",
064: "amanegemtn", "aminupalet", "amhtmetacsi", "ohjtvaa",
065: "evtrxe", "nuisngde", "rtdatioialn" };
066:
067: /**
068: * Singleton class.
069: */
070: private WordLibrary() {
071: }
072:
073: /**
074: * Gets the word at a given index.
075: * @param idx index of required word
076: * @return word at that index in its natural form
077: */
078: public static String getWord(int idx) {
079: return WORD_LIST[idx];
080: }
081:
082: /**
083: * Gets the word at a given index in its scrambled form.
084: * @param idx index of required word
085: * @return word at that index in its scrambled form
086: */
087: public static String getScrambledWord(int idx) {
088: return SCRAMBLED_WORD_LIST[idx];
089: }
090:
091: /**
092: * Gets the number of words in the library.
093: * @return the total number of plain/scrambled word pairs in the library
094: */
095: public static int getSize() {
096: return WORD_LIST.length;
097: }
098:
099: /**
100: * Checks whether a user's guess for a word at the given index is correct.
101: * @param idx index of the word guessed
102: * @param userGuess the user's guess for the actual word
103: * @return true if the guess was correct; false otherwise
104: */
105: public static boolean isCorrect(int idx, String userGuess) {
106: return userGuess.equals(getWord(idx));
107: }
108:
109: }
|