📄 hangmanlexicon.java
字号:
/* * File: HangmanLexicon.java * ------------------------- * This file contains a stub implementation of the HangmanLexicon * class that you will reimplement for Part III of the assignment. */import java.io.*;import java.util.ArrayList;import acm.util.*;public class HangmanLexicon { private ArrayList<String> list = new ArrayList<String>(); public HangmanLexicon(){ openFile(); readWordFromFile(); } public void openFile(){ try { br = new BufferedReader(new FileReader("HangmanLexicon.txt")); } catch (FileNotFoundException e) { e.printStackTrace(); } }/** Returns the number of words in the lexicon. */ public int getWordCount() { return list.size(); }/** Returns the word at the specified index. */ public String getWord(int index) { return list.get(index); /* switch (index) { case 0: return "BUOY"; case 1: return "COMPUTER"; case 2: return "CONNOISSEUR"; case 3: return "DEHYDRATE"; case 4: return "FUZZY"; case 5: return "HUBBUB"; case 6: return "KEYHOLE"; case 7: return "QUAGMIRE"; case 8: return "SLITHER"; case 9: return "ZIRCON"; default: throw new ErrorException("getWord: Illegal index"); }*/ } private void readWordFromFile() { String str; try { while(true){ str = br.readLine(); if(str==null) break; list.add(str); } } catch (IOException e) { e.printStackTrace(); } }; private BufferedReader br;}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -