Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

can you fix the error in this? it does not save the entered start date. import java.io . * ; import java.util. * ; class

can you fix the error in this? it does not save the entered start date.
import java.io.*;
import java.util.*;
class EmployeeRecordManagement
{
private Employee head;
//Constructor
public EmployeeRecordManagement()
{
head = null;
}
//done
private boolean recordExists(int id)
{
Employee current = head;
if(head == null)
{
return false;
}
while (current != null && head != null)
{
if (current.id == id)
{
return true;
}
current = current.next;
}
return false;
}
//done
public void insert(String name, int id, String startDate, String phoneNumber, String address, int workHours, double salary) throws FileNotFoundException
{
Employee newEmployee = new Employee(name, id, startDate, phoneNumber, address, workHours, salary);
if (head == null)
{
newEmployee.next = head;
head = newEmployee;
}
else
{
Employee current = head;
while (current.next != null && current.next.id < newEmployee.id)
{
current = current.next;
}
if(head == current)
{
newEmployee.next = head;
head = newEmployee;
}
else
{
newEmployee.next = current.next;
current.next = newEmployee;
}
}
System.out.println("******************************************");
System.out.println(" Employee record added successfully.");
System.out.println("******************************************
");
}
//done
private void loadRecordsFromFile() throws FileNotFoundException
{
File emp = new File("EmployeeRecord.txt");
Scanner load = new Scanner(emp); //this
if(emp.exists())
{
while(load.hasNext())
{
String name = load.nextLine();
int id = load.nextInt();
String startDate = load.nextLine();
String phoneNumber = load.nextLine();
String address = load.nextLine();
int workHours = load.nextInt();
double salary = load.nextDouble();
load.nextLine();
insert(name,id,startDate,phoneNumber,address,workHours,salary);
}
load.close();
}
}
//done
private void saveRecordsToFile() throws IOException
{
Employee current = head;
File emp = new File("EmployeeRecord.txt");
FileWriter save = new FileWriter(emp);
while (current != null)
{
save.write("Name: "+ current.name +"
"+"ID: "+ current.id +"
"+ "Start date: "+ current.startDate +"
"
+ "Phone number: "+ current.phoneNumber +"
"+ "Address: "+ current.address
+"
"+ "Work hours: "+ current.workHours +"
"+ "Salary: "+ current.salary +"
");
current = current.next;
}
save.close();
}
//done
public int delete(int id)
{
Employee current = head;
Employee temp = null;
if (current != null && current.id == id)
{
head = current.next;
return -1;
}
while (current != null && current.id != id)
{
temp = current;
current = current.next;
}
if (current == null)
{
return 0;
}
temp.next = current.next;
return -1;
}
public void updateEmp(int id)
{
Scanner update = new Scanner(System.in);
Employee current = head;
String name, startDate, phoneNumber, Address;
int workHours, again =0, choice;
double Salary;
if(!recordExists(id))
{
System.out.println("----------------------------------------------------");
System.out.println(" The employee with ID "+ id +" is not found");
System.out.println("----------------------------------------------------");
}
else
{
while(current != null)
{
if(current.id == id)
{
break;
}
current = current.next;
}
}
do
{
System.out.p

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Databases On The Web Designing And Programming For Network Access

Authors: Patricia Ju

1st Edition

1558515100, 978-1558515109

More Books

Students also viewed these Databases questions

Question

3. Identify cultural universals in nonverbal communication.

Answered: 1 week ago