Beispiel #1
0
 //passes through contructed VendingMachine from launch of program to private VendingMAchine within class
 public Display(VendingMachine vm)
 {
     this.vm    = vm;
     this.sales = new SalesReport(vm.InventoryList);
 }
Beispiel #2
0
 public SubMenu(VendingMachine vm)
 {
     this.vm = vm;
 }
Beispiel #3
0
        static void Main(string[] args)
        {
            string currentDir  = Environment.CurrentDirectory;
            string filename    = "vendingmachine.csv";
            string filePath    = Path.Combine(currentDir, filename);
            bool   programDone = false;

            try
            {
                VendingMachine.InitializeInventory(filePath);
            }
            catch
            {
                programDone = true;
            }

            Menu.ResetScreen();
            while (!programDone)
            {
                Console.WriteLine("What would you like to do?\n(1) Display Vending Machine Items\n(2) Purchase\n(3) Quit");
                string userInput = Console.ReadLine();
                if (userInput == "1")
                {
                    Menu.ResetScreen();
                    Menu.DisplayProducts();
                }
                else if (userInput == "2")
                {
                    Menu.ResetScreen();
                    while (!programDone)
                    {
                        Console.WriteLine($"{Menu.DisplayMachineBalance()}What would you like to do?\n(1) Feed Money\n(2) Select Product\n(3) Finish Transaction");
                        userInput = Console.ReadLine();
                        if (userInput == "1")
                        {
                            Menu.ResetScreen();
                            while (userInput != "x")
                            {
                                Console.WriteLine($"{Menu.DisplayMachineBalance()}Please insert a bill (We accept $1, $2, $5, $10) or press 'x' to return to the previous menu...");
                                userInput = Console.ReadLine();
                                Menu.ResetScreen();
                                VendingMachine.FeedMoney(userInput);
                            }
                        }
                        else if (userInput == "2")
                        {
                            Menu.ResetScreen();
                            Menu.DisplayProducts();
                            Console.WriteLine($"{Menu.DisplayMachineBalance()}Please enter a number associated with the item you'd like to receive...");
                            userInput = Console.ReadLine();
                            VendingMachine.SelectProduct(userInput);
                        }
                        else if (userInput == "3")
                        {
                            Menu.ResetScreen();
                            VendingMachine.FinishTransaction();
                            programDone = true;
                        }
                        else
                        {
                            Console.WriteLine("\nInvalid input, please try again...\n");
                        }
                    }
                }
                else if (userInput == "3")
                {
                    Menu.ResetScreen();
                    VendingMachine.FinishTransaction();
                    programDone = true;
                }
                else
                {
                    Console.WriteLine("\nInvalid input, please try again...\n");
                }
            }

            //Logs sales history, printing the results to our sales file
            Logger.ReadSalesHistory(filename);
            Logger.UpdateSalesHistory(Customer.Purchases);
            Logger.PrintSalesHistory();

            Console.ReadLine();
        }
        static void Main(string[] args)
        {
            // Will Track Total Profit of Vending Machine for Sales Report
            decimal totalProfit = 0;

            decimal balance = 0;

            VendingMachine vendingMachine = new VendingMachine();

            while (true)
            {
                Console.WriteLine("\n**Welcome to the Vend-O-Matic 4000**\n\nSelect Option Below\n-------------------");
                Console.WriteLine("(1) View Inventory \n(2) Select Product \n(3) Quit\n");
                Console.Write($"> Current Balance: ${balance} \n\n>>:");
                string menu = Console.ReadLine();
                Console.WriteLine("");

                if (menu == "1")
                {
                    vendingMachine.DisplayItems();
                }
                else if (menu == "2")
                {
                    bool valid = false;

                    do
                    {
                        Console.Write(">> Please enter the location of the product you'd like to puchase: ");

                        string input = Console.ReadLine().ToUpper();

                        valid = false;

                        if (vendingMachine.inventory.ContainsKey(input))
                        {
                            Product product = vendingMachine.inventory[input];

                            if (product.Quantity > 0)
                            {
                                Console.Write($"\n> Price of item selected : ${product.Price} \n\n> {product.Quantity} Remaining\n");

                                bool run = true;

                                while (run)
                                {
                                    Console.Write($"\n> Current Balance is ${balance}\n\n>> Please Enter a Whole Dollar Amount(1, 2, 5, 10), (d) to dispence or (s) to start over\n\n>>: ");
                                    string input2 = Console.ReadLine();

                                    if (input2 == "1" || input2 == "2" || input2 == "5" || input2 == "10")
                                    {
                                        int amount = int.Parse(input2);
                                        balance += (decimal)amount;

                                        Console.WriteLine($"> ${input2} inserted.");

                                        using (StreamWriter sw = new StreamWriter("log.txt", true))
                                        {
                                            sw.WriteLine($"{DateTime.Now.ToString("MM/dd/yyyy hh:mm:ss tt")} FEED MONEY: ${amount}     ${balance}");
                                        }
                                    }
                                    else if (input2 == "D" || input2 == "d")
                                    {
                                        if (balance >= product.Price)
                                        {
                                            run = false;
                                            vendingMachine.DispenseProduct(input);
                                            using (StreamWriter sw = new StreamWriter("log.txt", true))
                                            {
                                                sw.WriteLine($"{DateTime.Now.ToString("MM/dd/yyyy hh:mm:ss tt")} {product.Name} {product.Location} ${balance}     ${balance - product.Price}");
                                            };
                                            balance     -= product.Price;
                                            totalProfit += product.Price;
                                        }
                                        else
                                        {
                                            Console.WriteLine("> Insufficient Funds, please add more money.");
                                        }
                                    }
                                    else if (input2 == "S" || input2 == "s")
                                    {
                                        Console.WriteLine("");
                                        break;
                                    }
                                    else
                                    {
                                        Console.WriteLine("> Invalid Entry. Please enter valid input.");
                                    }
                                }
                            }
                            else
                            {
                                Console.WriteLine("\n>>Sorry that item is SOLD OUT<<\n");
                            }
                        }
                        else
                        {
                            Console.WriteLine("\n> Invalid Entry. Please enter valid input.\n");
                            valid = true;
                        }
                    } while (valid);
                }
                else if (menu == "3")
                {
                    Console.WriteLine("> Thank You for using Vend-O-Matic 4000!");
                    Console.WriteLine($"> Your remaining balance is: ${balance}");

                    using (StreamWriter sw = new StreamWriter("log.txt", true))
                    {
                        sw.WriteLine($"{DateTime.Now.ToString("MM/dd/yyyy hh:mm:ss tt")} GIVE CHANGE: ${balance}     $0.00");
                    };
                    int numQuarter = 0;
                    int numDime    = 0;
                    int numNickel  = 0;

                    while (balance > 0)
                    {
                        if (balance >= 0.25M)
                        {
                            numQuarter++;
                            balance -= 0.25M;
                        }
                        else if (balance >= 0.10M)
                        {
                            numDime++;
                            balance -= 0.10M;
                        }
                        else if (balance >= 0.50M)
                        {
                            numNickel++;
                            balance -= 0.05M;
                        }
                    }

                    Console.WriteLine($"> Here is your change: {numQuarter} Quarter(s), {numDime} Dime(s), {numNickel} Nickel(s).\n");
                    Console.WriteLine("\n------------------------------------------------------------------------------\n");
                }
                else if (menu == "4")
                {
                    foreach (KeyValuePair <string, Product> kvp in vendingMachine.inventory)
                    {
                        Console.WriteLine($"{kvp.Value.Name} | {kvp.Value.Sold}");
                    }

                    Console.WriteLine($"\n\n**TOTAL SALES** ${totalProfit}\n");
                }
                else
                {
                    Console.WriteLine("\n> Invalid Entry. Please enter valid input.\n");
                }
            }
        }
Beispiel #5
0
        public void CreateUpdatedSalesReport(VendingMachine vendoMatic600)
        {
            //searching for files with "SalesReport" in the name and creating an array of what it finds
            string        partialFileName      = "SalesReport";
            string        currentDirectory     = Directory.GetCurrentDirectory();
            DirectoryInfo salesReportDirectory = new DirectoryInfo(currentDirectory);

            FileInfo[] salesReportFiles = salesReportDirectory.GetFiles(partialFileName + "*.txt");

            //finds the most recent sales report
            DateTime mostRecentFileDate = new DateTime(1, 1, 1);

            foreach (FileInfo file in salesReportFiles)
            {
                DateTime fileDateTime = File.GetLastWriteTime(file.FullName);
                if (fileDateTime > mostRecentFileDate)
                {
                    mostRecentFileDate = fileDateTime;
                }
            }

            //formatting the timestamps for the file name
            string lastSalesReportFileDate = $"{mostRecentFileDate}";

            lastSalesReportFileDate = lastSalesReportFileDate.Replace("/", "-").Replace(":", ".");
            string timeStamp = $"{DateTime.Now}";

            timeStamp = timeStamp.Replace("/", "-").Replace(":", ".");

            //paths for the reading and writing of the sales reports
            string salesReportFile          = $"SalesReport({lastSalesReportFileDate}).txt";
            string updatedSalesReportFile   = $"SalesReport({timeStamp}).txt";
            string pathToUpdatedSalesReport = Path.Combine(currentDirectory, updatedSalesReportFile);

            try
            {
                using (StreamReader sr = new StreamReader(salesReportFile))
                {
                    using (StreamWriter sw = new StreamWriter(pathToUpdatedSalesReport))
                    {
                        decimal totalSales = 0; // Should be old totalSales???
                        while (!sr.EndOfStream)
                        {
                            string   line        = sr.ReadLine();
                            string[] productLine = line.Split("|"); // Not spliting old totalSales???
                            int      amountSold  = int.Parse(productLine[1]);

                            foreach (string key in vendoMatic600.AllProducts.Keys)
                            {
                                if (productLine[0] == vendoMatic600.AllProducts[key].Name)
                                {
                                    amountSold += vendoMatic600.AllProducts[key].AmountSold;
                                    totalSales += vendoMatic600.AllProducts[key].PurchasePrice * vendoMatic600.AllProducts[key].AmountSold;
                                    sw.WriteLine($"{vendoMatic600.AllProducts[key].Name}|{amountSold}");
                                }
                            }
                        }
                        sw.WriteLine($"\nTOTAL SALES: {totalSales.ToString("C2")}"); // Goal to have oldTotal + newTotal;
                    }
                }
            }
            catch (Exception e)
            {
                Console.WriteLine("An unexpected error occurred, verify the updated sales report");
                Console.WriteLine(e.Message);
            }
        }