Create an Employee class in which you can store employees’ identification/employ
ID: 3691938 • Letter: C
Question
Create an Employee class in which you can store employees’ identification/employee number, first and last names, phone numbers, employee salary, the month and day that each employee was hired. Write an application that can prompt the user to capture employee data and uses serialization to store each employees’ record to a file called emplist.dat. In order to accomplish the above task, you need to do the following: 1. Declare six instance variables for the pieces of data about an employee as listed above in (a) i.e. private int employeeNumber private String firstName private String lastName, etc. 2. Create two constructors; one default and the other with parameters. 3. You are required to provide appropriate getters and setters. 4. Create an output stream for file au_emplist.dat to facilitate the writing of an object to a file. 5. Create an Employee[] array that will help in capturing employee data and writing it to a file as an array object.
Explanation / Answer
Answer for Question:
This below java code may help or solve the given problem statement.
1. Created class called Employee
2. Created setters and getters and two constrctors.
3. Created test class for employee
class Employee
{
private String firstName;
private String lastName;
private int phone;
private int salary;
private int month;
private int number;
Employee()
{
firstName = "hello";
lastName = "world";
phone = 12345;
salary = 4589;
month = 5;
number = 986;
}
public Employee(String first, String last, int ssn, int phone, int month, int salary)
{
firstName = first;
lastName = last;
number = ssn;
phone = phone;
month = month;
salary = salary;
}
public void setFirstName(String first)
{
firstName = first;
}
public String getFirstName()
{
return firstName;
}
public void setLastName(String last)
{
lastName = last;
}
public String getFirstName()
{
return lastName;
}
public void setPhone(int phone)
{
phone = phone;
}
public int getPhone()
{
return phone;
}
public void setNumber(int number)
{
number = number;
}
public int getNumber()
{
return number;
}
public void setSalary(int salary)
{
salary = salary;
}
public int getSalary()
{
return salary;
}
public int setMonth(int month)
{
month = month;
}
public int getMonth()
{
return month;
}
}
public class EmployeeTest
{
public static void main(String[] args)
{
Employee e1 = new Employee("Hart","nani",1256,8956,5,589);
FileOutputStream fout = new FileOutputStream("au_emplist.dat");
ObjectOutputStream oos = new ObjectOutputStream(fout);
oos.writeObject(e1);
oos.close();
System.out.println("Done");
}
}
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.