我正在做一个关于创建交互式字典的班级项目。在这里你搜索一个单词,输出是单词、词性和定义。
看起来像这样。
搜索: Reddit Reddit名词:一个充斥着迷因的地方。
我遇到的问题是,我们必须将原始数据存储在一组枚举对象中。“每个关键字、每个词性和每个定义都必须存储在单独的数据字段中”。
这是否意味着我必须将所有关键字存储在枚举中,将所有词性存储在枚举中,将所有定义存储在同一个类中的单独枚举中?“单独的数据字段”是什么意思?
发布于 2019-02-13 11:29:32
这里有一种方法:
import java.util.HashMap;
public class Main {
HashMap<String, Word> dictionary = new HashMap<String, Word>();
}
class Word{
private String word;
private WordType type;
private String definition;
public Word(String word, WordType type, String definition) {
this.setWord(word);
this.setType(type);
this.setDefinition(definition);
}
public String getDefinition() {
return definition;
}
public void setDefinition(String definition) {
this.definition = definition;
}
public WordType getType() {
return type;
}
public void setType(WordType type) {
this.type = type;
}
public String getWord() {
return word;
}
public void setWord(String word) {
this.word = word;
}
}
enum WordType{
Noun,
Verb,
etc;
}这是在你的字典项目中实现“Word”的一种方式。有了Word类中的toString()覆盖和一些文件IO,您就可以开始工作了。
https://stackoverflow.com/questions/54661947
复制相似问题