// CSE 143, Summer 2012 // This program hires and fires teaching assistants based on their experience. // It demonstrates the use of the PriorityQueue data structure. import java.io.*; import java.util.*; public class FiringSquad { public static void main(String[] args) throws IOException { Queue lazyBums = new PriorityQueue(); // read all current TAs from a file "tas.txt" Scanner in = new Scanner(new File("tas.txt")); while (in.hasNext()) { String name = in.next(); int exp = in.nextInt(); TA ta = new TA(name, exp); lazyBums.add(ta); } int fired = 0; while (!lazyBums.isEmpty() && lazyBums.peek().getExperience() <=2) { lazyBums.remove(); fired++; } Queue replacements = new PriorityQueue(); Scanner in2 = new Scanner(new File("replacements.txt")); while (in2.hasNext()) { String name = in2.next(); int exp = in2.nextInt(); TA ta = new TA(name, exp); replacements.add(ta); } while (fired > 0) { lazyBums.add(replacements.remove()); fired--; } while(!lazyBums.isEmpty()) { System.out.println(lazyBums.remove()); } //System.out.println(lazyBums); } }