Advertisement
April_The_Sergal

fixed

Mar 21st, 2019
94
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 2.13 KB | None | 0 0
  1. public class HWK5_Taylen_Schmaltz {
  2.  
  3.     /**
  4.      * @throws java.io.IOException
  5.      */
  6.     public static int empIndex = 0;
  7.     private static final String FILE_PATH = "C:\\Users\\Admin\\IdeaProjects\\hw\\src\\acmeEgr.txt";
  8.     public static void main(String[] args) throws FileNotFoundException {
  9.         Employee[] employees = new Employee[50];
  10.  
  11.         Scanner scanner = new Scanner(new File(FILE_PATH));
  12.         while (scanner.hasNext()) {
  13.             String firstName = scanner.nextLine();
  14.             String lastName = scanner.nextLine();
  15.             int departmentId = Integer.parseInt(scanner.nextLine());
  16.             employees[empIndex++] = new Employee(firstName, lastName, departmentId);
  17.         }
  18.         printAll(employees);
  19.         printDepartment("IT", employees);
  20.         printLocation("Rochester Hills", employees);
  21.     }
  22.  
  23.     public static void printAll(Employee[] ppl) {
  24.         for (int i = 0; i < empIndex; i++) {
  25.             System.out.println("Name:           " + ppl[i].getName());
  26.             System.out.println("Department:     " + ppl[i].getDept());
  27.             System.out.println("location:       " + ppl[i].getLocation());
  28.         }
  29.         System.out.println("-----------------------");
  30.     }
  31.  
  32.     public static void printDepartment(String title, Employee[] ppl) {
  33.         System.out.println("Department: " + title);
  34.         for (int i = 0; i < empIndex; i++) {
  35.             if(ppl[i].getDept().equals(title)) {
  36.                 System.out.println("Name:           " + ppl[i].getName());
  37.                 System.out.println("location:       " + ppl[i].getLocation());
  38.             }
  39.         }
  40.         System.out.println("-----------------------");
  41.     }
  42.  
  43.     public static void printLocation(String loc, Employee[] ppl) {
  44.         System.out.println("Location: " + loc);
  45.         for (int i = 0; i < empIndex; i++) {
  46.             if(ppl[i].getLocation().equals(loc)) {
  47.                 System.out.println("Name:           " + ppl[i].getName());
  48.                 System.out.println("location:       " + ppl[i].getDept());
  49.             }
  50.         }
  51.         System.out.println("-----------------------");
  52.     }
  53. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement