Ejemplo n.º 1
0
        public void SalesReport()
        {
            string logDirectory = Environment.CurrentDirectory;
            string fileName     = "SalesReport.txt";
            string filePath     = logDirectory + fileName;

            try
            {
                DollarAmount totalSales = new DollarAmount(0);
                using (StreamWriter sw = new StreamWriter(filePath, true))
                {
                    sw.WriteLine($"SALES REPORT: {DateTime.Now}");
                    sw.WriteLine();

                    foreach (KeyValuePair <string, VMItem> kvp in VMContents)
                    {
                        int          itemsSold       = 5 - kvp.Value.Quantity;
                        DollarAmount itemSalesAmount = new DollarAmount(itemsSold * kvp.Value.Price.TotalAmountInCents);
                        totalSales = totalSales.Plus(itemSalesAmount);
                        sw.WriteLine($"{kvp.Value.Item}|{itemsSold}");
                    }

                    sw.WriteLine();
                    sw.WriteLine($"**TOTAL SALES** {totalSales}");
                    sw.WriteLine();
                }
            }

            catch (Exception)
            {
            }
        }
Ejemplo n.º 2
0
 public Candy(string item, DollarAmount price) : base(item, price)
 {
 }
Ejemplo n.º 3
0
 public VMItem(string item, DollarAmount price)
 {
     this.item  = item;
     this.price = price;
     quantity   = 5;
 }
Ejemplo n.º 4
0
        public VendingMachine()
        {
            string filePath = "vendingmachine.csv";

            try
            {
                using (StreamReader sr = new StreamReader(filePath))
                {
                    while (!sr.EndOfStream)
                    {
                        string itemInfo = sr.ReadLine();

                        if (itemInfo[0] == 'A')
                        {
                            string[]     chipsInfo   = itemInfo.Split('|');
                            double       doublePrice = double.Parse(chipsInfo[2]);
                            int          intPrice    = (int)(doublePrice * 100);
                            DollarAmount price       = new DollarAmount(intPrice);
                            vmContents.Add(chipsInfo[0], new Chips(chipsInfo[1], price));
                            //string[0]== slot which is key of dictionary
                            //string[1]== item to be passed into object
                            //string[2]== price to be passed into object
                        }

                        else if (itemInfo[0] == 'B')
                        {
                            string[]     candyInfo   = itemInfo.Split('|');
                            double       doublePrice = double.Parse(candyInfo[2]);
                            int          intPrice    = (int)(doublePrice * 100);
                            DollarAmount price       = new DollarAmount(intPrice);
                            vmContents.Add(candyInfo[0], new Candy(candyInfo[1], price));
                            //string[0]== slot which is key of dictionary
                            //string[1]== item to be passed into object
                            //string[2]== price to be passed into object
                        }

                        if (itemInfo[0] == 'C')
                        {
                            string[]     beveragesInfo = itemInfo.Split('|');
                            double       doublePrice   = double.Parse(beveragesInfo[2]);
                            int          intPrice      = (int)(doublePrice * 100);
                            DollarAmount price         = new DollarAmount(intPrice);
                            vmContents.Add(beveragesInfo[0], new Beverages(beveragesInfo[1], price));
                            //string[0]== slot which is key of dictionary
                            //string[1]== item to be passed into object
                            //string[2]== price to be passed into object
                        }

                        if (itemInfo[0] == 'D')
                        {
                            string[]     gumInfo     = itemInfo.Split('|');
                            double       doublePrice = double.Parse(gumInfo[2]);
                            int          intPrice    = (int)(doublePrice * 100);
                            DollarAmount price       = new DollarAmount(intPrice);
                            vmContents.Add(gumInfo[0], new Gum(gumInfo[1], price));
                            //string[0]== slot which is key of dictionary
                            //string[1]== item to be passed into object
                            //string[2]== price to be passed into object
                        }
                    }
                }
            }

            catch (Exception)
            {
                Console.WriteLine("Vendingmachine.csv. Please exit the console and copy file from Capstone.etc to Captone.bin.Debug and CapstoneTests.bin.Debug folders.");
                Environment.Exit(0);
            }
        }
Ejemplo n.º 5
0
 public Chips(string item, DollarAmount price) : base(item, price)
 {
 }
Ejemplo n.º 6
0
 public Gum(string item, DollarAmount price) : base(item, price)
 {
 }
Ejemplo n.º 7
0
 public Beverages(string item, DollarAmount price) : base(item, price)
 {
 }
Ejemplo n.º 8
0
        public DollarAmount Plus(DollarAmount amountToAdd)
        {
            int newTotal = this.totalAmountInCents + amountToAdd.totalAmountInCents;

            return(new DollarAmount(newTotal));
        }
Ejemplo n.º 9
0
        public DollarAmount Minus(DollarAmount amountToSubtract)
        {
            int difference = this.totalAmountInCents - amountToSubtract.totalAmountInCents;

            return(new DollarAmount(difference));
        }