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