Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

***Please check sample run before answering Thank You*** Create a class called E

ID: 3706782 • Letter: #

Question

***Please check sample run before answering Thank You***

Create a class called Employee that includes four pieces of information as instance variables (declared as private):

•a first name (type String), firstName

•a last name (typeString), lastName

•a employee ID (type integer), employeeId

•a salary (type double), salary

Your class should have three different constructors that initializes the four instance variables.

A default constructor will have no parameters; a constructor that includes the first and last names as parameters and a constructor that includes all instance variables as parameters:

•public Employee()

•public Employee( String last, String first )

•public Employee( String last, String first, int id, double wage )

Create a set and a get method for each of the four instance variables.

If the monthly salary is not positive, set it to 0.0.

Create a toString method() which provides a formatted output in a String return value, to be used when the application prints the object.

Create a equals method() to compare a String parameter with the String that is stored in the lastName instance parameter.

Add three Constructors to the Employee class to properly create an object. These default constructor will contain no parameters and will initialize the four instances variables. The second constructor will include the first and last names as parameters, which will set the instance variables, initialize the other two.

The third constructor will include all four parameters, which will set the instance variables.

Add four set (mutator) methods and four get (accessor) methods, for each of the four instance variables. The mutator and accessor method should be named appropriately to match the variables: i.e., setFirstName and getFirstName.

These methods should be defined as public, so they are accessible by the application.

The application shell has been created, which is a simple menu program.

Enter Selection

===============

A> Add new Employee

E> Edit Employee

L> List Employees

Q> Quit

If the user selects ‘Add’, the application must be modified to prompt the user for appropriate employee information and set the specific information using the mutator methods you created in

Run the EmployeeApp, choose <List>. The object references are displayed on the screen.

Add a toString method to the Employee class which returns a formatted string pertaining to the employee information. Play with returning different formatted strings, this choose <List> when running the application. This will demonstrate how this method controls the format of the employee object. String toString()

If you choose ‘Edit’ from the EmployeeApp, the application will prompt for a last name. The application will do a comparison of this last name to each employee object. Add a equals method to the Employee class which accepts the last name String that was entered from the menu and return either true or false. This method will compare the object last name variable (this.lastName) with the last name that was prompted for in the application. If the names match, return true. If the names do not match, return false.

public Boolean equals( String name )

Sample Output

Enter Selection

===============

A> Add new Employee

E> Edit Employee

L> List Employees

Q> Quit

Select: l

Mitchum, Robert

ID Number: 120402

Salary   : $34000.00

Ryan,

Cornelius

ID Number: 0

Salary   : $0.00

Asimov, Isaac

ID Number: 0

Salary   : $0.00

null

null

Enter Selection

===============

A> Add new Employee

E> Edit Employee

L> List Employees

Q> Quit

Select: a

Enter Last Name      : Frost

Enter

First Name     : Jack

Enter Employee ID    : 93842

Enter Employee Salary: 34500

Enter Selection

===============

A> Add new Employee

E> Edit Employee

L> List Employees

Q> Quit

Select: l

Mitchum, Robert

ID Number: 120402

Salary   : $34000.00

Ryan, Cornelius

ID Number: 0

Salary   : $0.00

Asimov, Isaac

ID Number: 0

Salary   : $0.00

Frost, Jack

ID Number: 93842

Salary   : $34500.00

null

Enter Selection

===============

A> Add new Employee

E> Edit Employee

L> List Employees

Q> Quit

Select: e

Enter Last Name of Employee to Edit: Ryan

Enter Employee ID    : 982734

Enter Employee Salary: 76250

Enter Selection

===============

A> Add new Employee

E> Edit Employee

L> List Employees

Q> Quit

Select: l

Mitchum, Robert

ID Number: 120402

Salary   : $34000.00

Ryan, Cornelius

ID Number: 982734

Salary   : $76250.00

Asimov, Isaac

ID Number: 0

Salary   : $0.00

Frost, Jack

ID Number: 93842

Salary   : $34500.00

null

Enter

Selection

===============

A> Add new Employee

E> Edit Employee

L> List Employees

Q> Quit

Explanation / Answer

Screenshot

--------------------------------------------------------------------------------------------

Program

//package importing for user input reading and input/output manipulation
import java.io.*;
import java.util.*;
//Employee class generation
class Employee{
   //Member variables
   String firstName,lastName;
   int eId;
   double salary;
   static int count = 0; //to track the no. of employees
   //Default constructor
   Employee(){
       firstName=null;
       lastName=null;
       eId=0;
       salary=0.0;
   }
   //Constructor with two parameters
   Employee(String firstName,String lastName){
       super();
       this.firstName=firstName;
       this.lastName=lastName;
       count++;
   }
   //Constructor with 4 parameters
       Employee(String firstName,String lastName,int eId,double salary){
           super();
           this.firstName=firstName;
           this.lastName=lastName;
           this.eId=eId;
           if(salary==0) {
               this.salary=0.0;
           }
           else {
               this.salary=salary;
           }
          
           count++;
       }
      
       //Mutator to set values
       public void setFirstName(String firstName) {
           this.firstName=firstName;
       }
       public void setLasttName(String lastName) {
           this.lastName=lastName;
       }
       public void setEId(int eId) {
           this.eId=eId;
       }
       public void setSalary(double salary) {
           if(salary==0) {
               this.salary=0.0;
           }
           else {
               this.salary=salary;
           }
          
       }
       //Acessors to get values
        public String getFirstName() {
           return firstName;
       }
        public String getLasttName() {
           return lastName;
       }
       public int getEId() {
           return eId;
       }
       public double getSalary() {
           return salary;
       }
       //toString method to print
       public String toString() {
           return firstName+","+lastName+" ID Number: "+eId+" Salary: $"+salary;
       }
  
}
//Main class
public class EmployeeProgram {
   //Main Method
   public static void main(String[] args) {
       //Scanner to read user choice
       Scanner sc=new Scanner(System.in);
       String loop="true";
       String fName="",lName="";
       int empId=0;
       double salary=0.0;
       List<Employee> list = new ArrayList<Employee>();
       while(loop=="true") {
           //Menu creation
           System.out.println("Enter Selection");
           System.out.println("================");
           System.out.println("A> Add new Employee L> List Employees Q>Quit");
           System.out.println("Select: ");
           String ch=sc.next();
           //User selection operation
           switch(ch) {
           //Adding employee details
           case "a":
           case "A":
               //Ask user to set enter details
               System.out.println("Enter First name : ");
               fName=sc.next();
               System.out.println("Enter Last name : ");
               lName=sc.next();
               System.out.println("Enter Employee Id : ");
               empId=sc.nextInt();
               System.out.println("EnterSalary: ");
               salary=sc.nextDouble();
               //Add into array list
               list.add(new Employee(fName, lName,empId,salary));
               break;
               //Print employee details
           case "l":
           case "L":
               for (Employee s : list) {
                   System.out.println(s.toString());
               }
              
               break;
               //Exit from program
           case "q":
           case "Q":
               System.out.println("Thank You !!!!");
               loop="false";
               System.exit(0);
               break;
          
              
       }
      
              
              
   }

}
}


---------------------------------------------------------------------

Output:-

Enter Selection
================
A> Add new Employee
L> List Employees
Q>Quit
Select:
a
Enter First name :
harry
Enter Last name :
Potter
Enter Employee Id :
1023
EnterSalary:
10000
Enter Selection
================
A> Add new Employee
L> List Employees
Q>Quit
Select:
l
harry,Potter
ID Number: 1023
Salary: $10000.0
Enter Selection
================
A> Add new Employee
L> List Employees
Q>Quit
Select:
q
Thank You !!!!