Question: Please explain this code [ java ] step by step public class employee { EmployeeNode head; public employee(){ head=null; } public void insertRecord(EmployeeNode

Please explain this code [ java ] step by step

public class employee {

EmployeeNode head; \\

public employee(){

head=null; \\

}

public void insertRecord(EmployeeNode heNode)

{

\\

if(head == null)

{

\\

head = heNode;

}

\\

else if(!searchRecord(heNode.getid()))

{

EmployeeNode temp = head; //

EmployeeNode prev = null; // while(temp!= null && temp.getid() < heNode.getid()) //

{

prev = temp; //

temp = temp.next; //

}

prev.next = heNode; //

heNode.next = temp; //

}

}

//Delete employee record

public int deleteRecord(int id)

{

if(searchRecord(id)) //

return -1; //

if(head.getid() == id) //

{

head = head.next; //

return 0; //

}

EmployeeNode temp = head; //

EmployeeNode prev = null; //

while(temp!= null && temp.getid() != id) //

{

prev = temp; //

temp = temp.next; //

}

//delete the record

prev.next = temp.next; //

return 0; //

}

//Update employee record

public void updateRecord(String name, int id, Date firstDay, String phoneNumber, String address, int workHours, double salary) //

{

if(!searchRecord(id)) //

System.out.print ("Employee record are not found:)"); //

else

{

EmployeeNode temp = head; //

while(temp.getid() != id) //

{

temp = temp.next; //

}

//

temp.setName(name); //

temp.setAddress(address); //

temp.setFirstDay(firstDay); //

temp.setPhoneNumber(phoneNumber);

temp.setWorkHours(workHours);

temp.setSalary(salary);

}

}

public void showRecord(int id) {

EmployeeNode tem = head; //

while(tem != null) { //

if(tem.id == id) { //

System.out.println("Name>>" + tem.name); //

System.out.println(" ID>> " + tem.id);

System.out.println(" First Day of Work>>" + tem.firstDay);

System.out.println(" Phone Number>>" + tem.phoneNumber);

System.out.println(" Address>>" + tem.address);

System.out.println(" Work Hours>> " + tem.workHours);

System.out.println(" Salary>>" + tem.salary);

return;

}

tem = tem.next; //

}

System.out.print ("Employee record are not found:)"); //

}

public boolean searchRecord(int id) //

{

EmployeeNode temp = head; //

while(temp != null){ //

if(temp.id == id) //

return true;

temp = temp.next; //

}

return false;

}

public void updateSalary(int ID)

{

if(!searchRecord(ID)) //

System.out.print ("Employee record are not found:)");

else{

EmployeeNode tem = head; //

while(tem.getid() != ID){ //

tem = tem.next; //

}

double salary = tem.getSalary(); //

int workHours = tem.getWorkHours(); //

double hoursal=salary/workHours; //

Scanner sc = new Scanner(System.in);

System.out.println("enter the extra hours");

int extra=sc.nextInt();

double increase=(hoursal)*(extra);

salary += increase;

tem.setSalary(salary);

System.out.println("the update salary is"+salary); //

}

}

}

This code for

: Create an employee Record Management system using linked list that can perform the following operations: Insert employee record Delete employee record Update employee record Show details of an employee Search an employee Update the salary of an employee

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!