Ejemplo n.º 1
0
    public VendingMachineStoredContents unload()
    {
        VendingMachineStoredContents contents = new VendingMachineStoredContents();

        // coin rack coins
        CoinRack[] racks = vendingHardware.CoinRacks;
        foreach (CoinRack rack in racks)
        {
            List <Coin> emptiedCoins = rack.Unload();
            contents.CoinsInCoinRacks.Add(emptiedCoins);
        }
        // storage coins
        CoinReceptacle recep      = vendingHardware.StorageBin;
        List <Coin>    recepCoins = recep.Unload();

        foreach (Coin coin in recepCoins)
        {
            contents.PaymentCoinsInStorageBin.Add(coin);
        }
        // pops
        PopCanRack[] popRacks = vendingHardware.PopCanRacks;
        foreach (PopCanRack rack in popRacks)
        {
            List <PopCan> emptiedPops = rack.Unload();
            contents.PopCansInPopCanRacks.Add(emptiedPops);
        }
        return(contents);
    }
Ejemplo n.º 2
0
    public void pressButton(int button)
    {
        SelectionButton[] buttons      = vendingHardware.SelectionButtons;
        SelectionButton   chosenButton = null;

        try
        {
            chosenButton = buttons[button];
        } catch (Exception e)
        {
            Console.WriteLine("Invalid button chosen");
        }
        // press button
        chosenButton.Press();

        // now button is pressed, process action

        // get price and name of chosen pop
        SoftwarePop pop   = pops[button];
        int         price = pop.getCost();
        string      name  = pop.getName();

        Console.WriteLine("Requested: " + name + ":" + price);
        PopCanRack[] racks = vendingHardware.PopCanRacks;

        // check if enough money inserted
        if (insertedAmount >= price && racks[button].Count > 0)
        {
            // dispense pop
            racks[button].DispensePopCan();
            // take money into machine from receptacle
            CoinReceptacle recep = vendingHardware.CoinReceptacle;
            recep.StoreCoins();
            // calculate and dispense change
            int change          = insertedAmount - price;
            int remainingCredit = dispenseChange(change);
            // reset inserted amount taking into
            // account any credit
            insertedAmount = remainingCredit;
            Console.WriteLine("Remaining credit: " + remainingCredit);
        }
        else
        {
            if (racks[button].Count > 0)
            {
                Console.WriteLine("Not enough money entered");
            }
            else
            {
                Console.WriteLine("Not enough pop");
            }
        }
    }