/** * An attempt to solve the shelf-packing problem. * * @author CSC153 2003 * @version 1.0 */ public class ShelfPacking { public static void main(String[] args) { // Set up the array of width/value pairs. WidthValue[] booktypes = { new WidthValue(50,51) , new WidthValue(33,32) , new WidthValue(1,0) }; } // main(String[]) } // class ShelfPacking public static WidthValue bestRatio(WidthValue[] booktypes) { WidthValue guess = booktypes[0]; for (int i = 1; i < booktypes.length; ++i) { // bv/bw > gv/gw iff bv*gw > gv*bw if (booktypes[i].value*guess.width > booktypes[i].width*gues.value) { guess = booktypes[i]; } // if element i is better } // for return guess; } // bestRatio(WidthValue[] class WidthValue { int width; int value; public WidthValue(int width, int value) { this.width = width; this.value = value; } // WidthValue(int,int) } // class WidthValue