Reputation: 35
I've got a small project I'm working on in which I'm trying to be able to pull data from a massive .txt file. The files got about 100 rows of the following:
Employee ID -- Salary -- Currently Employed == Employee Name == Paycheck Amounts
1 100 true == Michael == 300 200 100 300
2 200 true == Stephanie == 4000 2300 1000
Essentially I need to be able to call Employee ID at a later date and it shows their salary, employment etc. The other issue is that the paychecks could be either 1 paycheck or 50
I'm curious what are your thoughts on how to store this data? I can split the lines and what not to actually get it but what's the best method of storing it all at once.
Ideally what I would like to do is be able to call ID 2 and see its Stephanie and her last 3 paychecks were 4000, 2300 and 1000.
This seems like a bit of a big task for my small Java skills. Any thoughts / assitance would be highly appreciated!!!
Upvotes: 0
Views: 1058
Reputation: 1
Create a Employee Class ..
class Employee{
final int employeeId;
final int salary;
final boolean isCurrentlyEmployed;
final String employeeName;
final List<Integer> paycheckAmounts = new ArrayList<>();
Employee(
int employeeId,
int salary,
boolean isCurrentlyEmployed,
String employeeName) {
this.employeeId = employeeId;
this.salary = salary;
this.isCurrentlyEmployed = isCurrentlyEmployed;
this.employeeName = employeeName;
}
}
Then create employee object And add all employees to the list of employees
List<Employee> employees= new ArrayList<>();
Upvotes: 0
Reputation: 1
Maybe you can use map to store the data.
Map<String, YourEmployeeObject> records = new HashMap<>();
Upvotes: 0
Reputation: 46960
This is pretty standard stuff:
class EmployeeRecord {
final int employeeId;
final int salary;
final boolean isCurrentlyEmployed;
final String employeeName;
final List<Integer> paycheckAmounts = new ArrayList<>();
EmployeeRecord(
int employeeId,
int salary,
boolean isCurrentlyEmployed,
String employeeName) {
this.employeeId = employeeId;
this.salary = salary;
this.isCurrentlyEmployed = isCurrentlyEmployed;
this.employeeName = employeeName;
}
}
Put these in an array
List<EmployeeRecord> records = new ArrayList<>();
Upvotes: 1