IUP Computer Science
COSC 310     Fall 07

Project #5
(Apothecary Weights)
(Due  14 November 2007)

A group of French archeologists has recently found a collection of apothecary weights in the ruins of a small shop dating from about 1780.  Each of the weights is different and weigh some number of whole grams, such as 3 grams, 12 grams, 85 grams, 301 grams, etc.  Collectively, the weights total 1199 grams; the archeologiest believe the weights were used to weigh quantities of herbal tea and other remedies of the time..

Because the weights have such unusual values, there is some controversy among the archeologists  as to whether or not they could be used on a simple balance scale to weigh various quantities of tea.  (On a simple balance scale, the quantity is put on one side and the weights are put on the other side. )  For example, it was found by trial and error that 100 grams of tea could be weighed by using weights of size 3, 38 and 59 grams, which are among the weight sizes.  And it was found that 200 grams of tea could be weighed using weights of size 85, 62, 38, 12 and 3 grams.  The question was whether all possible tea weights from 2 (the lowest single weight) to 1199 (sum of all of the weights) could be weighed with at least one combination of weights.

You are to write a recursive method to test various possible tea weights to determine if they could be weighted using the apothecary weights.  The program should read in the weight values from the file weights.txt  This is a text file with spaces separating values.  The program should then repeatedly prompt for a quantity of tea and determine whether that quantity can be weighted with the weights.  After making the determination, the program should display the combination of weights used to weigh the tea or should display a message indicating that the specified quantity cannot be weighted exactly.

When the program is finished, test it by trying to find combinations that can weigh the following quantities of tea (these are in grams).

70    150    175    262    364    600    789    1000    1100    1150

Capture this output to hand in.  Hand in a printout of your well-documented program, and a printout of thecaptured output.  You must create a folder named p5 under the folder named after you on the P: drive for COSC 310.  Copy into p5 all .java files that you created for this project.
 

For extra credit, modify the program to test all quantities between 2 and 1199 grams and display which quantities cannot be weighted exactly.  You will see a pattern in these quantities.  On the printout listing the quantities that cannot be weighed, explain what causes the pattern.  Note:  don't do the extra credit until after you have done the assignment above.