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

Q Search or enter website name CIS 23448 - Homework 4 - Spring 2018 Due Date: Ap

ID: 3701312 • Letter: Q

Question

Q Search or enter website name CIS 23448 - Homework 4 - Spring 2018 Due Date: April 10h 2018 Exercise 1 of 1: Write a program that simulates a very simple HR application for a company. Your program should be able to 1. List all the current employees 2. Add a new employee 3. Remove a current employee 4. (Extra credit: Edit current employee) You will need to create a class to instantiate a Person object (or Employee object) In the beginning, the console output should ask the user what they want to do (list, add, remove) The program should keep all the employees in an appropriate storage object of your choice (List Collection, Array, etc.), but make sure it is not limited to a maximum amount of people. The Employee class should have at minimum the following fields First Name Last Name Id . Date of Birth . Position . Salary

Explanation / Answer

copy and paste the following java code to af file hr.java

comiple code : javac hr.java

excute the class file : java hr

*Assuming that you are using linux operating system.

import java.util.*;

class Employee{

String firstName, lastName, dateOfBirth, position;

int id, salary;

public Employee(String firstName, String lastName, int id, String dateOfBirth, String position, int salary){

this.firstName = firstName;

this.lastName = lastName;

this.id= id;

this.dateOfBirth = dateOfBirth;

this.position = position;

this.salary = salary;

}

}

public class hr{

  public static void main(String args[]){

   Scanner takeIn = new Scanner(System.in);

Map<Integer,Employee> eList = new Hashtable<Integer,Employee>();

   while(true)

    {

System.out.println(" ************MENU****************");

System.out.println("Enter 0 to Quit");

System.out.println("Enter 1 to List All Current Employees");

System.out.println("Enter 2 to ADD a new Employee");

System.out.println("Enter 3 to Remove a Current Employee");

System.out.println("Enter 4 to Edit a Current Employee");

int check = takeIn.nextInt();

if(check==0)

break;

else if(check==1){

System.out.println("<---Listing all current employees---_>");

for(Map.Entry<Integer, Employee> entry:eList.entrySet()){

int key=entry.getKey();

Employee e=entry.getValue();

System.out.println(key+" Details:");

System.out.println(e.id+" "+e.firstName+" "+e.lastName+" "+e.position+" "+e.salary);

}

}

else if(check==2){

System.out.println("Please Fill the following form to add a new employee");

System.out.println("Id");

int id = takeIn.nextInt();

takeIn.nextLine();

System.out.println("First Name");

String fn = takeIn.nextLine();

System.out.println("Last Name");

String ln = takeIn.nextLine();

System.out.println("Date Of Birth");

String dob = takeIn.nextLine();

System.out.println("Position");

String pos = takeIn.nextLine();

System.out.println("Salary");

int sal = takeIn.nextInt();

eList.put(id, new Employee(fn,ln,id,dob,pos,sal));

}

else if(check==3){

System.out.println("Enter the Id to remove that employee");

int id = takeIn.nextInt();

eList.remove(id);

}

else if(check==4){

System.out.println("Will add this in another edit.Sorry for the inconvience.It is due to time");

}

    }

  }

}