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

A local company has asked you to write a program which creates an Employee class

ID: 3859745 • Letter: A

Question

A local company has asked you to write a program which creates an Employee class, a vector of Employee class objects, and fills the objects with employee data, creating a "database" of employee information. The program allows the user to repeatedly search for an employee in the vector by entering the employee's ID number and if found, display the employee's data. The Employee_C class should have the following data: -employee full name -employee ID number (int of 6 digits) -employee salary -employee gender (char) -static variable to hold the total of all employees' salaries Also create the appropriate constructors and getter and setter member functions for the class variables (hint: an employee's salary should be set, not accumulated; and before a salary is set and added to the static variable, the prior salary should be removed from the static variable). In main, declare two vectors: one for Employee_C class objects, and one for ID numbers (int). The program will have three functions: 1) Fill_Vector: have the user repeatedly enter employees' data into Employee objects (unknown number of employees), and place the objects into the Employee vector (hint: fill an object, then place it into the vector). 2) Extract_ID: retrieve the employees' IDs from the Employee vector and place them into the ID vector, i. e., create a vector of employee IDs. 3) Find_Employee: in main the user will repeatedly enter employee IDs and call this function, which will search the ID vector with the entered ID (must use STL algorithm "binary_search") and return either true or false via the function's return type. Then in main: if the entered ID was found display the employee's data (from the employee vector) plus the total of all employee salaries (using the static variable), or if not found display an error message along with the erroneous ID number. Enter the following data (full name, ID, salary, gender): -Joe Jones, 123456, $60,000, M -Jill James, 987654, $65,000, F -Leonardo DeApe, 567890, $20,000, M Then have the user enter the following IDs to search for an employee: -987654 -123456 -135790 (should produce an error)

Explanation / Answer

Hi,

Please see below the classes:

Thanks!

Employee.java

public class Employee {

private static double TOTAL_SALARY =0;

private String fullName;

private String id;

private double salary;

private String gender;

//constructors

public Employee(String fullName,String id,double salary,String gender){

this.fullName = fullName;

this.id = id;

this.salary = salary;

TOTAL_SALARY =TOTAL_SALARY+ this.salary;

this.gender = gender;

}

//Getters and Setters

public String getFullName() {

return fullName;

}

public void setFullName(String fullName) {

this.fullName = fullName;

}

public String getId() {

return id;

}

public void setId(String id) {

this.id = id;

}

public double getSalary() {

return salary;

}

public void setSalary(double salary) {

this.salary = salary;

}

public String getGender() {

return gender;

}

public void setGender(String gender) {

this.gender = gender;

}

}

EmployeeDriver.java

import java.util.Scanner;

import java.util.Vector;

public class EmployeeDriver {

//Employee vector

static Vector<Employee> employees = new Vector<Employee>();

static Vector<String> ids = new Vector<String>();

static Scanner scan = new Scanner(System.in);

public static void main(String[] args) {

System.out.println("Please enter employee data");

Fill_Vector();

//Extracting the IDs

Extract_ID();

//finding the data

String choice= "C";

while(!"Q".equalsIgnoreCase(choice)){

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

String id = scan.nextLine();

boolean found =Find_Employee(id);

if(found){

for(Employee emp: employees){

if(id.equalsIgnoreCase(emp.getId())){

System.out.println("Name: "+emp.getFullName()+"ID: "+emp.getId()+"Gender: "+emp.getGender()+"Salery : $"+emp.getSalary());

}

}

}

else{

System.out.println(id +" not found!");

}

System.out.println("Enter C cto continue, Q to quit");

choice = scan.nextLine();

}

}

/**

* have the user repeatedly enter employees' data into Employee objects (unknown number of employees),

* and place the objects into the Employee vector (hint: fill an object, then place it into the vector).

*/

public static void Fill_Vector(){

String choice= "C";

while(!"Q".equalsIgnoreCase(choice)){

System.out.println("Full name: ");

String fullName = scan.nextLine();

System.out.println("Id(6 digits): ");

String id = scan.nextLine();

System.out.println("Salary: ");

double salary = Double.valueOf(scan.nextLine());

System.out.println("Gender M/F : ");

String gender = scan.nextLine();

//Creating Employe eobject

Employee emp = new Employee(fullName, id, salary, gender);

employees.add(emp); //Adding to vector

System.out.println("Q to quit,C to Continue");

choice = scan.nextLine();

}

}

/**

* retrieve the employees' IDs from the Employee vector and place them into the ID vector,

* i. e., create a vector of employee IDs.

*/

public static void Extract_ID(){

for(Employee emp: employees){

ids.add(emp.getId()); //Adding to the vector

}

}

/**

* user will repeatedly enter employee IDs and call this function, which will search the ID vector with the entered ID

* @return

*/

public static boolean Find_Employee(String id){

if(ids.contains(id)){ //Calling Find_Employee,if id present in ids vector

return true;

}

return false;

}

}

Sample output:

Please enter employee data
Full name:
Joe Jones
Id(6 digits):
123456
Salary:
60000
Gender M/F :
M
Q to quit,C to Continue
C
Full name:
Jill James
Id(6 digits):
987654
Salary:
65000
Gender M/F :
F
Q to quit,C to Continue
C
Full name:
Leonardo DeApe
Id(6 digits):
567890
Salary:
20000
Gender M/F :
M
Q to quit,C to Continue
Q
Enter ID:
987654
987654 not found!
Enter C cto continue, Q to quit
C
Enter ID:
123456
Name: Joe JonesID: 123456Gender: MSalery : $60000.0
Enter C cto continue, Q to quit
C
Enter ID:
135790
135790 not found!
Enter C cto continue, Q to quit
Q

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