Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.io.BufferedReader;
- import java.io.IOException;
- import java.io.InputStreamReader;
- import java.util.ArrayList;
- import java.util.Collections;
- import java.util.Comparator;
- class Employee {
- String title;
- String firstName;
- String lastName;
- String homeAddress;
- String department;
- String homePhone;
- String workPhone;
- String campusBox;
- public Employee(String title, String firstName, String lastName, String homeAddress, String department,
- String homePhone, String workPhone, String campusBox) {
- super();
- this.title = title;
- this.firstName = firstName;
- this.lastName = lastName;
- this.homeAddress = homeAddress;
- this.department = department;
- this.homePhone = homePhone;
- this.workPhone = workPhone;
- this.campusBox = campusBox;
- }
- @Override
- public String toString() {
- StringBuilder s = new StringBuilder();
- s.append("----------------------------------------").append("\n");
- s.append(String.format("%s %s %s", this.title, this.firstName, this.lastName)).append("\n");
- s.append(homeAddress).append("\n");
- s.append(String.format("Department: %s", this.department)).append("\n");
- s.append(String.format("Home Phone: %s", this.homePhone)).append("\n");
- s.append(String.format("Work Phone: %s", this.workPhone)).append("\n");
- s.append(String.format("Campus Box: %s", this.campusBox)).append("\n");
- return s.toString();
- }
- }
- class EmployeeComparator implements Comparator<Employee> {
- @Override
- public int compare(Employee o1, Employee o2) {
- return o1.lastName.compareTo(o2.lastName);
- }
- }
- public class Main {
- public static void main(String[] args) throws NumberFormatException, IOException {
- BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
- int numberOfDepartments = Integer.parseInt(in.readLine());
- ArrayList<Employee> employeeList = new ArrayList<>();
- for (int i = 0; i < numberOfDepartments; i++) {
- String recored;
- String department = in.readLine();
- while ((recored = in.readLine()) != null && recored.length() != 0) {
- String[] fields = recored.split(",");
- String title = fields[0];
- String fName = fields[1];
- String lName = fields[2];
- String sAddress = fields[3];
- String hPhone = fields[4];
- String wPhone = fields[5];
- String cMAilBox = fields[6];
- Employee employee = new Employee(title, fName, lName, sAddress, department, hPhone, wPhone, cMAilBox);
- employeeList.add(employee);
- }
- }
- Collections.sort(employeeList, new EmployeeComparator());
- StringBuilder ans = new StringBuilder();
- for (Employee e : employeeList)
- ans.append(e.toString());
- System.out.print(ans.toString());
- }
- }
Add Comment
Please, Sign In to add comment