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! ");
        }

    }

}
相关推荐
Bat U1 小时前
JavaEE|多线程初阶(七)
java·开发语言
谭欣辰2 小时前
C++ 排列组合完整指南
开发语言·c++·算法
foundbug9993 小时前
自适应滤除直达波干扰的MATLAB实现
开发语言·算法·matlab
XDH_CS3 小时前
MySQL 8.0 安装与 MySQL Workbench 使用全流程(超详细教程)
开发语言·数据库·mysql
小短腿的代码世界3 小时前
Qt实时盈亏计算深度解析:从持仓数据到动态盈亏展示
开发语言·qt
小康小小涵3 小时前
基于ESP32S3实现无人机RID模块底层源码编译
linux·开发语言·python
lzjava20243 小时前
Python的函数
开发语言·python
Awesome Baron4 小时前
skill、tool calling、MCP区别
开发语言·人工智能·python
Python私教4 小时前
GenericAgent PySide6 桌面应用深度解析:悬浮按钮 + 聊天面板的原生 Qt 方案
开发语言·数据库·qt