Likes

Java Lab02_Ans2

Write a program to creat a class named EmployeeDetails and display a menue similar to the following menu:
--------------Menu--------
1. Enter Data 
2. Display Data 
3. Exit

Chosse the option
Thereafter, invoke the respective method according to the given menu input. The methods will contain appropriate message, such as the displayData() 
method will contain the message, displayData method is invoked.



ANSWER

1. Create a Java application, Lab02_Ans2.
2. Create a class, EmployeeDetails, in the Java application, Lab02_Ans2.
3. Replace the exisiting code in the EmployeeDetails.java file with following code:

   public class EmployeeDetails {

     public void showMenue ()  {
         int option;
         System.out.println("------------Menu--------");
         System.out.println("1. Enter Data");
         System.out.println("2. Display Data");
         System.out.println("3. Exit");
         System.out.println("\nChoose the option:  ");


         Option = 2;
switch (option)  {
case 1:
enterData();
break;
case2:
DisplayData();
break;
case3:
exitMenue();
break;
defalt:
System.out.println("Incorrect menu option");
showMenu();
break;
 }
}
public void enterData() {
System.out.println("enterData method is invoked");
}

public void enterData() {
System.out.println("displayData method is invoked");
}


public void enterData() {
System.out.println("exitMenu method is invoked");
System.exit(0);
}

public static void main(String[] args)  {
EmployeeDetails obj = new EmployeeDetails();
obj.showMenu();
  }
}

1 comment:

Unknown said...

all are mistakes in that just verify once kamal sharma