// CSE 143, Winter 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); } // FIRE all TAs with <= 2 quarters of experience System.out.println(lazyBums); int fired = 0; while (lazyBums.peek().getExperience() <= 2) { lazyBums.remove(); // Donald Trump: "YOU'RE FIRED!" fired++; } System.out.println("fired " + fired + " TAs."); System.out.println(lazyBums); // hire an equivalent number of new replacement TAs from "replacements.txt" Scanner in2 = new Scanner(new File("replacements.txt")); while (in2.hasNext() && fired > 0) { String name = in2.next(); int exp = in2.nextInt(); TA ta = new TA(name, exp); lazyBums.add(ta); fired--; } // print all TAs in increasing order of experience System.out.println(); while (!lazyBums.isEmpty()) { TA ta = lazyBums.remove(); System.out.println(ta); } } }