package InterfaceDemo; /** * Scale.java * * * Created: Tue Feb 13 19:44:08 2001 * * @author Stuart C. Shapiro * The class of scales, * objects that can hold weighable objects. */ public class Scale { /** The number of objects held on this scale. */ private int numberHeld = 0; /** The total weight of ojbects held on this scale. */ private double totalWeight = 0.0; /** Constructs a scale. */ public Scale (){ } /** * Adds the object to this scale. * @param object The object being added to this scale. */ public void addObject(Weighable object) { numberHeld = numberHeld + 1; totalWeight = totalWeight + object.getWeight(); } /** * Prints the number of objects on the scale, * and their total weight. */ public void report(){ System.out.println("I'm holding " + numberHeld + " object(s), weighing a total of " + totalWeight + " pounds."); } }// Scale