Question
In java, how to add a customer and a card reader class into this progrm import java.util.ArrayList; import java.util.Collections; import java.util.HashMap; import java.util.List; import java.util.Map;
In java, how to add a customer and a card reader class into this progrm
import java.util.ArrayList; import java.util.Collections; import java.util.HashMap; import java.util.List; import java.util.Map;
public class VendingMachineImpl implements VendingMachine { private Inventory
@Override public void insertCoin(Coin coin) { currentBalance = currentBalance + coin.getDenomination(); cashInventory.add(coin); }
@Override public Bucket
private List
private void updateCashInventory(List
class VendingMachineFactory { public static VendingMachine createVendingMachine() { return new VendingMachineImpl(); } }
enum Item { COKE("Coke", 25), PEPSI("Pepsi", 35), SODA("Soda", 45); private String name; private int price;
private Item(String name, int price) { this.name = name; this.price = price; }
public String getName() { return name; }
public long getPrice() { return price; } }
enum Coin { PENNY(1), NICKLE(5), DIME(10), QUARTER(25);
class Inventory
public int getQuantity(T item) { Integer value = inventory.get(item); return value == null ? 0 : value; }
public void add(T item) { int count = inventory.get(item); inventory.put(item, count + 1); }
public void deduct(T item) { if (hasItem(item)) { int count = inventory.get(item); inventory.put(item, count - 1); } }
public boolean hasItem(T item) { return getQuantity(item) > 0; }
public void clear() { inventory.clear(); }
public void put(T item, int quantity) { inventory.put(item, quantity); } }
package com.chegg.vending.test;
public class NotFullPaidException extends RuntimeException { private String message; private long remaining;
public NotFullPaidException(String message, long remaining) { this.message = message; this.remaining = remaining; }
public long getRemaining() { return remaining; }
@Override public String getMessage() { return message + remaining; } }
class NotSufficientChangeException extends RuntimeException { private String message;
public NotSufficientChangeException(String string) { this.message = string; }
@Override public String getMessage() { return message; } }
class SoldOutException extends RuntimeException { private String message;
public SoldOutException(String string) { this.message = string; }
@Override public String getMessage() { return message; } }
private int denomination;
private Coin(int denomination) { this.denomination = denomination; }
public int getDenomination() { return denomination; } }
public interface VendingMachine { public long selectItemAndGetPrice(Item item); public void insertCoin(Coin coin); public List
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started