// CSE 143, Autumn 2013 // 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); } System.out.println(lazyBums); // FIRE all TAs with <= 2 quarters of experience int fired = 0; while(lazyBums.peek().getExperience() <= 2) { lazyBums.remove(); fired++; } System.out.println("fired: " + fired); 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--; } System.out.println(lazyBums); System.out.println(); // print all TAs in increasing order of experience while(!lazyBums.isEmpty()) { System.out.println(lazyBums.remove()); } } }