daily pastebin goal
46%
SHARE
TWEET

Untitled

a guest Mar 24th, 2019 71 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  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_jessica_lafraugh;
  7.  
  8. /**
  9.  *
  10.  * @author jlafr
  11.  */
  12. import java.util.*;
  13. import java.io.File;
  14. import java.io.FileNotFoundException;
  15.  
  16.  
  17.  
  18. public class Hwk5_Jessica_LaFraugh {
  19.  
  20.     //this static variable empIndex is supposed to keep track of how many employees are read from the file
  21.     public static int empIndex = 0;
  22.  
  23.     public static void main(String[] args) throws FileNotFoundException {
  24.         //this is how i am going to do 1b: create an array to hold up to 50 objects of class Employee
  25.         Employee[] emp = new Employee[50];
  26.         //now i get to open the file and use a while loop to read contents until empty
  27.         Scanner ScanFile;
  28.         ScanFile = new Scanner(new File("acmeEgr.txt"));
  29.         while (empIndex < 50) {
  30.             empIndex++; //first begin by incrementing the static variable
  31.             String First, Last;
  32.             int digit;
  33. //reading in the 3 lines each time through the while loop
  34.             First = ScanFile.nextLine();
  35.             Last = ScanFile.nextLine();
  36.             digit = Integer.parseInt(ScanFile.nextLine());
  37. // creating an object of the employee class
  38.             Employee obj = new Employee(Last, First, digit);
  39.             //this is how to store the object into the array
  40.             emp[empIndex] = obj;
  41.             if (!ScanFile.hasNext()) {
  42.                 break;
  43.             }
  44.            
  45. //    
  46.         }//when you fall out the array call the printall method
  47. printAll(emp);
  48. printDepartment("IT", emp);
  49. printDepartment("Rochester Hills", emp);
  50.     }
  51.  
  52.     public static void printAll(Employee[] ppl) { //loop through the results of each array
  53.         for (int i = 1; i < empIndex; i++){
  54.             ppl[i].toString();
  55.         }
  56.     }
  57.  
  58.     public static void printDepartment(String title, Employee[] ppl) { //loop through the array while creating the employee class
  59. for (int i = 1; i < empIndex; i++){
  60.     if (ppl[i].getDept().equals(title)){
  61.         System.out.println(ppl[i].getName() + "\n" + ppl[i].getLocation());
  62.     }
  63. }
  64.     }
  65.  
  66.     public static void printLocation(String loc, Employee ppl[]) { //do the same as above instead of printing the department you print the parameters.
  67. for (int i = 1; i < empIndex; i++){
  68.     if (ppl[i].getLocation().equals(loc)){
  69.         System.out.println(ppl[i].getName() + "\n" + ppl[i].getDept());
  70.     }
  71.     }
  72.  
  73.     }
  74. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top