import javax.swing.JOptionPane;
import java.util.*;
import java.io.*;


public class WorstFit {

  /***********************************************
   *  see:	http://www.cs.princeton.edu/courses/archive/fall06/cos226/assignments/bins.html	
   *		http://www.cs.princeton.edu/courses/archive/fall05/cos226/checklist/bins.html
   ***********************************************/
  private static MaxHeapPriorityQueue maxPQ = new MaxHeapPriorityQueue();
 
  public static void main(String[] args) {

    String textFile = JOptionPane.showInputDialog(
        "Enter the name of the text file to be processed", "input20.txt");
 
    // read the text file and add entries to our table...
    try {
      Scanner file = new Scanner(new File(textFile));
      int count = 0;

      while (file.hasNext()) {
        int fileSize = file.nextInt();
        allocate(fileSize);
      }
    } catch (FileNotFoundException ex) {
      System.out.println("Cannot open the input file: " + textFile);
    }

    int sum = 0;
	Object[] rack = maxPQ.getItems();
    int numDisks = maxPQ.getNumItems();
    for (int i=1; i<numDisks+1; i++)
      sum += ((Disk)rack[i]).getUsedSpace();
   
    System.out.println("file sizes sum\t= "+sum/1000000.0+" GB");
    System.out.println("total disks\t= " + numDisks);

    for (Object d:rack) {
      if (d != null)
      	System.out.println(((Disk)d));
    }
  }

  private static void allocate(int fileSize) {
  // insert your code here...

  }

}
ÿ