public VendingMachineSafety(bool safetyOn, CoinSlot coinSlot, DeliveryChute deliveryChute,
                             IndicatorLight exactChangeLight, IndicatorLight outOfOrderLight, PopCanRack[] popCanRacks, CoinRack[] coinRacks)
 {
     this.SafetyOn         = safetyOn;
     this.CoinSlot         = coinSlot;
     this.DeliveryChute    = deliveryChute;
     this.ExactChangeLight = exactChangeLight;
     this.OutOfOrderLight  = outOfOrderLight;
     this.PopCanRacks      = popCanRacks;
     this.CoinRacks        = coinRacks;
 }
예제 #2
0
        /**
         * Creates a standard arrangement for the vending machine. All the
         * components are created and interconnected. The machine is initially
         * empty. The pop kind names and costs are initialized to "<default>"
         * and 1 respectively.
         *
         * All pop kinds
         *
         * @param coinKinds
         *            The values (in cents) of each kind of coin. The order of the
         *            kinds is maintained. One coin rack is produced for each kind.
         *            Each kind must have a unique, positive value.
         * @param selectionButtonCount
         *            The number of selection buttons on the machine. Must be
         *            positive.
         * @param coinRackCapacity
         *            The maximum capacity of each coin rack in the machine. Must be
         *            positive.
         * @param popCanRackCapacity
         *            The maximum capacity of each pop can rack in the machine. Must
         *            be positive.
         * @param receptacleCapacity
         *            The maximum capacity of the coin receptacle, storage bin, and
         *            delivery chute. Must be positive.
         */
        public VendingMachine(int[] coinKinds, int selectionButtonCount, int coinRackCapacity, int popCanRackCapacity, int receptacleCapacity)
        {
            if (coinKinds == null)
            {
                throw new Exception("Arguments may not be null");
            }

            if (selectionButtonCount < 1 || coinRackCapacity < 1 || popCanRackCapacity < 1)
            {
                throw new Exception("Counts and capacities must be positive");
            }

            if (coinKinds.Length < 1)
            {
                throw new Exception("At least one coin kind must be accepted");
            }

            this.coinKinds = coinKinds;

            var coinKindsSet = new HashSet <int>(coinKinds);

            if (coinKindsSet.Count != this.coinKinds.Length)
            {
                throw new Exception("Coin kinds must have unique values");
            }
            if (coinKindsSet.Where(ck => ck < 1).Count() > 0)
            {
                throw new Exception("Coin kind must have a positive value");
            }

            this.Display          = new Display();
            this.CoinSlot         = new CoinSlot(this.coinKinds);
            this.CoinReceptacle   = new CoinReceptacle(receptacleCapacity);
            this.StorageBin       = new CoinReceptacle(receptacleCapacity);
            this.DeliveryChute    = new DeliveryChute(receptacleCapacity);
            this.CoinRacks        = new CoinRack[this.coinKinds.Length];
            this.coinRackChannels = new Dictionary <int, CoinChannel>();
            for (int i = 0; i < this.coinKinds.Length; i++)
            {
                this.CoinRacks[i] = new CoinRack(coinRackCapacity);
                this.CoinRacks[i].Connect(new CoinChannel(this.DeliveryChute));
                this.coinRackChannels[this.coinKinds[i]] = new CoinChannel(CoinRacks[i]);
            }

            this.PopCanRacks = new PopCanRack[selectionButtonCount];
            for (int i = 0; i < selectionButtonCount; i++)
            {
                this.PopCanRacks[i] = new PopCanRack(popCanRackCapacity);
                this.PopCanRacks[i].Connect(new PopCanChannel(DeliveryChute));
            }

            this.PopCanNames = new string[selectionButtonCount];
            for (int i = 0; i < selectionButtonCount; i++)
            {
                this.PopCanNames[i] = "<default>";
            }
            this.PopCanCosts = new int[selectionButtonCount];
            for (int i = 0; i < selectionButtonCount; i++)
            {
                this.PopCanCosts[i] = 1;
            }

            this.SelectionButtons = new SelectionButton[selectionButtonCount];
            for (int i = 0; i < selectionButtonCount; i++)
            {
                this.SelectionButtons[i] = new SelectionButton();
            }

            this.CoinSlot.Connect(new CoinChannel(this.CoinReceptacle), new CoinChannel(this.DeliveryChute));
            this.CoinReceptacle.Connect(this.coinRackChannels, new CoinChannel(this.DeliveryChute), new CoinChannel(this.StorageBin));

            this.ExactChangeLight = new IndicatorLight();
            this.OutOfOrderLight  = new IndicatorLight();

            this.SafetyOn = false;
        }