コード例 #1
0
        public string ConsumeItems()
        {
            string sound = PurchasedItems[0].MakeSound();

            PurchasedItems.RemoveAt(0);

            return(sound);
        }
コード例 #2
0
        public void DispenseItem(string position)
        {
            // User selects valid position
            if (Stock.ContainsKey(position))
            {
                // There is at least one item within the position
                if (Stock[position].Count != 0)
                {
                    // Call Transaction Class --> Make purchase Method

                    // Add item to List of purchased items in the transaction
                    if (transaction.MakePurchase(Stock[position][0].Cost))
                    {
                        PurchasedItems.Add(Stock[position][0]);
                        TotalPurchasedItems.Add(Stock[position][0]);

                        fileIO.LogTransaction(Stock[position][0].Name, position, Stock[position][0].Cost, Balance);
                        Console.WriteLine($"{Stock[position][0].Name} purchased!");

                        // Remove an item from the Dictionary's stock
                        Stock[position].RemoveAt(0);
                    }
                }
                // There is no inventory left
                else
                {
                    // Tell user out of stock
                    Console.WriteLine($"{position} is out of stock.");
                }
            }
            // User entered invalid position
            else
            {
                // Tell user invalid position
                Console.WriteLine($"Please enter a valid position.");
            }
        }
コード例 #3
0
        // sets up a string to log into log.txt
        public void generatePurchaseString(PurchasedItems item)
        {
            string logString = item.QtyToPurchase + "   " + item.Name + "   " + item.Code + "   $" + item.TotalPrice + "   $" + catering.customerMoney;

            file.fileWriterPurchase(logString);
        }
コード例 #4
0
        //main interface
        public void RunInterface()
        {
            //read our caterng menu in
            file.FileReader(catering);

            //while loop condition
            bool done = false;

            //do a loop
            while (!done)
            {
                //Display main menu
                ShowMainMenu();
                //get our menu option
                string menuSelection = Console.ReadLine().ToString();

                //do a switch with menuSelection
                switch (menuSelection)
                {
                case "1":
                    //log out the full list/menu of catering items
                    RetrievePrintList();

                    break;

                case "2":
                    //set up a few conditions
                    bool   transactionComplete = false;
                    string purchasingSelection = "";

                    //go into loop
                    while (!transactionComplete)
                    {
                        //display purchasing menu
                        ShowPurchasingMenu();
                        //take in user choice input
                        purchasingSelection = Console.ReadLine().ToString();

                        switch (purchasingSelection)
                        {
                        //Add that moola(money)
                        case "1":
                            //prompt user for money to add
                            Console.WriteLine("How much money would you like to add?");
                            //set up variable for money
                            decimal wantToAdd = decimal.Parse(Console.ReadLine());
                            //add the money throught the AddMoney method
                            bool isMoneyValid = catering.AddMoney(wantToAdd);
                            if (isMoneyValid)
                            {
                                // add a log to log.txt with the money and balance
                                generateAddMoneyString(wantToAdd);
                            }
                            else
                            {
                                Console.WriteLine("Account Balance cannot exceed $5000");
                            }



                            break;

                        //select items for purchase
                        case "2":
                            //prompt for code
                            Console.WriteLine("Enter the code of the item you would like to purchase");
                            //take in code
                            string itemCode = Console.ReadLine();
                            //is the code valid?
                            bool validCode = catering.isCodeValid(itemCode);
                            //if invalid, let user know and return to menu
                            if (validCode == false)
                            {
                                Console.WriteLine("Invalid Code, returning to Menu.");
                                break;
                            }

                            //check if the item is sold out
                            bool IsItemSoldOut = catering.IsSoldOut(itemCode);
                            //check if the item is sold out
                            if (IsItemSoldOut)
                            {
                                Console.WriteLine("This item is Sold Out. Returning to Menu.");
                                break;
                            }

                            //prompt for quantity to purchase
                            Console.WriteLine("Please enter the quantity you would like to purchase");
                            //store quantity in qtyToPurchase
                            int qtyToPurchase = int.Parse(Console.ReadLine());
                            //check if there is enough stock
                            bool isInventoryEnough = catering.isQuantityEnough(itemCode, qtyToPurchase);
                            //check if there is enough money
                            bool AreWeAbleToPurchase = catering.EnoughMoney(qtyToPurchase, itemCode);

                            //check if there is enough stock
                            if (isInventoryEnough == false)
                            {
                                Console.WriteLine("Not enough stock, please reduce quantity. Returning to Menu.");
                                break;
                            }
                            //check if there is enough money
                            if (AreWeAbleToPurchase == false)
                            {
                                Console.WriteLine("Not enough Money, please reduce quantity. Returning to Menu.");
                                break;
                            }

                            // if all conditions are good, then the next line grabs the item object
                            CateringItem itemPurchased = catering.purchaseItems(itemCode, qtyToPurchase);
                            //now we make a new object to represent the purchased item
                            PurchasedItems pItems = new PurchasedItems(qtyToPurchase, itemPurchased.Price, itemPurchased.Name, itemCode, itemPurchased.Type);
                            //generate string for log.txt
                            generatePurchaseString(pItems);
                            //add our items to our purchase list
                            purchaseList.addToList(pItems);

                            break;

                        //finish transaction, exit loop and return to main menu
                        case "3":
                            //loop through all items in purchaseList and add totalprice up, then log out to customer
                            getCompleteTransaction();
                            //give customer their change
                            Console.WriteLine(catering.ReturnChange());
                            //log out to log.txt
                            generateGiveChangeString();
                            //transactionComplete == true exits the loop and returns to the main menu
                            transactionComplete = true;
                            break;

                        default:
                            break;
                        }
                    }
                    break;

                //exit the loop
                case "3":
                    Console.WriteLine("Thank You For Using Our Service. Goodbye.");
                    done = !done;

                    break;


                default:

                    Console.WriteLine("hi");
                    break;
                }
            }
        }