// <------- 80 ------> // /******************************************************************************* *******************************************************************************/ /** * The Beverage class is used to represent a soft-drink beverage. It was * designed to show as much variance in class and instance membership as * CS302 students are ready for by the first exam. It does not have any final * methods, since that is generally covered in later Inheritance chapters. I * have tried to make this class definition both simple and sensical - a most * difficult task while attempting to include members of every kind. * * If this code make you thirsty, please email the coke heads immediately and * give them your money. */ public class Beverage { /** boolean only have two values, but here I made myself three. These * values are measured in fluid ounces. */ public static final int SMALL = 16; public static final int MEDIUM = 20; public static final int LARGE = 24; /** a similar tactic was used here for 4 different types of beverage. * the mathematician will notice that this representation in prime * numbers allows for unique decomposition of "mixed" drinks. */ public static final int COKE = 2; public static final int SPRITE = 3; public static final int DR_PEPPER = 5; public static final int ROOT_BEER = 7; private static final double pricePerOunce = 0.05; // in $$/oz. public final int orderSize; // original volume private final int drinkType; // coke, sprite, etc. public static int mostPoplarType; // coke, sprite, etc. private static int double dailyDiscout; // in $$/oz. public boolean ice; // whether or not there's ice left private int currentAmount; // in oz. public Beverage(int orderSize, int drinkType, boolean ice, double moneyPaid, Customer thirstyPerson) { this.orderSize = orderSize; refill(); this.drinkType = drinkType; this.ice = ice; if (moneyPaid >= currentCost()) { thirstyPerson.giveDrink(this); thirstyPerson.giveChange(moneyPaid - currentCost()); } } public Beverage(int orderSize, int drinkType, double moneyPaid, Customer thirstyPerson) { this(orderSize,drinkType,false,moneyPaid,thirstyPerson); } public static void setDailyDiscount(double dailyDiscount) { this.dailyDiscount = ; } public static void setDailyDiscountRandom() { dailyDiscount = getRandomDiscount(); } private static double getRandomDailyDiscount() { return .01*Math.random(); } public void drink(int drankAmount) { currentAmount = Math.max(0,currentAmount-drankAmount); } public void refill() { currentAmount = orderSize; } public void addIce() { ice = true; } private double currentCost() { return drinkSize * (pricePerOunce - dailyDiscount); } public String toString() { return "This is a beverage instance."; } }