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

    }

}
相关推荐
Dxy123931021612 分钟前
js如何把字符串转数字
开发语言·前端·javascript
_饭团30 分钟前
字符串函数全解析:12 种核心函数的使用与底层模拟实现
c语言·开发语言·学习·考研·面试·蓝桥杯
Larry_Yanan30 分钟前
Qt网络开发之基于 QWebEngine 实现简易内嵌浏览器
linux·开发语言·网络·c++·笔记·qt·学习
2401_8318249637 分钟前
嵌入式C++驱动开发
开发语言·c++·算法
qingcyb43 分钟前
重复 id 对应的多个对象
开发语言·python
li星野1 小时前
[特殊字符] 模拟试卷一:C++核心与系统基础(90分钟)答案版
开发语言·c++·算法
天下无贼!1 小时前
【Python】2026版——FastAPI 框架快速搭建后端服务
开发语言·前端·后端·python·aigc·fastapi
Irissgwe1 小时前
c++特殊类设计
java·开发语言·c++
2301_816651221 小时前
C++中的享元模式变体
开发语言·c++·算法
m0_583203131 小时前
C++中的访问者模式变体
开发语言·c++·算法