Advertisement
Guest User

Untitled

a guest
Jun 28th, 2016
60
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.58 KB | None | 0 0
  1.  
  2.  
  3. import java.io.BufferedReader;
  4. import java.io.IOException;
  5. import java.io.InputStreamReader;
  6. import java.util.ArrayList;
  7. import java.util.Collections;
  8. import java.util.Comparator;
  9.  
  10. class Employee {
  11. String title;
  12. String firstName;
  13. String lastName;
  14. String homeAddress;
  15. String department;
  16. String homePhone;
  17. String workPhone;
  18. String campusBox;
  19.  
  20. public Employee(String title, String firstName, String lastName, String homeAddress, String department,
  21. String homePhone, String workPhone, String campusBox) {
  22. super();
  23. this.title = title;
  24. this.firstName = firstName;
  25. this.lastName = lastName;
  26. this.homeAddress = homeAddress;
  27. this.department = department;
  28. this.homePhone = homePhone;
  29. this.workPhone = workPhone;
  30. this.campusBox = campusBox;
  31. }
  32.  
  33. @Override
  34. public String toString() {
  35. StringBuilder s = new StringBuilder();
  36. s.append("----------------------------------------").append("\n");
  37. s.append(String.format("%s %s %s", this.title, this.firstName, this.lastName)).append("\n");
  38. s.append(homeAddress).append("\n");
  39. s.append(String.format("Department: %s", this.department)).append("\n");
  40. s.append(String.format("Home Phone: %s", this.homePhone)).append("\n");
  41. s.append(String.format("Work Phone: %s", this.workPhone)).append("\n");
  42. s.append(String.format("Campus Box: %s", this.campusBox)).append("\n");
  43. return s.toString();
  44. }
  45.  
  46. }
  47.  
  48. class EmployeeComparator implements Comparator<Employee> {
  49.  
  50. @Override
  51. public int compare(Employee o1, Employee o2) {
  52. return o1.lastName.compareTo(o2.lastName);
  53. }
  54.  
  55. }
  56.  
  57. public class Main {
  58.  
  59. public static void main(String[] args) throws NumberFormatException, IOException {
  60. BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
  61. int numberOfDepartments = Integer.parseInt(in.readLine());
  62. ArrayList<Employee> employeeList = new ArrayList<>();
  63. for (int i = 0; i < numberOfDepartments; i++) {
  64. String recored;
  65. String department = in.readLine();
  66. while ((recored = in.readLine()) != null && recored.length() != 0) {
  67. String[] fields = recored.split(",");
  68. String title = fields[0];
  69. String fName = fields[1];
  70. String lName = fields[2];
  71. String sAddress = fields[3];
  72. String hPhone = fields[4];
  73. String wPhone = fields[5];
  74. String cMAilBox = fields[6];
  75. Employee employee = new Employee(title, fName, lName, sAddress, department, hPhone, wPhone, cMAilBox);
  76. employeeList.add(employee);
  77. }
  78. }
  79. Collections.sort(employeeList, new EmployeeComparator());
  80. StringBuilder ans = new StringBuilder();
  81. for (Employee e : employeeList)
  82. ans.append(e.toString());
  83. System.out.print(ans.toString());
  84.  
  85. }
  86.  
  87. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement