import javax.swing.*; public class ContainerTest { public static void main(String[] args) { Container[] box = new Container[25]; box[0] = new Container(10, 4, "a"); box[1] = new Container(10, 9, "b"); box[2] = new Container(20, 23, "c"); box[3] = new Container(20, 7, "d"); box[4] = new Container(40, 8, "e"); box[5] = new Container(40, 6, "f"); box[6] = new Container(40, 17, "g"); box[7] = new Container(40, 25, "h"); box[8] = new Container(20, 31, "i"); box[9] = new Container(10, 9, "j"); box[10] = new Container(40, 8, "k"); box[11] = new Container(40, 27, "l"); box[12] = new Container(20, 8, "m"); box[13] = new Container(10, 16, "n"); box[14] = new Container(20, 33, "o"); box[15] = new Container(40, 7, "p"); box[16] = new Container(10, 8, "q"); box[17] = new Container(20, 9, "r"); box[18] = new Container(10, 23, "s"); box[19] = new Container(10, 39, "t"); box[20] = new Container(40, 34, "u"); box[21] = new Container(10, 25, "v"); box[22] = new Container(10, 27, "w"); box[23] = new Container(40, 15, "x"); box[24] = new Container(10, 18, "y"); int nextContainer= 0; // Next container to be added final int CRANES= 6; // Numbered 0-5 final int SIZES= 3; // Size 0 is 10 ft, size 1 is 20 ft, size 2 is 40 ft ContainerTerminal term= new ContainerTerminal(CRANES, SIZES); String input, param; int crane, size; boolean quit= false; while (!quit) { input = JOptionPane.showInputDialog("Action: (a)dd, (f)irst, (r)emove, "+ "list by (c)rane, list by (s)ize, (w)eight by size, (q)uit"); if (input.equals("a")) { param= JOptionPane.showInputDialog("Crane:"); crane= Integer.parseInt(param); if (nextContainer < box.length) { term.add(box[nextContainer++], crane); System.out.println("Container "+box[nextContainer-1].id+" added to"+ " crane line "+crane); } else System.out.println("No more containers available to add"); } else if (input.equals("f")) { param= JOptionPane.showInputDialog("Crane:"); crane= Integer.parseInt(param); Container first= term.getFirst(crane); if (first != null) System.out.println("First container for crane "+crane+" : "+first.id); else System.out.println("No containers for crane "+crane); } else if (input.equals("r")) { param= JOptionPane.showInputDialog("ID to remove:"); boolean success= term.remove(param); System.out.println("Container "+param+" removed? "+success); } else if (input.equals("c")) { param= JOptionPane.showInputDialog("Crane:"); crane= Integer.parseInt(param); term.printCraneLine(crane); } else if (input.equals("s")) { param= JOptionPane.showInputDialog("Size:"); size= Integer.parseInt(param); term.printContainerSizeLine(size); } else if (input.equals("w")) { param= JOptionPane.showInputDialog("Size:"); size= Integer.parseInt(param); int nbr= term.getWeightBySize(size); System.out.println("Total weight of containers for size "+size+" : "+nbr); } else if (input.equals("q")) { quit= true; } else System.out.println("Unrecognized choice; please try again."); } System.exit(0); } }