I have an ArrayList
storing employee information (Name, employee score, and date hired for each employee) from a .dat file. I'm trying to loop through the ArrayList to put teams of employees together so that their collective score is over 20. I'm trying to do this by masking out each bit in the subset.
This is the .dat file:
Francis Pelaez, 9, 3/7/1992
Marlo Frankel, 4, 4/4/2001
Suzanne Engelmann, 2, 5/20/1992
Gertrude Anderson, 5, 8/16/2009
Delmer Mickels, 3, 1/19/1994
Here is where I load the employees into the ArrayList from the .dat file:
public static ArrayList<Employee> loadEmployees() {
ArrayList<Employee> employees = new ArrayList<Employee>();
//load employees from employees.dat here...
try (Scanner scanner = new Scanner(new FileInputStream("employees.dat"))) {
while(scanner.hasNextLine()) {
String line = scanner.nextLine();
String[] tokens = line.split(", ");
String fullName = tokens[0];
String score = tokens[1];
String dateHired = tokens[2];
System.out.println("Full Name: " + fullName);
System.out.println("Employee Score: " + score);
System.out.println("Date Hired: " + dateHired);
System.out.println("-----------------------------------");
employees.add(new Employee(fullName, score, dateHired));
}
} catch (FileNotFoundException ex) {
System.out.println("File not found: " + ex.getMessage());
}
return employees;
}
This is my saveTeams() method:
public static void saveTeams() {
//load employee objects and then query them
ArrayList<Employee> employees = loadEmployees();
//enumerate all subsets of employees and print
//any teams found with a collective employee
//rating above 20
int allMasks = (1 << employees.size());
for (int i = 1; i < allMasks; i++) {
for (int j = 0; j < employees.size(); j++) {
if ((i &(1 << j)) > 0) //the j-th element is used
System.out.print((j + 1) + " ");
System.out.println();
}
}
}
Once I run saveTeams(), it seems to show all combinations of numbers that are lesser than the size of my ArayList. My question is how would I go about comparing the scores of each employee rather than what index they are in the ArrayList?
Thank you all for your time.