





Here is the logic for packing a type 1 item into the current bin (with residual capacity resCap) that we are using:



import java.util.*; public class BinPacking { /*  solveBP(k1, s1, k2, s2, k3, s3, resCap, Cap): returns the min # bins needed to pack: k1 items of size s1 k2 items of size s2 k3 items of size s3 using bins of capacity Cap when the current bin has a residual capacity of "resCap"  */ public static int solveBP(int k1, int s1, int k2, int s2, int k3, int s3, int resCap, int Cap) { // Write you (recursive) solution here } public static void main(String[] args) { int n1, n2, n3; int s1, s2, s3; int Cap; int out; Scanner in = new Scanner(System.in); System.out.print("Size of item 1 = "); s1 = in.nextInt(); System.out.print("Number of item 1 = "); n1 = in.nextInt(); System.out.print("Size of item 2 = "); s2 = in.nextInt(); System.out.print("Number of item 2 = "); n2 = in.nextInt(); System.out.print("Size of item 3 = "); s3 = in.nextInt(); System.out.print("Number of item 3 = "); n3 = in.nextInt(); System.out.println(); System.out.print("Capacity of the bin = "); Cap = in.nextInt(); if ( s1 > Cap  s2 > Cap  s3 > Cap ) { System.out.println("Input error: some item's size is too large for bin"); System.exit(1); } out = solveBP(n1, s1, n2, s2, n3, s3, Cap, Cap); System.out.println("Min # bins needed = " + out); } } 
It reads n_{1}, s_{1}, n_{2}, s_{2}, n_{3}, s_{3}, and C, invoke the method solveBP(n1, s1, n2, s2, n3, s3, Cap, Cap) to find the solution.
You need to write the solveBP() method


Cut and paste the entire line into a console window to run it.

/home/cs323000/turnin BinPacking.java hw6 