Skip to content

9 File IO and grouping

  1. If needed, retrieve the OOP Company project up to chapter 8 from DLO. It contains the classes as you left them at the end of chapter 8.

  2. Create a Data folder in the same folder as your src folder.

  3. Download the files Departments.txt and People.csv from DLO and place them in the Data folder.

  4. Read the departments from the text file Departments.txt and add them to a list named departments. Note: the name and location of the department are on two different lines in the text file.

  5. Read the various persons from the file People.csv and add them to a list named people. A line consists of: person type, name, city, index of the departments list, monthly salary / hourly rate / 0.

  6. Sort the list of persons and print them.

  7. Add code to create an output file PeoplePerDepartment.txt that looks like this (grouped by department):

     1
     2
     3
     4
     5
     6
     7
     8
     9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    Department: Operations
    -- Ambi lives in Amsterdam and works at department Operations at Hilversum and is a volunteer
    -- Anne lives in Zwolle and works at department Operations at Hilversum and is a freelancer with an hourly rate of 40.0
    -- Jannie lives in Utrecht and works at department Operations at Hilversum and is a freelancer with an hourly rate of 60.0
    -- Ronald lives in Zaandam and works at department Operations at Hilversum and is a freelancer with an hourly rate of 80.0
    
    Department: Support
    -- Caroline lives in Delft and works at department Support at Amsterdam and is an employee without right to a bonus
    -- Naledi lives in Gaborone and works at department Support at Amsterdam and is a volunteer
    
    Department: Management
    -- Angelique lives in Rotterdam and works at department Management at Almere and is an employee with right to a bonus
    -- Ceren lives in Istanboel and works at department Management at Almere and is a volunteer
    -- Mark lives in Den Haag and works at department Management at Almere and is an employee with right to a bonus
    
    Department: Documentation
    -- Haining lives in Shaoxing and works at department Documentation at Gouda and is a volunteer
    -- Klaas lives in Diemen and works at department Documentation at Gouda and is a freelancer with an hourly rate of 50.0