01: /* Anagram Game Application */
02:
03: package com.toy.anagrams.lib;
04:
05: /**
06: * Logic for the Anagram Game application.
07: */
08: public final class WordLibrary {
09:
10: private static final String[] WORD_LIST = { "abstraction",
11: "ambiguous", "arithmetic", "backslash", "bitmap",
12: "circumstance", "combination", "consequently",
13: "consortium", "decrementing", "dependency", "disambiguate",
14: "dynamic", "encapsulation", "equivalent", "expression",
15: "facilitate", "fragment", "hexadecimal", "implementation",
16: "indistinguishable", "inheritance", "internet", "java",
17: "localization", "microprocessor", "navigation",
18: "optimization", "parameter", "patrick", "pickle",
19: "polymorphic", "rigorously", "simultaneously",
20: "specification", "structure", "lexical", "likewise",
21: "management", "manipulate", "mathematics", "hotjava",
22: "vertex", "unsigned", "traditional" };
23:
24: private static final String[] SCRAMBLED_WORD_LIST = {
25: "batsartcoin", "maibuguos", "ratimhteci", "abkclssha",
26: "ibmtpa", "iccrmutsnaec", "ocbmnitaoni", "ocsnqeeutnyl",
27: "ocsnroitmu", "edrcmeneitgn", "edepdnneyc", "idasbmgiauet",
28: "ydanicm", "neacsplutaoni", "qeiuaveltn", "xerpseisno",
29: "aficilatet", "rfgaemtn", "ehaxedicalm", "milpmeneatitno",
30: "niidtsniugsiahleb", "niehiratcen", "nietnret", "ajav",
31: "olacilazitno", "imrcpoorecssro", "anivagitno",
32: "poitimazitno", "aparemert", "aprtcki", "ipkcel",
33: "opylomprich", "irogorsuyl", "isumtlnaoesuyl",
34: "psceficitaoni", "tsurtcreu", "elixalc", "ilekiwse",
35: "amanegemtn", "aminupalet", "amhtmetacsi", "ohjtvaa",
36: "evtrxe", "nuisngde", "rtdatioialn" };
37:
38: /**
39: * Singleton class.
40: */
41: private WordLibrary() {
42: }
43:
44: /**
45: * Gets the word at a given index.
46: * @param idx index of required word
47: * @return word at that index in its natural form
48: */
49: public static String getWord(int idx) {
50: return WORD_LIST[idx];
51: }
52:
53: /**
54: * Gets the word at a given index in its scrambled form.
55: * @param idx index of required word
56: * @return word at that index in its scrambled form
57: */
58: public static String getScrambledWord(int idx) {
59: return SCRAMBLED_WORD_LIST[idx];
60: }
61:
62: /**
63: * Gets the number of words in the library.
64: * @return the total number of plain/scrambled word pairs in the library
65: */
66: public static int getSize() {
67: return WORD_LIST.length;
68: }
69:
70: /**
71: * Checks whether a user's guess for a word at the given index is correct.
72: * @param idx index of the word guessed
73: * @param userGuess the user's guess for the actual word
74: * @return true if the guess was correct; false otherwise
75: */
76: public static boolean isCorrect(int idx, String userGuess) {
77: return userGuess.equals(getWord(idx));
78: }
79:
80: }
|