-
Notifications
You must be signed in to change notification settings - Fork 0
/
WordLibrary.java
191 lines (183 loc) · 6.8 KB
/
WordLibrary.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
package A1;
/**
* Created by kevin on 1/29/16.
*/
public class WordLibrary {
private static final String NUMBERS[] = {"zero", "one", "two", "three", "four", "five", "six", "seven", "eight", "nine", "ten", "eleven", "tweleve",
"thirteen", "fourteen", "fifteen", "sixteen", "seventeen", "eighteen", "nineteen", "twenty","thirty", "forty",
"fifty", "sixty", "seventy", "eighty", "ninety"};
private static final String POWERS[] = { "hundred", "thousand", "million", "billion", "trillion"};
private static final String FRACTIONS[] = {"half", "third", "fourth", "fifth", "sixth", "seventh", "eighth", "ninth", "tenth",
"eleventh", "twelfth", "thirteenth", "fourteenth", "fifteenth", "sixteenth",
"seventeenth", "eighteenth", "nineteenth", "twentieth", "thirtieth","fortieth", "fiftieth", "sixtieth", "seventieth", "eightieth", "ninetieth"};
private static final String FRACTIONPOWERS[] = { "hundredth" , "thousandth", "millionth", "billionth", "trillionth"};
private static final String XTRAFRACTIONS[] = {"first", "second"};
public static String percent = "percent";
public static String simpleNumberWord(char digit){
String representation;
switch (digit){
case '0': representation = NUMBERS[0];
break;
case '1': representation = NUMBERS[1];
break;
case '2': representation = NUMBERS[2];
break;
case '3': representation = NUMBERS[3];
break;
case '4': representation = NUMBERS[4];
break;
case '5': representation = NUMBERS[5];
break;
case '6': representation = NUMBERS[6];
break;
case '7': representation = NUMBERS[7];
break;
case '8': representation = NUMBERS[8];
break;
case '9': representation = NUMBERS[9];
break;
default: representation = "simpleNumberWord";
break;
}
return representation;
}
public static String teenWords(char digit){
String representation;
switch (digit){
case '0': representation = NUMBERS[10];
break;
case '1': representation = NUMBERS[11];
break;
case '2': representation = NUMBERS[12];
break;
case '3': representation = NUMBERS[13];
break;
case '4': representation = NUMBERS[14];
break;
case '5': representation = NUMBERS[15];
break;
case '6': representation = NUMBERS[16];
break;
case '7': representation = NUMBERS[17];
break;
case '8': representation = NUMBERS[18];
break;
case '9': representation = NUMBERS[19];
break;
default: representation = "teenWords";
break;
}
return representation;
}
public static String tenWords(char digit){
String representation;
switch (digit){
case '2': representation = NUMBERS[20];
break;
case '3': representation = NUMBERS[21];
break;
case '4': representation = NUMBERS[22];
break;
case '5': representation = NUMBERS[23];
break;
case '6': representation = NUMBERS[24];
break;
case '7': representation = NUMBERS[25];
break;
case '8': representation = NUMBERS[26];
break;
case '9': representation = NUMBERS[27];
break;
default: representation = "tenWords";
break;
}
return representation;
}
public static String fractionWords(char number){
String representation;
switch (number){
case '2': representation = FRACTIONS[0];
break;
case '3': representation = FRACTIONS[1];
break;
case '4': representation = FRACTIONS[2];
break;
case '5': representation = FRACTIONS[3];
break;
case '6': representation = FRACTIONS[4];
break;
case '7': representation = FRACTIONS[5];
break;
case '8': representation = FRACTIONS[6];
break;
case '9': representation = FRACTIONS[7];
break;
default: representation = "fractionWords";
}
return representation;
}
public static String teenFractions(char c){
String representation;
switch (c){
case '0': representation = FRACTIONS[8];
break;
case '1': representation = FRACTIONS[9];
break;
case '2': representation = FRACTIONS[10];
break;
case '3': representation = FRACTIONS[11];
break;
case '4': representation = FRACTIONS[12];
break;
case '5': representation = FRACTIONS[13];
break;
case '6': representation = FRACTIONS[14];
break;
case '7': representation = FRACTIONS[15];
break;
case '8': representation = FRACTIONS[16];
break;
case '9': representation = FRACTIONS[17];
break;
default: representation = "teenFractions";
break;
}
return representation;
}
public static String firstorSecond(char c){
String representation;
switch (c){
case '1': representation = XTRAFRACTIONS[0];
break;
case '2': representation = XTRAFRACTIONS[1];
break;
default: representation = "firstorSecond";
break;
}
return representation;
}
public static String tenFractions(char c){
String representation;
switch (c){
case '2': representation = FRACTIONS[18];
break;
case '3': representation = FRACTIONS[19];
break;
case '4': representation = FRACTIONS[20];
break;
case '5': representation = FRACTIONS[21];
break;
case '6': representation = FRACTIONS[22];
break;
case '7': representation = FRACTIONS[23];
break;
case '8': representation = FRACTIONS[24];
break;
case '9': representation = FRACTIONS[25];
break;
default: representation = "tenFractions";
break;
}
return representation;
}
}