Пример #1
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");
            }
        }
    }
Пример #2
0
    public void configure(List <string> popNames, List <int> popCosts)
    {
        // reset software list in case of reconfiguring
        pops.Clear();
        int counter = 0;

        foreach (string name in popNames)
        {
            SoftwarePop pop = new SoftwarePop(name, popCosts[counter]);
            pops.Add(pop);
            counter++;
        }
        vendingHardware.Configure(popNames, popCosts);
    }