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

Java Write a program that simulates a very simple HR application for a company.

ID: 3704312 • Letter: J

Question

Java

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

Code

package com.chegg.vinoth;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Scanner;
import java.util.Set;

public class HRApplication {

class Employee {
  
  String firstName;
  String lastName;
  String id;
  String dob;
  String position;
  int salary;
  public Employee(String firstName, String lastName, String id, String dob, String position, int salary) {
   super();
   this.firstName = firstName;
   this.lastName = lastName;
   this.id = id;
   this.dob = dob;
   this.position = position;
   this.salary = salary;
  }
  
  public String toString() {
   return "Name: " + (firstName+", " + lastName) + "ID: " + id + " DOB: " + dob +" Position: " + position +" Salary: " + salary;
  }

  
}
public static void main(String[] args) {
  // TODO Auto-generated method stub
  Map<String, Employee> empMap = new HashMap<>();
  char option = 0;
  Scanner scan = new Scanner(System.in);
  do {
   
   System.out.println("Menu");
   System.out.println("1. List All Employee");
   System.out.println("2. Add Employee");
   System.out.println("3. Remove Employee");
   System.out.println("4. Edit Employee");
   System.out.print("Enter option: ");
   int userChoice = scan.nextInt();
   switch(userChoice) {
    case 1:
     Set<String> empKey = empMap.keySet();
     boolean flag = false;
     for(String key: empKey) {
      Employee e = empMap.get(key);
      System.out.println(e.toString());
      flag = true;
     }
     if(!flag)
      System.out.println("No employee to display!! Add Few");
     break;
    case 2:
     System.out.print("Enter First Name: ");
     String fname = scan.next();
     System.out.print("Enter Last Name: ");
     String lname = scan.next();
     System.out.print("Enter ID: ");
     String id = scan.next();
     System.out.print("Enter DOB: ");
     String dob = scan.next();
     System.out.print("Enter Position: ");
     String position = scan.next();
     System.out.print("Enter Salary: ");
     int salary = scan.nextInt();
     Employee e = new HRApplication().new Employee(fname, lname, id, dob, position, salary);
     empMap.put(id, e);
     break;
    case 3:
     System.out.print("Enter ID to remove employee: ");
     String id1 = scan.nextLine();
     empMap.remove(id1);
     break;
    case 4:
     System.out.print("Enter ID to edit employee: ");
     String id2 = scan.next();
     System.out.print("Enter First Name: ");
     String fname1 = scan.next();
     System.out.print("Enter Last Name: ");
     String lname1 = scan.next();
     System.out.print("Enter DOB: ");
     String dob1 = scan.next();
     System.out.print("Enter Position: ");
     String position1 = scan.next();
     System.out.print("Enter Salary: ");
     int salary1 = scan.nextInt();
     Employee e1 = new HRApplication().new Employee(fname1, lname1, id2, dob1, position1, salary1);
     empMap.put(id2, e1);
     break;
    default:
     System.out.println("Wrong choice");
   }
   System.out.print("Enter Y to continue or N to quit: ");
   option = scan.next().charAt(0);
  }while(option=='Y');
}

}

Output

Menu
1. List All Employee
2. Add Employee
3. Remove Employee
4. Edit Employee
Enter option: 1
No employee to display!! Add Few
Enter Y to continue or N to quit: Y
Menu
1. List All Employee
2. Add Employee
3. Remove Employee
4. Edit Employee
Enter option: 2
Enter First Name: Vinoth
Enter Last Name: Sivakumar
Enter ID: 123
Enter DOB: 12/12/1990
Enter Position: Manager
Enter Salary: 120000
Enter Y to continue or N to quit: Y
Menu
1. List All Employee
2. Add Employee
3. Remove Employee
4. Edit Employee
Enter option: 1
Name: Vinoth, SivakumarID: 123 DOB: 12/12/1990 Position: Manager Salary: 120000
Enter Y to continue or N to quit: Y
Menu
1. List All Employee
2. Add Employee
3. Remove Employee
4. Edit Employee
Enter option: 4
Enter ID to edit employee: 123
Enter First Name: Vinoth
Enter Last Name: Kumar
Enter DOB: 11/11/1991
Enter Position: CEO
Enter Salary: 130000
Enter Y to continue or N to quit: Y
Menu
1. List All Employee
2. Add Employee
3. Remove Employee
4. Edit Employee
Enter option: 1
Name: Vinoth, KumarID: 123 DOB: 11/11/1991 Position: CEO Salary: 130000
Enter Y to continue or N to quit: Y
Menu
1. List All Employee
2. Add Employee
3. Remove Employee
4. Edit Employee
Enter option: 2
Enter First Name: Gayathri
Enter Last Name: Venkat
Enter ID: 124
Enter DOB: 12/12/1995
Enter Position: CFO
Enter Salary: 1400000
Enter Y to continue or N to quit: Y
Menu
1. List All Employee
2. Add Employee
3. Remove Employee
4. Edit Employee
Enter option: 1
Name: Vinoth, KumarID: 123 DOB: 11/11/1991 Position: CEO Salary: 130000
Name: Gayathri, VenkatID: 124 DOB: 12/12/1995 Position: CFO Salary: 1400000

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