java0004——迷你小项目--英汉小字典

本文介绍了一个使用Java编写的迷你英汉小字典项目,涵盖了流程图解析、代码设计思路以及需要注意的问题,如Scanner的next()与nextLine()方法的区别,以及父类与子类命名的注意事项。提供了Word、dictionaryFunction、LookUpDictionary和dictionaryDemo四个关键类的代码示例。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

  1. 流程图
  • 代码思路流程图
    在这里插入图片描述
  • 代码设计流程图
    在这里插入图片描述
  1. 注意的问题
  • Scanner next()与nextline()的区别 :
    一句话 nextline()可以输入空格、tab等特殊的字符,而且还可以避免在连续输入多个字符串的时候出现输入问题
  • 父类与子类在这里尽量不要重名
  1. 代码
  • Word.java
package MyDictionary;

public class Word {
    
    
	String eWord;
	String cWord;

	public String geteWord() {
    
    
		return eWord;
	}

	public void seteWord(String eWord) {
    
    
		this.eWord = eWord;
	}

	public String getcWord() {
    
    
		return cWord;
	}

	public void setcWord(String cWord) {
    
    
		this.cWord = cWord;
	}

	public Word(String eWord, String cWord) {
    
    
		this.eWord = eWord;
		this.cWord = cWord;
	}

	public Word() {
    
    
		this.eWord = null;
		this.cWord = null;
	}

	public String toString() {
    
    
		return (this.eWord + "===" + this.cWord);
	}
}
  • dictionaryFuction .java
package MyDictionary;
public class dictionaryFuction {
    
    
	Word[] words;
	int count;

	public dictionaryFuction() {
    
    
		// TODO Auto-generated constructor stub
		words = new Word[100];
		count = 0;
	}

	// 添加单词
	public boolean add(Word word) {
    
    
		if (count < 100) {
    
    
			this.words[this.count++] = word;
			return true;
		} else
			return false;
	}

	// 查询单词
	public Word searchWord(String word) {
    
    
		for (int i = 0; i < count; i++) {
    
    
			if (this.words[i
评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值