Exam 2 Sample Questions from Spring 2012 Part III: Coding an Instantiable Class public class ShippingContainer { private static long qty; // number of containers created private final long ID; private double emptyWeight; private double loadWeight; private double maxLoadWeight; public ShippingContainer( double maxLoad, double emptyWeight ) { this.maxLoadWeight = maxLoad; this.emptyWeight = emptyWeight; ID = qty; qty++; loadWeight = 0; } public static long getQuantity() { return qty; } public long getID() { return ID; } public double getWeight() { return emptyWeight + loadWeight; } public boolean load( double w ) { if ( loadWeight + w <= maxLoadWeight ) { loadWeight += w; return true; } return false; } public boolean isEmpty() { return loadWeight <= 0; } public boolean isFull() { return loadWeight >= maxLoadWeight; } public boolean unload( double w ) { if ( loadWeight - w >= 0 ) { loadWeight -= w; return true; } return false; } private static String gradeEgg( int w, char c ) { String grade = "Commerical"; // default if no match if ( c == 'w' ) { if ( w >= 30 ) grade = "Jumbo"; else if ( w >= 27 ) grade = "Extra Large"; else if ( w >= 24 ) grade = "Large"; } return grade; } }