-
Notifications
You must be signed in to change notification settings - Fork 88
Expand file tree
/
Copy pathMain.java
More file actions
31 lines (27 loc) · 1012 Bytes
/
Main.java
File metadata and controls
31 lines (27 loc) · 1012 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
package org.example;
import java.io.IOException;
import java.io.PrintWriter;
import java.nio.file.Files;
import java.nio.file.Path;
import java.util.ArrayList;
import java.util.List;
public class Main {
public static void main(String[] args) {
List<Employee> employees = createEmployees();
Path outputPath = Path.of("employees.txt");
try (PrintWriter writer = new PrintWriter(Files.newBufferedWriter(outputPath))) {
for (Employee employee : employees) {
writer.println(employee.toFileLine());
}
} catch (IOException e) {
System.err.println("Failed to write employees file: " + e.getMessage());
}
}
private static List<Employee> createEmployees() {
List<Employee> employees = new ArrayList<>();
for (int i = 1; i <= 10; i++) {
employees.add(new Employee("Employee " + i, "employee" + i + "@company.com", 20 + i, 30000 + (i * 1000)));
}
return employees;
}
}