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

Ask the user to enter the name of an employee and check if the person exists in

ID: 3915399 • Letter: A

Question

Ask the user to enter the name of an employee and check if the person exists in the array list, the search must be case insensitive. Display the message “EMPLOYEE found”, if the name is found in the list and display the employee’s corresponding employee information (name, hours, rate, and pay). Otherwise, display “EMPLOYEE NOT found”. EMPLOYEE is the name of the person. So, if the input for name is LILY TAYE, we’ll display something like LILY TAYE, 10 20 200. If the input for name is keke mamo , we’ll display something like keke mamo NOT found, if we don’t have an employee named keke mamo, in java.

Explanation / Answer

Please find the code as shown below

public class Employee

{

private String name;

private Double hours;

private Double rate;

private Double pay;

public Employee (String name, Double hours, Double rate, Double pay)

{

this. name = name;

this. hours = hours;

this.rate = rate;

this.pay = pay;

}

public String toString()

{

return "Employee[name = " + name + ", hours = " + hours + ", rate = " + rate ", pay = " + pay + "]";

}

public String getName()

{

return name;

}

public Double getHours()

{

return hours;

}

public Double getPay(){

return pay;

}

public Double getRate(){

return rate

}

public void setName(Double name)

{

this.name = name;

}

public void setHours(Double hours)

{

this. hours = hours;

}

public void setPay(Double pay)

{

this.pay = pay;

}

public void setRate(Double rate)

{

this. rate = rate;

}

Test.java

import java.util.Scanner;

import java.util.*;

public class Test

{

public static int menu()

{

System.out.println("Choose one option from following : ");

System.out.println("1) Add a new employee.");

System.out.println("2) Retrive an employee and check employee exist or not.");

System.out.println("3) Exit.");

Scanner sc = new Scanner(System.in);

return sc.nextInt();

}

public static void main(String[] args)

{

Arraylist< Employee> employeesByKey = new Arraylist <Employee>();

int menuStore = menu();

while(menuStore != 3)

{

System.out.println();

switch (menuStore)

{

case 1:

Scanner input1 = new Scanner(System.in);

System.out.println("Enter a name of the employee: ");

String str1 = input1.nextLine();

Scanner input2;

System.out.println("Enter hours: ");

Double str2 =Double.parseDouble(input2.nextLine());

Scanner input3;

System.out.println("Enter pay: ");

Double pay =Double.parseDouble(input3.nextLine());

Scanner input4;

System.out.println("Enter rate: ");

Double rate =Double.parseDouble(input4.nextLine())

Employee newEmp = new Employee(name, hours, rate, pay);

employeesByKey.(newEmp);

employeesByKey.put(1,newEmp);

  

System.out.println();

case 2:

Scanner input3 = new Scanner(System.in);

System.out.println("Please enter the name of the employee you wish to retrive: ");

String retStr = input3.nextLine();

System.out.println("check whether the employee name exist or not ");

if(employeesByKey. containsKey(retStr)) //checking employee exist or not

{

Employee recievedEmployee = employeesByKey.get(retStr);

System.out.println(“employee found”+recievedEmployee);

System.out.println("");

}

Else

{

System.out.println(“employee not found”+ retStr);

System.out.println("");

}

}

case 3:

break;

}

menuStore = menu();

}

}

}

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote