原来还有这样的记词方法_Java版记不规则动词_博主推荐

昨天在看一本英语书的不规则动词的时候,突然产生的灵感:就是想把这样记单词简单方式,用程序代码实现,然后,使用户可以与之进行交互

这样,在用户背不规则动词的时候就会轻松把它给记住。基于这一点,于是我就思考了一下,画了画图,理了一下思路。然后就开始着手开干。

现在基本成型了,也可以和大家见面了。

先看看一些截图,这样比较直接一点

项目结构:

效果图:

用户可以输入命令:

"all" :  输出所有的不规则动词信息

"pronunciation" : 单词的发音,该命令时一个发音开关,如果连续输入,效果则是:开,关,开,关...

"exit" : 退出系统

其他:如果用户输入的在库中没有,系统则会给出一些联想的词汇供用户选择,如:"drea", 则供选择的是 "dream"

如果用户输入的在库中,如:"dream", 系统会输出"dream"的详细信息,这样用户就可以轻松和系统交互,并且在这一

过程中把单词给记住。

看完效果图,我想大家都基本上了解这个小程序的功能和作用吧!

=================================================

Source Code

Description:

User input some commands in the console,then the system will receive the command

and process it, and display the result to user.

e.g:

ONE : When user input the command "all", then the system will display all irregular verbs.

TWO : When user input the command "pronunciation", then the system will change the status of the pronunciation.

THREE : When user input the a irregular verb, then the system will diplay the detial of the word.

=================================================

/IrregularVerbs/src/com/b510/irregularverbs/client/Client.java

  1 /**
  2  * 
  3  */
  4 package com.b510.irregularverbs.client;
  5 
  6 import java.util.Scanner;
  7 
  8 import com.b510.irregularverbs.utils.CommonUtil;
  9 import com.b510.irregularverbs.utils.IrregularVerbUtil;
 10 import com.b510.irregularverbs.utils.PrintUtil;
 11 
 12 /**
 13  * User input some commands in the console,then the system will receive<br> 
 14  * the command and process it, and display the result to user.<br>
 15  * for example: 
 16  * <li>all : show the all of the Irregular Verbs</li>
 17  * <li>pronunciation : the switch of the pronunciation.and the system default status<br>
 18  *     is not pronunciation.</li>
 19  * <li>The Irregular Verbs : user input the irregular verb,for example: "swim", "cost", "became".etc.</li>
 20  * @author Hongten
 21  * @created Feb 27, 2014
 22  */
 23 public class Client {
 24 
 25     private Scanner inputStreamScanner;
 26     private boolean controlFlag = false;
 27 
 28     public static void main(String[] args) {
 29         Client client = new Client();
 30         client.listenConsoleAndHandleContent();
 31     }
 32 
 33     public Client() {
 34         inputStreamScanner = new Scanner(System.in);
 35     }
 36 
 37     /**
 38      * Listen to the console and handle the content,what user inputed.
 39      */
 40     public void listenConsoleAndHandleContent() {
 41         PrintUtil.printInfo(CommonUtil.DESCRIPTION);
 42         try {
 43             while (!controlFlag && inputStreamScanner.hasNext()) {
 44                 processingConsoleInput();
 45             }
 46         } catch (Exception e) {
 47             e.printStackTrace();
 48         } finally {
 49             closeScanner();
 50         }
 51     }
 52 
 53     /**
 54      * The system receive the content, and process it.
 55      */
 56     private void processingConsoleInput() {
 57         String inputContent = inputStreamScanner.nextLine();
 58         if (!inputContent.isEmpty()) {
 59             if (pronounce(inputContent)) {
 60                 IrregularVerbUtil.reLoadVerbs();
 61             } else {
 62                 if (showAll(inputContent)) {
 63                     return;
 64                 }
 65                 controlFlag = exit(inputContent);
 66                 if (!controlFlag) {
 67                     notExit(inputContent);
 68                 }
 69             }
 70         }
 71     }
 72 
 73     /**
 74      * When user input the command "all"(ignore case),the system will handle the command "all",<br>
 75      * and display the all of the irregular verbs.
 76      * @param inputContent the command "all"(ignore case)
 77      * @return true, if user input the command "all"(ignore case);return false,if user input other command.
 78      */
 79     private boolean showAll(String inputContent) {
 80         if (CommonUtil.ALL.equalsIgnoreCase(inputContent)) {
 81             IrregularVerbUtil.showAll();
 82             return true;
 83         } else {
 84             return false;
 85         }
 86     }
 87 
 88     /**
 89      * When user input the command "pronunciation"(ignore case), the system will handle the command "pronunciation",<br>
 90      * and reload all of the irregular verbs. and display the message "After loading vocabulary!".
 91      * @param inputContent the command "pronunciation"(ignore case)
 92      * @return true, if user input the command "pronunciation"(ignore case);return false, if user input other command.
 93      */
 94     private boolean pronounce(String inputContent) {
 95         if (CommonUtil.PRONUNCIATION.equalsIgnoreCase(inputContent)) {
 96             IrregularVerbUtil.proFlag = !IrregularVerbUtil.proFlag;
 97             return true;
 98         } else {
 99             return false;
100         }
101     }
102 
103     private void notExit(String inputContent) {
104         IrregularVerbUtil verbsLib = IrregularVerbUtil.getInstance();
105         verbsLib.match(inputContent);
106     }
107 
108     private boolean exit(String inputContent) {
109         if (CommonUtil.EXIT.equalsIgnoreCase(inputContent)) {
110             controlFlag = true;
111             systemExit();
112         }
113         return controlFlag;
114     }
115 
116     private void systemExit() {
117         System.out.println(CommonUtil.EXIT_SYSTEM);
118         System.exit(0);
119     }
120 
121     private void closeScanner() {
122         inputStreamScanner.close();
123     }
124 }

/IrregularVerbs/src/com/b510/irregularverbs/lib/VocabularyLib.java

  1 /**
  2  * 
  3  */
  4 package com.b510.irregularverbs.lib;
  5 
  6 import java.util.HashMap;
  7 import java.util.Iterator;
  8 import java.util.List;
  9 import java.util.Map;
 10 
 11 import com.b510.irregularverbs.utils.CommonUtil;
 12 import com.b510.irregularverbs.utils.IrregularVerbUtil;
 13 import com.b510.irregularverbs.vo.IrregularVerbsVO;
 14 
 15 /**
 16  * Library for the irregular verbs.
 17  * @author Hongten
 18  * @created Feb 28, 2014
 19  */
 20 public class VocabularyLib {
 21     
 22     /**
 23      * Load all of the irregular verbs.<br>
 24      * There have FOUR types of the irregular verbs : "AAA", "ABA", "ABB", "ABC".<br>
 25      * so,there are FOUR methods to load all irregular verbs.
 26      * @return all of the irregular verbs.
 27      */
 28     public static List<IrregularVerbsVO> getVocabularyLib() {
 29         formatAAA();
 30         formatABA();
 31         formatABB();
 32         formatABC();
 33         return IrregularVerbUtil.verbs;
 34     }
 35     
 36     /**
 37      * The "AAA" format for irregular verbs.
 38      * 
 39      * @return
 40      */
 41     private static List<IrregularVerbsVO> formatAAA() {
 42         Map<String, String> aaaTypemap = libAAA();
 43         Iterator<String> it = aaaTypemap.keySet().iterator();
 44         while (it.hasNext()) {
 45             handleAAA(aaaTypemap, it);
 46         }
 47         return IrregularVerbUtil.verbs;
 48     }
 49 
 50     /**
 51      * @param aaaTypemap
 52      * @param it
 53      */
 54     private static void handleAAA(Map<String, String> aaaTypemap, Iterator<String> it) {
 55         String key = it.next();
 56         if (IrregularVerbUtil.proFlag) {
 57             IrregularVerbUtil.verbs.add(new IrregularVerbsVO(key, key, key, aaaTypemap.get(key)));
 58         } else {
 59             IrregularVerbUtil.verbs.add(new IrregularVerbsVO(key, key, key, aaaTypemap.get(key)));
 60         }
 61     }
 62 
 63     /**
 64      * The "ABA" format for irregular verbs
 65      * 
 66      * @return
 67      */
 68     private static List<IrregularVerbsVO> formatABA() {
 69         Map<String, String> abaTypemap = libABA();
 70         Iterator<String> it = abaTypemap.keySet().iterator();
 71         while (it.hasNext()) {
 72             handleABA(abaTypemap, it);
 73         }
 74         return IrregularVerbUtil.verbs;
 75     }
 76 
 77     /**
 78      * @param abaTypemap
 79      * @param it
 80      */
 81     private static void handleABA(Map<String, String> abaTypemap, Iterator<String> it) {
 82         String key = it.next();
 83         String[] keys = key.split(CommonUtil.COMMA);
 84         if (IrregularVerbUtil.proFlag) {
 85             IrregularVerbUtil.verbs.add(new IrregularVerbsVO(keys[0] + CommonUtil.COMMA + keys[1], keys[2] + CommonUtil.COMMA + keys[3], keys[0] + CommonUtil.COMMA + keys[1], abaTypemap
 86                     .get(key)));
 87         } else {
 88             IrregularVerbUtil.verbs.add(new IrregularVerbsVO(keys[0], keys[1], keys[0], abaTypemap.get(key)));
 89         }
 90     }
 91 
 92     /**
 93      * The "ABB" format for irregular verbs
 94      * 
 95      * @return
 96      */
 97     private static List<IrregularVerbsVO> formatABB() {
 98         Map<String, String> abbTypemap = libABB();
 99         Iterator<String> it = abbTypemap.keySet().iterator();
100         while (it.hasNext()) {
101             handleABB(abbTypemap, it);
102         }
103         return IrregularVerbUtil.verbs;
104     }
105 
106     /**
107      * @param abbTypemap
108      * @param it
109      */
110     private static void handleABB(Map<String, String> abbTypemap, Iterator<String> it) {
111         String key = it.next();
112         String[] keys = key.split(CommonUtil.COMMA);
113         if (IrregularVerbUtil.proFlag) {
114             IrregularVerbUtil.verbs.add(new IrregularVerbsVO(keys[0] + CommonUtil.COMMA + keys[1], keys[2] + CommonUtil.COMMA + keys[3], keys[2] + CommonUtil.COMMA + keys[3],
115                     abbTypemap.get(key)));
116         } else {
117             IrregularVerbUtil.verbs.add(new IrregularVerbsVO(keys[0], keys[1], keys[1], abbTypemap.get(key)));
118         }
119     }
120 
121     /**
122      * The "ABC" format for irregular verbs
123      * 
124      * @return
125      */
126     private static List<IrregularVerbsVO> formatABC() {
127         Map<String, String> abaTypemap = libABC();
128         Iterator<String> it = abaTypemap.keySet().iterator();
129         while (it.hasNext()) {
130             handleABC(abaTypemap, it);
131         }
132         return IrregularVerbUtil.verbs;
133     }
134 
135     /**
136      * @param abaTypemap
137      * @param it
138      */
139     private static void handleABC(Map<String, String> abaTypemap, Iterator<String> it) {
140         String key = it.next();
141         String[] keys = key.split(CommonUtil.COMMA);
142         if (IrregularVerbUtil.proFlag) {
143             IrregularVerbUtil.verbs.add(new IrregularVerbsVO(keys[0] + CommonUtil.COMMA + keys[1], keys[2] + CommonUtil.COMMA + keys[3], keys[4] + CommonUtil.COMMA + keys[5], abaTypemap
144                     .get(key)));
145         } else {
146             IrregularVerbUtil.verbs.add(new IrregularVerbsVO(keys[0], keys[1], keys[2], abaTypemap.get(key)));
147         }
148     }
149     
150     //============================================
151     // Library for all of the irregular verbs
152     //============================================
153     /**
154      * Library for "AAA" type.
155      * @return
156      */
157     private static Map<String, String> libAAA() {
158         Map<String, String> aaaTypemap = new HashMap<String, String>();
159         aaaTypemap.put(IrregularVerbUtil.proFlag ? "cost,[kɔst]" : "cost", "花费");
160         aaaTypemap.put(IrregularVerbUtil.proFlag ? "cut,[kʌt]" : "cut", "割,切");
161         aaaTypemap.put(IrregularVerbUtil.proFlag ? "hurt,[hə:t]" : "hurt", "受伤");
162         aaaTypemap.put(IrregularVerbUtil.proFlag ? "hit,[hit]" : "hit", "打,撞");
163         aaaTypemap.put(IrregularVerbUtil.proFlag ? "let,[let]" : "let", "让");
164         aaaTypemap.put(IrregularVerbUtil.proFlag ? "put,[put]" : "put", "放下");
165         aaaTypemap.put(IrregularVerbUtil.proFlag ? "read,[ri:d]" : "read", "读");
166         aaaTypemap.put(IrregularVerbUtil.proFlag ? "set,[set]" : "set", "安排,安置");
167         aaaTypemap.put(IrregularVerbUtil.proFlag ? "spread,[spred]" : "spread", "展开,传播,涂");
168         aaaTypemap.put(IrregularVerbUtil.proFlag ? "spit,[spit]" : "spit", "吐痰");
169         aaaTypemap.put(IrregularVerbUtil.proFlag ? "shut,[ʃʌt]" : "shut", "关上, 闭起,停止营业");
170         return aaaTypemap;
171     }
172     
173     /**
174      * Library for "ABA" type.
175      * @return
176      */
177     private static Map<String, String> libABA() {
178         Map<String, String> abaTypemap = new HashMap<String, String>();
179         abaTypemap.put(IrregularVerbUtil.proFlag ? "become,[bi'kʌm],became,[bi'keim]" : "become,became", "变");
180         abaTypemap.put(IrregularVerbUtil.proFlag ? "come,[kʌm],came,[keim]" : "come,came", "来");
181         abaTypemap.put(IrregularVerbUtil.proFlag ? "run,[rʌn],ran,[ræn]" : "run,ran", "跑");
182         return abaTypemap;
183     }
184     
185     /**
186      * Library for "ABB" type.
187      * @return
188      */
189     private static Map<String, String> libABB() {
190         Map<String, String> abbTypemap = new HashMap<String, String>();
191         abbTypemap.put(IrregularVerbUtil.proFlag ? "burn,[bə:n],burnt,[bə:nt]" : "burn,burnt", "燃烧");
192         abbTypemap.put(IrregularVerbUtil.proFlag ? "deal,[di:l],dealt,[delt]" : "deal,dealt", "解决");
193         abbTypemap.put(IrregularVerbUtil.proFlag ? "dream,[dri:m],dreamed,[dremt]" : "dream,dreamed", "做梦");
194         abbTypemap.put(IrregularVerbUtil.proFlag ? "dream,[dri:m],dreamt,[dremt]" : "dream,dreamt", "做梦");
195         abbTypemap.put(IrregularVerbUtil.proFlag ? "hear,[hiə],heard,[hə:d]" : "hear,heard", "听见");
196         abbTypemap.put(IrregularVerbUtil.proFlag ? "hang,['hæŋ],hanged,[]" : "hang,hanged", "绞死,悬挂");
197         abbTypemap.put(IrregularVerbUtil.proFlag ? "hang,['hæŋ],hung,[hʌŋ]" : "hang,hung", "绞死,悬挂");
198         abbTypemap.put(IrregularVerbUtil.proFlag ? "learn,[lə:n],learned,[]" : "learn,learned", "学习");
199         abbTypemap.put(IrregularVerbUtil.proFlag ? "learn,[lə:n],learnt,[lə:nt]" : "learn,learnt", "学习");
200         abbTypemap.put(IrregularVerbUtil.proFlag ? "light,['lait],lit,[lit]" : "light,lit", "点燃, 照亮");
201         abbTypemap.put(IrregularVerbUtil.proFlag ? "light,['lait],lighted,[]" : "light,lighted", "点燃, 照亮");
202         abbTypemap.put(IrregularVerbUtil.proFlag ? "mean,[mi:n],meant,[ment]" : "mean,meant", "意思");
203         abbTypemap.put(IrregularVerbUtil.proFlag ? "prove,[pru:v],proved,[]" : "prove,proved", "证明, 证实,试验");
204         abbTypemap.put(IrregularVerbUtil.proFlag ? "shine,[ʃain],shone,[ʃəun]" : "shine,shone", "使照耀,使发光");
205         abbTypemap.put(IrregularVerbUtil.proFlag ? "shine,[ʃain],shined,[]" : "shine,shined", "使照耀,使发光");
206         abbTypemap.put(IrregularVerbUtil.proFlag ? "show,[ʃəu],showed,[]" : "show,showed", "展示, 给...看");
207         abbTypemap.put(IrregularVerbUtil.proFlag ? "smell,[smel],smelled,[]" : "smell,smelled", "闻, 嗅");
208         abbTypemap.put(IrregularVerbUtil.proFlag ? "smell,[smel],smelt,[smelt]" : "smell,smelt", "闻, 嗅");
209         abbTypemap.put(IrregularVerbUtil.proFlag ? "speed,[spi:d],sped,[sped]" : "speed,sped", "加速");
210         abbTypemap.put(IrregularVerbUtil.proFlag ? "speed,[spi:d],speeded,[]" : "speed,speeded", "加速");
211         abbTypemap.put(IrregularVerbUtil.proFlag ? "spell,[spel],spelled,[]" : "spell,spelled", "拼写");
212         abbTypemap.put(IrregularVerbUtil.proFlag ? "spell,[spel],spelt,[spelt]" : "spell,spelt", "拼写");
213         abbTypemap.put(IrregularVerbUtil.proFlag ? "wake,[weik],waked,[]" : "wake,waked", "醒来,叫醒, 激发");
214         abbTypemap.put(IrregularVerbUtil.proFlag ? "wake,[weik],woke,[wəuk]" : "wake,woken", "醒来,叫醒, 激发");
215         abbTypemap.put(IrregularVerbUtil.proFlag ? "build,[bild],built,[bilt]" : "build,built", "建筑");
216         abbTypemap.put(IrregularVerbUtil.proFlag ? "lend,[lend],lent,[lent]" : "lend,lent", "借给");
217         abbTypemap.put(IrregularVerbUtil.proFlag ? "rebuild,[ri:'bild],rebuilt,[ri:'bilt]" : "rebuild,rebuilt", "改建, 重建");
218         abbTypemap.put(IrregularVerbUtil.proFlag ? "send,[send],sent,[sent]" : "send,sent", "送");
219         abbTypemap.put(IrregularVerbUtil.proFlag ? "spend,[spend],spent,[spent]" : "spend,spent", "花费");
220         abbTypemap.put(IrregularVerbUtil.proFlag ? "bring,[briŋ],brought,[brɔ:t]" : "bring,brought", "带来");
221         abbTypemap.put(IrregularVerbUtil.proFlag ? "buy,[bai],bought,[bɔ:t]" : "buy,bought", "买");
222         abbTypemap.put(IrregularVerbUtil.proFlag ? "fight,[fait],fought,[fɔ:t]" : "fight,fought", "打架");
223         abbTypemap.put(IrregularVerbUtil.proFlag ? "think,[θiŋk],thought,[θɔ:t]    " : "think,though", "思考,想");
224         abbTypemap.put(IrregularVerbUtil.proFlag ? "catch,[kætʃ],caught,[kɔ:t]" : "catch,caught", "捉,抓");
225         abbTypemap.put(IrregularVerbUtil.proFlag ? "teach,[ti:tʃ],taught,[tɔ:t]" : "teach,taught", "教");
226         abbTypemap.put(IrregularVerbUtil.proFlag ? "dig,[diɡ],dug,[dʌɡ]" : "dig,dug", "掘(土), 挖(洞、沟等)");
227         abbTypemap.put(IrregularVerbUtil.proFlag ? "feed,[fi:d],fed,[fed]" : "feed,fed", "喂");
228         abbTypemap.put(IrregularVerbUtil.proFlag ? "find,[faind],found,[]" : "find,found", "发现,找到");
229         abbTypemap.put(IrregularVerbUtil.proFlag ? "get,[ɡet],got,[ɡɔt]" : "get,got", "得到");
230         abbTypemap.put(IrregularVerbUtil.proFlag ? "hold,[həuld],held,[held]" : "hold,held", "拥有,握住,支持");
231         abbTypemap.put(IrregularVerbUtil.proFlag ? "lead,[li:d],led,[led]" : "lead,led", "引导, 带领, 领导");
232         abbTypemap.put(IrregularVerbUtil.proFlag ? "meet,[mi:t],met,[met]" : "meet,met", "遇见");
233         abbTypemap.put(IrregularVerbUtil.proFlag ? "sit,[sit],sat,[sæt]" : "sit,sat", "坐");
234         abbTypemap.put(IrregularVerbUtil.proFlag ? "shoot,[ʃu:t],shot,[ʃɔt]" : "shoot,shot", "射击");
235         abbTypemap.put(IrregularVerbUtil.proFlag ? "spit,[spit],spit,[]" : "spit,spit", "吐痰");
236         abbTypemap.put(IrregularVerbUtil.proFlag ? "spit,[spit],spat,[spæt]" : "spit,spat", "吐痰");
237         abbTypemap.put(IrregularVerbUtil.proFlag ? "stick,[stik],stuck,[stʌk]" : "stick,stuck", "插进, 刺入, 粘住");
238         abbTypemap.put(IrregularVerbUtil.proFlag ? "win,[win],won,[wʌn]" : "win,won", "赢");
239         abbTypemap.put(IrregularVerbUtil.proFlag ? "feel,['fi:l],felt,[felt]" : "feel,felt", "感到");
240         abbTypemap.put(IrregularVerbUtil.proFlag ? "keep,[ki:p],kept,[kept]" : "keep,kept", "保持");
241         abbTypemap.put(IrregularVerbUtil.proFlag ? "leave,[li:v],left,[left]" : "leave,left", "离开");
242         abbTypemap.put(IrregularVerbUtil.proFlag ? "sleep,[sli:p],slept,[slept]" : "sleep,slept", "睡觉");
243         abbTypemap.put(IrregularVerbUtil.proFlag ? "sweep,[swi:p],swept,[swept]" : "sweep,swept", "扫");
244         abbTypemap.put(IrregularVerbUtil.proFlag ? "lay,[lei],laid,[leid]" : "lay,laid", "下蛋, 放置");
245         abbTypemap.put(IrregularVerbUtil.proFlag ? "pay,[pei],paid,[peid]" : "pay,paid", "付");
246         abbTypemap.put(IrregularVerbUtil.proFlag ? "say,[sei],said,[sed]" : "say,said", "说");
247         abbTypemap.put(IrregularVerbUtil.proFlag ? "stand,[stænd],stood,[stud]" : "stand,stood", "站");
248         abbTypemap.put(IrregularVerbUtil.proFlag ? "understand,[],understood,[ʌndə'stænd]" : "understand,understood", "明白");
249         abbTypemap.put(IrregularVerbUtil.proFlag ? "lose,[lu:z],lost,[lɔst]" : "lose,lost", "失去");
250         abbTypemap.put(IrregularVerbUtil.proFlag ? "have,[həv],had,[hæd]" : "have,had", "有");
251         abbTypemap.put(IrregularVerbUtil.proFlag ? "make,[meik],made,[meid]" : "make,made", "制造");
252         abbTypemap.put(IrregularVerbUtil.proFlag ? "sell,[sel],sold,[səuld]" : "sell,sold", "卖");
253         abbTypemap.put(IrregularVerbUtil.proFlag ? "tell,[tel],told,[təuld]" : "tell,told", "告诉");
254         abbTypemap.put(IrregularVerbUtil.proFlag ? "retell,[ri:'tel],retold,[ri:'təuld]" : "retell,retold", "重讲,重复,复述");
255         return abbTypemap;
256     }
257     
258     
259 
260     /**
261      * Library for "ABC" type.
262      * @return
263      */
264     private static Map<String, String> libABC() {
265         Map<String, String> abaTypemap = new HashMap<String, String>();
266         abaTypemap.put(IrregularVerbUtil.proFlag ? "blow,[bləu],blew,[blu:],blown,[]" : "blow,blew,blown", "吹");
267         abaTypemap.put(IrregularVerbUtil.proFlag ? "drive,[draiv],drove,[drəuv],driven,[drivən]" : "drive,drove,driven", "驾驶");
268         abaTypemap.put(IrregularVerbUtil.proFlag ? "draw,[drɔ:],drew,[dru:],drawn,[drɔ:n]" : "draw,drew,drawn", "画画");
269         abaTypemap.put(IrregularVerbUtil.proFlag ? "eat,[i:t],ate,[eit],eaten,['i:tən]" : "eat,ate,eaten", "吃");
270         abaTypemap.put(IrregularVerbUtil.proFlag ? "fall,[fɔ:l],Fell,[fel],fallen,['fɔ:lən]" : "fall,fell,fallen", "落下");
271         abaTypemap.put(IrregularVerbUtil.proFlag ? "give,[ɡiv],gave,[ɡeiv],given,['ɡivən]" : "give,gave,given", "给");
272         abaTypemap.put(IrregularVerbUtil.proFlag ? "get,[ɡet],got,[ɡɔt],gotten,['ɡɔtən]" : "get,got,gotten", "得到");
273         abaTypemap.put(IrregularVerbUtil.proFlag ? "show,[ʃəu],showed,[],shown,['ʃəun]" : "show,showed,shown", "展示, 给...看");
274         abaTypemap.put(IrregularVerbUtil.proFlag ? "fall,[fɔ:l],Fell,[fel],fallen,['fɔ:lən]" : "prove,proved,proven", "证明, 证实,试验");
275         abaTypemap.put(IrregularVerbUtil.proFlag ? "give,[ɡiv],gave,[ɡeiv],given,['ɡivən]" : "beat,beat,beaten", "打败");
276         abaTypemap.put(IrregularVerbUtil.proFlag ? "grow,[ɡrəu],grew,[ɡru:],grown,[ɡrəun]" : "grow,grew,grown", "生长");
277         abaTypemap.put(IrregularVerbUtil.proFlag ? "forgive,[fə'ɡiv],forgot,[fə'ɡɔt],forgiven,[]" : "forgive,forgot,forgiven", "原谅, 饶恕");
278         abaTypemap.put(IrregularVerbUtil.proFlag ? "know,[nəu],knew,[nju: nu:],known,[]" : "know,knew,known", "知道");
279         abaTypemap.put(IrregularVerbUtil.proFlag ? "mistake,[mi'steik],mistook,[mi'stuk],mistooken,[]" : "mistake,mistook,mistooken", "弄错; 误解,");
280         abaTypemap.put(IrregularVerbUtil.proFlag ? "overeat,['əuvə'i:t],overate,[əuvə'reit],overeaten,[]" : "overeat,overate,overeaten", "(使)吃过量");
281         abaTypemap.put(IrregularVerbUtil.proFlag ? "take,[teik],took,[tuk],taken,['teikn]" : "take,took,taken", "拿");
282         abaTypemap.put(IrregularVerbUtil.proFlag ? "throw,[θrəu],threw,[θru:],thrown,[θrəun]" : "throw,threw,thrown", "抛,扔");
283         abaTypemap.put(IrregularVerbUtil.proFlag ? "ride,[raid],rode,[rəud],ridden,['ridən]" : "ride,rode,ridden", "骑");
284         abaTypemap.put(IrregularVerbUtil.proFlag ? "see,[si:],saw,[sɔ:],seen,[si:n]" : "see,saw,seen", "看见");
285         abaTypemap.put(IrregularVerbUtil.proFlag ? "write,[rait],wrote,[rəut],written,['ritən]" : "write,wrote,writen", "写");
286         abaTypemap.put(IrregularVerbUtil.proFlag ? "break,[breik],broke,[brəuk],broken,['brəukən]" : "break,broke,broken", "打破");
287         abaTypemap.put(IrregularVerbUtil.proFlag ? "choose,[tʃu:z],chose,[tʃəuz],chosen,['tʃəuzən]" : "choose,chose,chosen", "选择");
288         abaTypemap.put(IrregularVerbUtil.proFlag ? "hide,[haid],hid,[hid],hidden,['hidən]" : "hide,hid,hidden", "隐藏");
289         abaTypemap.put(IrregularVerbUtil.proFlag ? "forget,[fə'ɡet],forgot,[fə'ɡɔt],forgotten,[fə'ɡɔtn]" : "forget,forgot,forgotten", "忘记");
290         abaTypemap.put(IrregularVerbUtil.proFlag ? "freeze,[fri:z],froze,[frəuz],frozen,['frəuzn]" : "freeze,froze,frozen", "冷冻,结冰,感到严寒");
291         abaTypemap.put(IrregularVerbUtil.proFlag ? "speak,[spi:k],spoke,[spəuk],spoken,['spəukən]" : "speak,spoke,spoken", "说");
292         abaTypemap.put(IrregularVerbUtil.proFlag ? "steal,[sti:l],stole,[],stolen,['stəulən]" : "steal,stole,stolen", "偷");
293         abaTypemap.put(IrregularVerbUtil.proFlag ? "begin,[bi'ɡin],began,[bi'ɡæn],begun,[bi'ɡʌn]" : "begin,began,gegun", "开始");
294         abaTypemap.put(IrregularVerbUtil.proFlag ? "drink,[driŋk],drank,[dræŋk],drunk,[drʌŋk]" : "drink,drank,drunk", "喝");
295         abaTypemap.put(IrregularVerbUtil.proFlag ? "sing,[siŋ],sang,[sæŋ],sung,[sʌŋ]" : "sing,sang,sung", "唱");
296         abaTypemap.put(IrregularVerbUtil.proFlag ? "sink,[siŋk],sank,[sæŋk],sunk,[sʌŋk]" : "sink,sank,sunk", "下沉, 沉没");
297         abaTypemap.put(IrregularVerbUtil.proFlag ? "swim,[swim],swam,[swæm],swum,[swʌm]" : "swim,swam,swum", "游泳");
298         abaTypemap.put(IrregularVerbUtil.proFlag ? "ring,[riŋ],rang,[ræŋ],rung,[rʌŋ]" : "ring,rang,rung", "打电话");
299         abaTypemap.put(IrregularVerbUtil.proFlag ? "be,[],was,[],been,[]" : "be,was,been", "是");
300         abaTypemap.put(IrregularVerbUtil.proFlag ? "be,[],was,[],been,[]" : "be,were,been", "是");
301         abaTypemap.put(IrregularVerbUtil.proFlag ? "bear,[bεə],bore,[bɔ:],born,[]" : "bear,bore,born", "负担, 忍受");
302         abaTypemap.put(IrregularVerbUtil.proFlag ? "bear,[bεə],bore,[bɔ:],born,[bɔ:n]" : "bear,bore,borne", "负担, 忍受");
303         abaTypemap.put(IrregularVerbUtil.proFlag ? "do,[du:],did,[did],done,[dʌn]" : "do,did,done", "做");
304         abaTypemap.put(IrregularVerbUtil.proFlag ? "fly,[flai],flew,[flu:],flown,[fləun]" : "fly,flew,flown", "飞");
305         abaTypemap.put(IrregularVerbUtil.proFlag ? "go,[ɡəu],went,[went],gone,[ɡɔn]" : "go,went,gone", "去");
306         abaTypemap.put(IrregularVerbUtil.proFlag ? "lie,[lai],lay,[lei],lain,[lein]" : "lie,lay,lain", "躺");
307         abaTypemap.put(IrregularVerbUtil.proFlag ? "wear,[wεə],wore,[wɔ:],worn,[wɔ:n]" : "wear,wore,worn", "穿");
308         return abaTypemap;
309     }
310 }

/IrregularVerbs/src/com/b510/irregularverbs/utils/CommonUtil.java

 1 /**
 2  * 
 3  */
 4 package com.b510.irregularverbs.utils;
 5 
 6 /**
 7  * @author Hongten
 8  * @created Feb 27, 2014
 9  */
10 public class CommonUtil {
11 
12     //Commands
13     public static final String EXIT = "exit";
14     public static final String PRONUNCIATION = "pronunciation";
15     public static final String ALL = "all";
16     //Description
17     public static final String DESCRIPTION = "Please input a Irregular Verb or Command:\n[e.g: 'came', 'all', 'pronunciation', 'exit']";
18     public static final String EXIT_SYSTEM = "exited system.";
19     public static final String LOADIGN_VERBS = "After loading vocabulary!";
20     
21     public static final String NO_MATCHED = "No matched!";
22     public static final String ADVICE = "You may want to search the follow word(s):";
23     public static final String SPEND = "Spend >> [";
24     public static final String SPEND_END = "]ms";
25 
26     public static final int STR_SIZE = 25;
27     public static final String COMMA = ",";
28     public static final String EMPTY = "";
29     public static final String BLANK = " ";
30 
31     public static final String LINE_ONE = "=====================";
32     public static final String LINE_TWO = LINE_ONE + LINE_ONE;
33     public static final String LINE_THREE = LINE_TWO+ "\n";
34 }

/IrregularVerbs/src/com/b510/irregularverbs/utils/IrregularVerbUtil.java

  1 /**
  2  * 
  3  */
  4 package com.b510.irregularverbs.utils;
  5 
  6 import java.util.ArrayList;
  7 import java.util.List;
  8 
  9 import com.b510.irregularverbs.lib.VocabularyLib;
 10 import com.b510.irregularverbs.vo.IrregularVerbsVO;
 11 
 12 /**
 13  * The tool for the Irregular Verbs. Providing load and reload methods to get all irregular verbs.<br>
 14  * it also provide the match method to handle the content, which user input in the console.<br>
 15  * and display the result of matching.
 16  * @author Hongten
 17  * @created Feb 27, 2014
 18  */
 19 public class IrregularVerbUtil {
 20 
 21     private static IrregularVerbUtil irregularVerbs = new IrregularVerbUtil();
 22     public static List<IrregularVerbsVO> verbs = new ArrayList<IrregularVerbsVO>();
 23     // The switch of the pronunciation
 24     public static boolean proFlag = false;
 25 
 26     /**
 27      * Load all of the irregular verbs.<br>
 28      * @return all of the irregular verbs.
 29      */
 30     public static List<IrregularVerbsVO> loadIrregularVerbsVOs() {
 31         return VocabularyLib.getVocabularyLib();
 32     }
 33 
 34     private IrregularVerbUtil() {
 35     }
 36 
 37     public static IrregularVerbUtil getInstance() {
 38         if (verbs.size() <= 0) {
 39             loadIrregularVerbsVOs();
 40         }
 41         return irregularVerbs;
 42     }
 43 
 44     /**
 45      * Reload all of the irregular verbs.
 46      */
 47     public static void reLoadVerbs() {
 48         verbs = null;
 49         verbs = new ArrayList<IrregularVerbsVO>();
 50         loadIrregularVerbsVOs();
 51         PrintUtil.printInfo(CommonUtil.LOADIGN_VERBS);
 52         PrintUtil.printInfo(CommonUtil.LINE_THREE);
 53     }
 54 
 55     /**
 56      * Processing the input content,and display the result for matching.
 57      * @param input input content.
 58      */
 59     public void match(String input) {
 60         long startTime = System.currentTimeMillis();
 61         List<IrregularVerbsVO> temp = new ArrayList<IrregularVerbsVO>();
 62         List<IrregularVerbsVO> mayBeVOs = new ArrayList<IrregularVerbsVO>();
 63         for (IrregularVerbsVO vo : verbs) {
 64             handleMatchWord(input, temp, vo);
 65             // match same word(s)
 66             input = input.toLowerCase();
 67             if (vo.getPrototype().startsWith(input) || vo.getPostTense().startsWith(input) || vo.getPostParticiple().startsWith(input)) {
 68                 mayBeVOs.add(vo);
 69             }
 70         }
 71         PrintUtil.printInfo(CommonUtil.LINE_TWO);
 72         matchResult(temp, mayBeVOs);
 73         long endTime = System.currentTimeMillis();
 74         PrintUtil.printInfo(CommonUtil.SPEND + (endTime - startTime) + CommonUtil.SPEND_END);
 75         PrintUtil.printInfo(CommonUtil.LINE_THREE);
 76     }
 77 
 78     /**
 79      * There have two results for matching.<br>
 80      * <li>First : matched, then display the result of matched.</li>
 81      * <li>Second : not matched, then display the related irregular verb(s)</li>
 82      * @param matchedList
 83      * @param relatedList
 84      */
 85     private void matchResult(List<IrregularVerbsVO> matchedList, List<IrregularVerbsVO> relatedList) {
 86         if (matchedList.size() > 0) {
 87             loopMatchResult(matchedList);
 88         } else {
 89             PrintUtil.printInfo(CommonUtil.NO_MATCHED);
 90             if (relatedList.size() > 0) {
 91                 PrintUtil.printInfo(CommonUtil.LINE_ONE);
 92                 PrintUtil.printInfo(CommonUtil.ADVICE);
 93                 loopMatchResult(relatedList);
 94             }
 95         }
 96     }
 97 
 98     /**
 99      * Display the match result
100      * @param list
101      */
102     private static void loopMatchResult(List<IrregularVerbsVO> list) {
103         for (IrregularVerbsVO vo : list) {
104             PrintUtil.printInfo(addBlank(vo.getPrototype().replace(CommonUtil.COMMA, CommonUtil.EMPTY))
105                     + addBlank(vo.getPostTense().replace(CommonUtil.COMMA, CommonUtil.EMPTY))
106                     + addBlank(vo.getPostParticiple().replace(CommonUtil.COMMA, CommonUtil.EMPTY)) + vo.getMean());
107         }
108     }
109 
110     /**
111      * @param input
112      * @param temp
113      * @param vo
114      */
115     private void handleMatchWord(String input, List<IrregularVerbsVO> temp, IrregularVerbsVO vo) {
116         if (proFlag) {
117             if (input.equalsIgnoreCase(vo.getPrototype().split(CommonUtil.COMMA)[0]) || input.equalsIgnoreCase(vo.getPostTense().split(CommonUtil.COMMA)[0])
118                     || input.equalsIgnoreCase(vo.getPostParticiple().split(CommonUtil.COMMA)[0])) {
119                 temp.add(vo);
120             }
121         } else {
122             if (input.equalsIgnoreCase(vo.getPrototype()) || input.equalsIgnoreCase(vo.getPostTense()) || input.equalsIgnoreCase(vo.getPostParticiple())) {
123                 temp.add(vo);
124             }
125         }
126     }
127 
128     /**
129      * Show all of the irregular verbs.
130      */
131     public static void showAll() {
132         if (verbs.size() <= 0) {
133             loadIrregularVerbsVOs();
134         }
135         long startTime = System.currentTimeMillis();
136         PrintUtil.printInfo(CommonUtil.LINE_TWO);
137         loopMatchResult(verbs);
138         long endTime = System.currentTimeMillis();
139         PrintUtil.printInfo(CommonUtil.SPEND + (endTime - startTime) + CommonUtil.SPEND_END);
140         PrintUtil.printInfo(CommonUtil.LINE_THREE);
141     }
142 
143     /**
144      * Add the blank
145      * @param str
146      * @return
147      */
148     private static String addBlank(String str) {
149         int blank = CommonUtil.STR_SIZE - str.getBytes().length;
150         for (int i = 0; i < blank; i++) {
151             str += CommonUtil.BLANK;
152         }
153         return str.toString();
154     }
155 }

/IrregularVerbs/src/com/b510/irregularverbs/utils/PrintUtil.java

 1 /**
 2  * 
 3  */
 4 package com.b510.irregularverbs.utils;
 5 
 6 /**
 7  * @author Hongten
 8  * @created 2014-2-27
 9  */
10 public class PrintUtil {
11 
12     public static void printInfo(String info) {
13         System.out.println(info);
14     }
15 
16     public static void printInfo(StringBuffer info) {
17         System.out.println(info);
18     }
19 
20     public static void printInfo(char info) {
21         System.out.println(info);
22     }
23 }

/IrregularVerbs/src/com/b510/irregularverbs/vo/IrregularVerbsVO.java

 1 /**
 2  * 
 3  */
 4 package com.b510.irregularverbs.vo;
 5 
 6 /**
 7  * @author Hongten
 8  * @created Feb 27, 2014
 9  */
10 public class IrregularVerbsVO {
11 
12     private String prototype;
13     private String postTense;
14     private String postParticiple;
15     private String mean;
16 
17     public IrregularVerbsVO(String prototype, String postTense, String postParticiple, String mean) {
18         super();
19         this.prototype = prototype;
20         this.postTense = postTense;
21         this.postParticiple = postParticiple;
22         this.mean = mean;
23     }
24 
25     public String getPrototype() {
26         return prototype;
27     }
28 
29     public void setPrototype(String prototype) {
30         this.prototype = prototype;
31     }
32 
33     public String getPostTense() {
34         return postTense;
35     }
36 
37     public void setPostTense(String postTense) {
38         this.postTense = postTense;
39     }
40 
41     public String getPostParticiple() {
42         return postParticiple;
43     }
44 
45     public void setPostParticiple(String postParticiple) {
46         this.postParticiple = postParticiple;
47     }
48 
49     public String getMean() {
50         return mean;
51     }
52 
53     public void setMean(String mean) {
54         this.mean = mean;
55     }
56 
57 }

Download Source Code : http://files.cnblogs.com/hongten/IrregularVerbs.zip

本文参与腾讯云自媒体分享计划,欢迎正在阅读的你也加入,一起分享。

发表于

我来说两句

0 条评论
登录 后参与评论

相关文章

来自专栏菩提树下的杨过

恶心的0.5四舍五入问题

四舍五入是财务类应用中常见的需求,按中国人的财务习惯,遇到0.5统一向上进位,但是c#与java中默认的却不是这样。 见c#代码: 1 stat...

20610
来自专栏一个会写诗的程序员的博客

禅与 JavaScript 编程艺术, Zen and The Art of JavaScript Programming禅与 JavaScript 编程艺术

Zen and The Art of JavaScript Programming

1071
来自专栏码匠的流水账

聊聊flink的TextOutputFormat

flink-streaming-java_2.11-1.7.0-sources.jar!/org/apache/flink/streaming/api/data...

1412
来自专栏HansBug's Lab

3402: [Usaco2009 Open]Hide and Seek 捉迷藏

3402: [Usaco2009 Open]Hide and Seek 捉迷藏 Time Limit: 3 Sec  Memory Limit: 128 MB ...

3407
来自专栏码匠的流水账

Java10的新特性

上面列出的是大方面的特性,除此之外还有一些api的更新及废弃,主要见What’s New in JDK 10 - New Features and Enhanc...

550
来自专栏草根专栏

Typescript 查缺补漏

Types Casting: let input = xxx as HTMLInputElement; let input = <HTMLElement>xxx...

2193
来自专栏swag code

练习-Map集合的操作

Teacher对象的值: “Tom”,”Java”, “John”,”Oracle”, “Susan”,”Oracle”, “Jerry”,”JDBC”...

1023
来自专栏码匠的流水账

聊聊springboot1.x及2.x的JvmGcMetrics的区别

本文主要研究一下springboot1.x及2.x的JvmGcMetrics的区别

2231
来自专栏程序你好

如何使用Java Stream Collectors(归约器)?

Java 8引入了Stream API,它允许我们以声明的方式处理数据。此外,Stream还可以在不需要编写多线程代码的情况下使用多核架构。

771
来自专栏HansBug's Lab

3410: [Usaco2009 Dec]Selfish Grazing 自私的食草者

3410: [Usaco2009 Dec]Selfish Grazing 自私的食草者 Time Limit: 3 Sec  Memory Limit: 128...

2849

扫码关注云+社区