wwwwwwjava

复制代码
public class Word {
    private String word;
    private String meaning;

    public Word(String word,String meaning){
        this.word=word;
        this.meaning=meaning;
    }

    public String getWord(){
        return  word;
    }

    public void setWord(String word){
        this.word=word;
    }

    public String getMeaning(){
        return meaning;
    }

    public void setMeaning(String meaning) {
        this.meaning = meaning;
    }

    @Override
    public String toString() {
        return word+": "+meaning;
    }
}
复制代码
import java.util.Scanner;

public class VocabularyManager {
    Word[] w=new Word[100];
    int count=0;
    Scanner sc =new Scanner(System.in);

    public VocabularyManager(){
        w[0]=new Word("Adaption","Adjusting to Current Environment");
        w[1]=new Word("Temptation","Getting attracted to something and can't resist");
        count=2;
    }

    public void displayAll(){
        for(int i=0;i<count;i++){
            System.out.println(w[i].getWord()+"="+w[i].getMeaning());
        }
    }

    public void searchWord(String word_name){
        boolean flag=false;
        for(int i=0;i<count;i++){
            if(w[i].getWord().equals(word_name)){
                System.out.println("Word is Found ");
                System.out.println(w[i].getWord()+"="+w[i].getMeaning());
                flag=true;
                break;
            }
        }
        if(!flag){
            System.out.println("No Such word exist in the Dictionary");
        }
    }

    public void addWord(){
        System.out.println("Enter new Word: ");
        String newWord=sc.nextLine();
        System.out.println("Enter meaning: ");
        String newMeaning=sc.nextLine();

        if(count<w.length){
            w[count]=new Word(newWord,newMeaning);
            count++;
            System.out.println("Word added ");
        }
        else{
            System.out.println("Full!");
        }

    }

    public void deleteWord(){
        System.out.println("Enter Word to delete: ");
        String word_name=sc.nextLine();
        boolean flag=false;

        for(int i=0;i<count;i++){
            if(w[i].getWord().equals(word_name)){
                flag=true;
                for(int j=i;j<count-1;j++){
                    w[j]=w[j+1];
                }
                count--;
                System.out.println("Word deleted ");
                break;
            }
        }

        if(!flag){
            System.out.println("Word not found!");
        }
    }

    public void updateWord(){
        System.out.println("Enter word to update: ");
        String newWord=sc.nextLine();
        boolean flag=false;

        for(int i=0;i<count;i++){
            if(w[i].getWord().equals(newWord)){
                flag=true;
                System.out.println("Enter word new meaning: ");
                String newMeaning=sc.nextLine();
                w[i].setMeaning(newMeaning);
                System.out.println("Word updated successfully");
                break;
            }
        }

        if(!flag){
            System.out.println("");
        }
    }

    public void teacherMenu(){
        int choice;



        do {
            System.out.println("Teacher Menu: ");
            System.out.println("0. Exit ");
            System.out.println("1.display All ");
            System.out.println("2.search word");
            System.out.println("3.add word ");
            System.out.println("4.delete word");
            System.out.println("5.update word");

            System.out.println("Enter your choice: ");
            choice=sc.nextInt();
            sc.nextLine();

            switch (choice) {
                case 0:
                    System.out.println("Exit!");
                    break;
                case 1:
                    displayAll();
                    break;
                case 2:
                    System.out.println("Enter word to search: ");
                    String S_word = sc.nextLine();
                    searchWord(S_word);
                    break;
                case 3:
                    addWord();
                    break;
                case 4:
                    deleteWord();
                    break;
                case 5:
                    updateWord();
                    break;
                default:
                    System.out.println("Invalid operation! ");
            }
        }while(choice!=0);
    }


    public void studentMenu(){
        int choice;

        do {
            System.out.println("Student Menu: ");
            System.out.println("0. Exit ");
            System.out.println("1.display All ");
            System.out.println("2.search word");


            System.out.println("Enter your choice: ");
            choice=sc.nextInt();
            sc.nextLine();

            switch (choice) {
                case 0:
                    System.out.println("Exit!");
                    break;
                case 1:
                    displayAll();
                    break;
                case 2:
                    System.out.println("Enter word to search: ");
                    String S_word = sc.nextLine();
                    searchWord(S_word);
                    break;
                default:
                    System.out.println("Invalid operation! ");
            }
        }while(choice!=0);

    }

    public boolean checkLogin(String username,String password,String identity){
        if (identity.equals("teacher")){
            return username.equals("teacher")&&password.equals("teacher123");
        }else if(identity.equals("student")){
            return username.equals("student")&&password.equals("student123");

        }
        return false;
    }




    public static void main(String[] args) {
        VocabularyManager m=new VocabularyManager();
        Scanner sc=new Scanner(System.in);

        System.out.println("*** Vocabulary Manager ***");
        System.out.println("Please Enter your identity: ");


        String identity=sc.nextLine();

        System.out.println("Username: ");
        String username=sc.nextLine();
        System.out.println("Password: ");
        String password=sc.nextLine();

        boolean result=m.checkLogin(username,password,identity);

        if(result){
            System.out.println("Login successfully! ");

            if(identity.equals("teacher")){
                m.teacherMenu();
            }else{
                m.studentMenu();
            }
        }else{
            System.out.println("Login failed! ");
        }

    }

}
相关推荐
言之。18 分钟前
【Python】免费的中文 AI 配音方案
开发语言·人工智能·python
天天进步201535 分钟前
Python全栈项目:从零手操一个高性能 API 网关
开发语言·python
Java面试题总结37 分钟前
java高频面试题(2026最新)
java·开发语言·jvm·数据库·spring·缓存
安生生申2 小时前
使用pygame实现2048
开发语言·python·pygame
魔法阵维护师2 小时前
从零开发游戏需要学习的c#模块,第十六章(安装 MonoGame 并创建第一个窗口)
学习·游戏·c#·monogame
hh.h.2 小时前
CANN算子开发入门:从零开始写第一个Ascend C算子
c语言·开发语言·cann·c算子
吴可可1232 小时前
用Teigha修改并保存CAD文件
数据库·算法·c#
AI科技星3 小时前
全域数学·第三部·数术几何部·平行网格卷 完整专著目录(含拓扑发展史+学科定位·终稿)
c语言·开发语言·网络·量子计算·agi
SunnyDays10113 小时前
Java 读写 Excel 公式:从基础到高级的实战总结
java·开发语言·excel
wb043072013 小时前
Java 26
java·开发语言