91av视频/亚洲h视频/操亚洲美女/外国一级黄色毛片 - 国产三级三级三级三级

  • 大小: 45KB
    文件類型: .zip
    金幣: 2
    下載: 0 次
    發布日期: 2021-06-02
  • 語言: Java
  • 標簽: JAVA入門??

資源簡介

初學JAVA的圖形設計界面,聯合了IO輸入輸出流,簡單地實現了一個詞匯的單詞測試單機版

資源截圖

代碼片段和文件信息

import?java.io.*;
import?java.util.*;

public?class?Dictionary?{

private?String?path;//單詞文件的地址
//使用ArrayList分別存儲英文單詞及其對應的中文解釋,方便隨機生成選項
private?final?List?keyWord?=?new?ArrayList<>();//英文單詞
private?final?List?valueWord?=?new?ArrayList<>();//中文解釋

Dictionary(String?path)
{
this.path?=?path;
initiDic();
}

private?void?initiDic()
//使用FileReader和BUfferedReader從文件中讀取單詞數據
{
FileReader?reader?=?null;
BufferedReader?bufferedReader?=?null;

try?{
reader?=?new?FileReader(path);
bufferedReader?=?new?BufferedReader(reader);
while(true)?{
String?line?=?bufferedReader.readLine();
if(line==null)?break;

String?regex?=?“[\\s]+“;
String[]?word?=?line.split(regex);

if(word.length? //將英文加入keyWord中,其對應的中文加入valueWord中,
//一組單詞的中英文在兩個ArrayList中的索引是一致的
keyWord.add(word[0]);
valueWord.add(word[1]);
}
}?catch(Exception?e){
????????????System.out.println(e);
????????}
finally?{
try{
????????????????bufferedReader.close();
????????????????reader.close();

????????????}catch(Exception?e){
????????????????System.out.println(e);
????????????}
}
}

private?int?getRandomIndex()
//隨機生成索引,用于隨機生成四個單詞選項
{
int?size?=?keyWord.size();
return?(int)?(Math.random()*100*size)%size;
}

HashMap?getChoice()
//生成四個選項
{
//防止生成的索引會有重復,保證四個選項不重復
List?indexTemp?=?new?ArrayList<>();
//生成的選項用HashMap存儲,以保持二者之間的對應關系
HashMap?choiceTemp?=?new?HashMap<>();
for?(int?i?=?0;?i?????????????int?index?=?getRandomIndex();
????????????while(?indexTemp.contains(?index?)?)
????????????//如果生成的索引有重復就一直生成直到沒有重復
????????????{
????????????????index?=?getRandomIndex();
????????????}
????????????
????????????indexTemp.add(?index?);
????????????
????????????choiceTemp.put(keyWord.get(index)?valueWord.get(index));
}

return?choiceTemp;
}
}

?屬性????????????大小?????日期????時間???名稱
-----------?---------??----------?-----??----
?????目錄???????????0??2017-12-25?12:13??Lab10_Words\
?????文件?????????295??2017-12-07?14:48??Lab10_Words\.classpath
?????文件?????????387??2017-12-07?14:48??Lab10_Words\.project
?????目錄???????????0??2017-12-25?12:13??Lab10_Words\.settings\
?????文件?????????598??2017-12-07?14:48??Lab10_Words\.settings\org.eclipse.jdt.core.prefs
?????文件???????73870??2017-12-07?15:22??Lab10_Words\CET6.txt
?????文件????????2836??2017-12-10?15:03??Lab10_Words\Dictionary.class
?????文件????????2161??2017-12-10?14:58??Lab10_Words\Dictionary.java
?????文件????????2463??2017-12-10?18:15??Lab10_Words\GivesWords.class
?????文件????????2107??2017-12-10?18:15??Lab10_Words\GivesWords.java
?????文件?????????611??2017-12-10?18:13??Lab10_Words\Test_Console$1.class
?????文件????????5939??2017-12-10?18:13??Lab10_Words\Test_Console.class
?????文件????????5883??2017-12-10?18:13??Lab10_Words\Test_Console.java

評論

共有 條評論