Likes

java Lab09_Solution2.

David has been assigned a task of creating an application to store the employee details. For this, David decided to display the following menu when the application starts:

1.  Entry Data
2.  Display Data
3.  Exit

Thereafter, he decides to implement the following functionalities:

-When a user selects the option to entry data, the employee details. such as employee ID, employee name, department, designation, date of joining, date of birth, marital status, and date of marrige, should be captured. In addition, a functionality to add more records should be implemented.

-When a user selects the option to display the data, the stored data muust be displayed.

-When a user selects the option to exit, the application must be terminated. Further, David needs to implement user- defined exceptions for the following cases:

- If the menu input entered by the user is other than1,2,or3, an appropriate message should be displayed to the user and the application must restart.

- If the employee ID does not start with the aplhabet, e or E, an appropriate message should be displayed to the user and the application must terminate.

Help David to implement the preceding functionalities.


SOLUTION


1- Create a Java application, Lab09_Solution2.
2- Create a class, SelectionExeption, in the Java application, Lab09_Solution2.
3- Replace the exiting code in the SelectionException.java file with the following code:

class SelectionException extands Exception  {

selectionException ()   {
System.out.println("Invalid input, Please select a valid menu option");

}
}
4- Create a class, PatternException, in the Java application, Lab09_Solution2.
5- Replace the exisiting code in the PatternException.java file with the following code:

public class PatternException extends RuntimeException  {

public PatternException()  {

System.out.println("Invalid pattern for Employee ID...");
}

public PatternException(String msg)   {
super(msg);
}
}
6- Create a class, EmployeeDetails, in the Java application,Lab09_Solution2.
7- Replace the existing code in the EmployeeDetails.java file with the following code:

import java.until.Scanner;

public class EmployeeDetails  {

String employeeDetails[] [] = new String[100] [8];

public void showMenu () throws SelectionException  {
   int option;
Scanner sc = new Scanner (System.in);

System.out.println("----------Menu--------");
System.out.println("1. Entry Data");
System.out.println("2. Display Data");
System.out.println("3. Exit");
System.out.print("\nchoose the option: ");

option = sc.nextInt() ;

No comments: