Programming 2 with Java
Exercise: Company Printing
The program
CompanyPrinting allows the employees of a
Company to be written to a file in different formats (CSV, JSON, XML).
-
Implement a functional interface
EmployeePrinting
with a method that takes an employee and a print writer as arguments.
-
Replace the existing print methods by methods that can write a single employee to a print writer in a specific format.
-
Implement a template method
printEmployees
that opens a file, iterates over the given employees and writes them into the file. The method has the following parameters:
format
- the printing format
header
- the first line to be written
footer
- the last line to be written
delimiter
- the line to be inserted between two employees
employeePrinting
- the function that can print a single employee
-
In the
main
method call the template method with appropriate parameters.
Solution