Hey all,
Im new to java and to java forums and need a dig out with an assignment Im working on.
I have an Employee Class with data members such as name, age etc. What I am trying to do is give each employee an ID when they are created. This is working: heres some of the construcor code:
import java.io.*;
import java.util.*;
public class Employee implements Serializable{
//data members
protected String firstname;
protected String surname;
protected int age;
protected char gender;
protected double annualSalary;
protected double bonus;
protected int empID;
protected static int noOfEmployees = 0;
//public int ID;
//constructors
//default constructor
public Employee(){
}
public Employee(String fName, String sName, int age1, char sex, double salary){
firstname = fName;
surname = sName;
age = age1;
gender = sex;
annualSalary = salary;
empID = ++noOfEmployees;
}
The problem is arising in the main class. I am prompting users to enter employee details, which I am adding to an ArrayList employees. I then output them and the empID is incrementing properly.
I write them correctly to a .data file. When I read the array back, all the previously enterer employees are there but when I add more employees, the ID is starting again at 1.
Please suggest a way around this??