Programming Assignment: Box Packing

This is a modification of exercise 21.25 in your textbook. The class containing your main should be named "PackBoxes".

Input:

Your program should read its input from the file "weights.txt". The contents of that file will consist of a series of floating point numbers, separated by space, \r or \n characters. Here is a sample weights.txt. Because you don't know how many numbers will be in the input file, you should read the data into an ArrayList, rather than an array.

Output:

The program should provide output for each of the two packing strategies (parts A and B of problem 21.25).  (If you're doing the extra credit, your program will generate output for that, as well.) The output should be of the format shown in packing_out.txt:

Inventory:
Item1: 0.1
Item2: 0.6
Item3: 0.11
....
Item10: 0.111
=========
Packing via most-filled strategy:
Box 1: Item1(0.1), Item3(0.11), Item5(0.55) : Weight = .76
Box 2: ....
...
In total, 4 boxes were needed. On average, the boxes were 71.2% full.
=========
Packing via heaviest-item first strategy:
Box 1: Item4(0.765), Item1(0.1), Item3(0.11): Weight = 0.975
...
In total, 5 boxes were needed. On average, the boxes were 66.9% full.

Note that the ouptut in this sample file is not necessarily correct. It should only be viewed as an example of the format of your output.

Commentary:

What classes will you want for this problem?  In code design one technique that can be used to answer this question is to consider the problem statement and list its verbs and nouns.  The nouns are potential classes, and the verbs are potential methods within the classes.  These won't necessarily be exhaustive, but it's a good start.

Strategy A should scan through the list of items, L. As you process each item,i, place it in the fullest box, b, that can hold i. (Use a priority queue of boxes to identify b.) If there is no such box, allocate a new box and place i there.

Strategy B is similar to A, but you'll remove items from L (placing them in boxes) in order from largest to smallest. You should use a priority queue to store L.

The first box any item placed in should be labelled "Box 1", the next box needed to place a new item should be labelled "Box 2", and so on.

To Hand in:

  1. A zip file of your source code, and a text file containing a transcript of your program running on the sample input file. At the top of the text file clearly indicate whether you have implemented the extra credit.