0

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!!!

1
  • Create a plain old java object (a pojo), and populate your array (or an arraylist) with instances of that type. Commented Apr 19, 2019 at 2:17

3 Answers 3

1

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<>();
Sign up to request clarification or add additional context in comments.

Comments

0

Maybe you can use map to store the data.

Map<String, YourEmployeeObject> records = new HashMap<>();

Comments

0

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<>();

1 Comment

This is a verbatim copy-paste of another existing answer.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.