Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /**
- * Use assertions and exceptions to create a candy machine
- *
- * @author Niki Jona
- * @version 4/3/16
- */
- public class CandyMachine
- {
- public static void main (String[] args)
- {
- Dispenser dispenser = new Dispenser(100, 50);
- CashRegister cashRegister = new CashRegister();
- System.out.println("Dispenser: " + dispenser.getCount() + " items, " + " each costing " + dispenser.getProductionCost() + " cents");
- System.out.println("Cash Register: " + cashRegister.getCashOnHand() + " cents");
- System.out.println();
- sellProduct(dispenser, cashRegister, 10);
- System.out.println();
- System.out.println("Dispenser: " + dispenser.getCount() + " items, " + " each costing " + dispenser.getProductionCost() + " cents");
- System.out.println("Cash Register: " + cashRegister.getCashOnHand() + " cents");
- }
- public static void sellProduct(Dispenser dispenser, CashRegister cashRegister, int amount)
- {
- System.out.println("Made sale: " + amount + " items");
- for(int i = 0; i < amount; i++)
- {
- dispenser.makeSale();
- }
- cashRegister.acceptAmount(amount * dispenser.getProductionCost());
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment