KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > toy > anagrams > lib > WordLibrary


1 /* Anagram Game Application */
2
3 package com.toy.anagrams.lib;
4
5 /**
6  * Logic for the Anagram Game application.
7  */

8 public final class WordLibrary {
9
10     private static final String JavaDoc[] WORD_LIST = {
11         "abstraction",
12         "ambiguous",
13         "arithmetic",
14         "backslash",
15         "bitmap",
16         "circumstance",
17         "combination",
18         "consequently",
19         "consortium",
20         "decrementing",
21         "dependency",
22         "disambiguate",
23         "dynamic",
24         "encapsulation",
25         "equivalent",
26         "expression",
27         "facilitate",
28         "fragment",
29         "hexadecimal",
30         "implementation",
31         "indistinguishable",
32         "inheritance",
33         "internet",
34         "java",
35         "localization",
36         "microprocessor",
37         "navigation",
38         "optimization",
39         "parameter",
40         "patrick",
41         "pickle",
42         "polymorphic",
43         "rigorously",
44         "simultaneously",
45         "specification",
46         "structure",
47         "lexical",
48         "likewise",
49         "management",
50         "manipulate",
51         "mathematics",
52         "hotjava",
53         "vertex",
54         "unsigned",
55         "traditional"};
56
57     private static final String JavaDoc[] SCRAMBLED_WORD_LIST = {
58         "batsartcoin",
59         "maibuguos",
60         "ratimhteci",
61         "abkclssha",
62         "ibmtpa",
63         "iccrmutsnaec",
64         "ocbmnitaoni",
65         "ocsnqeeutnyl",
66         "ocsnroitmu",
67         "edrcmeneitgn",
68         "edepdnneyc",
69         "idasbmgiauet",
70         "ydanicm",
71         "neacsplutaoni",
72         "qeiuaveltn",
73         "xerpseisno",
74         "aficilatet",
75         "rfgaemtn",
76         "ehaxedicalm",
77         "milpmeneatitno",
78         "niidtsniugsiahleb",
79         "niehiratcen",
80         "nietnret",
81         "ajav",
82         "olacilazitno",
83         "imrcpoorecssro",
84         "anivagitno",
85         "poitimazitno",
86         "aparemert",
87         "aprtcki",
88         "ipkcel",
89         "opylomprich",
90         "irogorsuyl",
91         "isumtlnaoesuyl",
92         "psceficitaoni",
93         "tsurtcreu",
94         "elixalc",
95         "ilekiwse",
96         "amanegemtn",
97         "aminupalet",
98         "amhtmetacsi",
99         "ohjtvaa",
100         "evtrxe",
101         "nuisngde",
102         "rtdatioialn"
103     };
104
105     /**
106      * Singleton class.
107      */

108     private WordLibrary() {
109     }
110
111     /**
112      * Gets the word at a given index.
113      * @param idx index of required word
114      * @return word at that index in its natural form
115      */

116     public static String JavaDoc getWord(int idx) {
117         return WORD_LIST[idx];
118     }
119
120     /**
121      * Gets the word at a given index in its scrambled form.
122      * @param idx index of required word
123      * @return word at that index in its scrambled form
124      */

125     public static String JavaDoc getScrambledWord(int idx) {
126         return SCRAMBLED_WORD_LIST[idx];
127     }
128
129     /**
130      * Gets the number of words in the library.
131      * @return the total number of plain/scrambled word pairs in the library
132      */

133     public static int getSize() {
134         return WORD_LIST.length;
135     }
136
137     /**
138      * Checks whether a user's guess for a word at the given index is correct.
139      * @param idx index of the word guessed
140      * @param userGuess the user's guess for the actual word
141      * @return true if the guess was correct; false otherwise
142      */

143     public static boolean isCorrect(int idx, String JavaDoc userGuess) {
144         return userGuess.equals(getWord(idx));
145     }
146
147 }
148
Popular Tags