/** * A mug with a maximum capacity, a current amount of liquid, and a kind of * liquid. */ public class SimpleMug { // Instance Data Members (instance fields) private final int MAX_CAPACITY; // the maximum capacity of the mug private int currAmount; // the current amount of liquid in the mug private String liquidKind; // the kind of liquid in the mug // Class (static) data members private static int mugCounter = 0; // # of mugs created // Class constants public static final int SMALL_SIZE = 8; public static final int MEDIUM_SIZE = 12; public static final int LARGE_SIZE = 16; // Constructors /** * Constructs a mug with the given maximum capacity to be filled with a * given kind of liquid. The mug starts out empty. * @param mugCapacity the maximum capacity of the mug * @param kindLiquid the kind of liquid the mug will hold */ public SimpleMug(int maxCapacity, String liquidKind) { this.MAX_CAPACITY = maxCapacity; this.currAmount = 0; this.liquidKind = liquidKind; SimpleMug.mugCounter++; } // Methods /** * Returns the maximum capacity of the mug. * @return the maximum capacity of the mug */ public int getMaxCapacity() { return MAX_CAPACITY; } /** * Returns the current amount of liquid in the mug. * @return the current amount of liquid in the mug */ public int getCurrentAmount() { return currAmount; } /** * Returns the kind of liquid in the mug. * @return the kind of liquid in the mug */ public String getLiquidKind() { return liquidKind; } /** * Changes the kind of liquid to be the new one given. * @param newKind the new kind of liquid */ public void changeLiquidKind(String newKind) { liquidKind = newKind; } /** * Fills the mug with the given amount of liquid. * @param amount the amount of liquid to add to the mug */ public void fill(int amount) { int newAmount = currAmount + amount; currAmount = newAmount; } /** * Pours the given amount of liquid out of the mug. * @param amount the amount of liquid to remove from the mug. */ public void pour(int amount) { int newAmount = currAmount - amount; currAmount = newAmount; } /** * Class (static) method to return the number of mugs created (i.e., * the number of times the SimpleMug constructor has been called). * @return number of mugs created */ public static int getMugCounter() { return mugCounter; } }