I am building a small project for my self and every time a Employee
is created they are given an ID.
This Id is generated by finding the .size() of a ArrayList.
//Creating the Employee Id
int employeeID = listEmployee.size() +1;
I know this is a bad idea because when removing an employee the Id's will star to duplicate.
This is the function I am using when creating a Employee
public void addHiredEmployee() {
Scanner kb = new Scanner(System.in);
System.out.println("Enter Name: ");
String nameEmployee = kb.nextLine();
//Creating Id for the employee by getting the last employee in the list
//getting their Id and adding 1 to it
Employee lastEmployee = listEmployee.get(listEmployee.size() -1);
int idCreation = lastEmployee.getEmployeeId();
int employeeID = idCreation + 1;
System.out.println("Enter password");
String employeePassword = kb.nextLine();
System.out.println("Your log-in Id is: " + employeeID);
Employee employeeHired = new Employee(nameEmployee, employeeID,
employeePassword);
listEmployee.add(employeeHired);
kb.close();
listEmployee.toString();
}
I know about using UUID but as the Employee
Id will be used to login I cant really expect that some one enters a full UUID.
Is there a simple way of creating a random Id or even can I use the last 4 characters of a UUID just for the login and how could I implement selecting the last 4 characters?