Advertisement
Guest User

Untitled

a guest
Mar 24th, 2019
84
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.07 KB | None | 0 0
  1. /*
  2. * To change this license header, choose License Headers in Project Properties.
  3. * To change this template file, choose Tools | Templates
  4. * and open the template in the editor.
  5. */
  6. package hwk5_stephanie_moyer;
  7.  
  8. /**
  9. *
  10. * @author Witch
  11. */
  12. import java.io.File;
  13. import java.io.FileNotFoundException;
  14. import java.util.*;
  15.  
  16. public class Hwk5_Stephanie_Moyer
  17. {
  18.  
  19. public static int empIndex = 0;
  20.  
  21. public static void main(String[] args) throws FileNotFoundException
  22. {
  23. Scanner lines = new Scanner(new File("acmeEgr.txt"));
  24. Employee[] array = new Employee[50];
  25. while (empIndex < 50)
  26. {
  27. empIndex++;
  28. String first;
  29. String last;
  30. int dpt;
  31.  
  32. first = lines.nextLine();
  33. last = lines.nextLine();
  34. dpt = Integer.parseInt(lines.nextLine());
  35.  
  36. Employee emp = new Employee(first, last, dpt);
  37. array[empIndex] = emp;
  38.  
  39. //if there is no next line, it exits the loop
  40. if(!lines.hasNext())
  41. {
  42. break;
  43. }
  44. }
  45. printAll(array);
  46. printDepartment("Engineering", array);
  47. printLocation("Auburn Hills", array);
  48.  
  49.  
  50. }
  51.  
  52. public static void printAll(Employee[] ppl)
  53. {
  54. for (int i = 1; i < ppl.length; i++)
  55. {
  56. //I was getting a NullPointerException Error, so I added this
  57. //if statement to make the code continue even when it
  58. //pulled a null value
  59. // if (ppl[i] == null)
  60. // {
  61. // continue;
  62. // }
  63. System.out.println(ppl[i].toString());
  64. }
  65.  
  66.  
  67. }
  68.  
  69. public static void printDepartment(String dept, Employee[] ppl)
  70. {
  71. for (int i = 1; i < ppl.length; i++)
  72. {
  73. //I was getting a NullPointerException Error, so I added this
  74. //if statement to make the code continue even when it
  75. //pulled a null value
  76. // if (ppl[i] == null)
  77. // {
  78. // continue;
  79. // }
  80. if (dept.equals(ppl[i].getDept()))
  81. {
  82. System.out.println(dept + ": \n"
  83. + ppl[i].getName() + "\n"
  84. + ppl[i].getLocation());
  85. }
  86. }
  87. }
  88.  
  89. public static void printLocation(String loc, Employee[] ppl)
  90. {
  91. for (int i = 1; i < ppl.length; i++)
  92. {
  93. //I was getting a NullPointerException Error, so I added this
  94. //if statement to make the code continue even when it
  95. //pulled a null value
  96. // if (ppl[i] == null)
  97. // {
  98. // continue;
  99. // }
  100. if (loc.equals(ppl[i].getLocation()))
  101. {
  102. System.out.println(loc + ": \n"
  103. + ppl[i].getName() + "\n"
  104. + ppl[i].getDept());
  105. }
  106.  
  107. }
  108. }
  109.  
  110. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement