Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*
- * To change this license header, choose License Headers in Project Properties.
- * To change this template file, choose Tools | Templates
- * and open the template in the editor.
- */
- package hwk5_stephanie_moyer;
- /**
- *
- * @author Witch
- */
- import java.io.File;
- import java.io.FileNotFoundException;
- import java.util.*;
- public class Hwk5_Stephanie_Moyer
- {
- public static int empIndex = 0;
- public static void main(String[] args) throws FileNotFoundException
- {
- Scanner lines = new Scanner(new File("acmeEgr.txt"));
- Employee[] array = new Employee[50];
- while (empIndex < 50)
- {
- empIndex++;
- String first;
- String last;
- int dpt;
- first = lines.nextLine();
- last = lines.nextLine();
- dpt = Integer.parseInt(lines.nextLine());
- Employee emp = new Employee(first, last, dpt);
- array[empIndex] = emp;
- //if there is no next line, it exits the loop
- if(!lines.hasNext())
- {
- break;
- }
- }
- printAll(array);
- printDepartment("Engineering", array);
- printLocation("Auburn Hills", array);
- }
- public static void printAll(Employee[] ppl)
- {
- for (int i = 1; i < ppl.length; i++)
- {
- //I was getting a NullPointerException Error, so I added this
- //if statement to make the code continue even when it
- //pulled a null value
- // if (ppl[i] == null)
- // {
- // continue;
- // }
- System.out.println(ppl[i].toString());
- }
- }
- public static void printDepartment(String dept, Employee[] ppl)
- {
- for (int i = 1; i < ppl.length; i++)
- {
- //I was getting a NullPointerException Error, so I added this
- //if statement to make the code continue even when it
- //pulled a null value
- // if (ppl[i] == null)
- // {
- // continue;
- // }
- if (dept.equals(ppl[i].getDept()))
- {
- System.out.println(dept + ": \n"
- + ppl[i].getName() + "\n"
- + ppl[i].getLocation());
- }
- }
- }
- public static void printLocation(String loc, Employee[] ppl)
- {
- for (int i = 1; i < ppl.length; i++)
- {
- //I was getting a NullPointerException Error, so I added this
- //if statement to make the code continue even when it
- //pulled a null value
- // if (ppl[i] == null)
- // {
- // continue;
- // }
- if (loc.equals(ppl[i].getLocation()))
- {
- System.out.println(loc + ": \n"
- + ppl[i].getName() + "\n"
- + ppl[i].getDept());
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement