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) { } }
public Candy(string item, DollarAmount price) : base(item, price) { }
public VMItem(string item, DollarAmount price) { this.item = item; this.price = price; quantity = 5; }
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); } }
public Chips(string item, DollarAmount price) : base(item, price) { }
public Gum(string item, DollarAmount price) : base(item, price) { }
public Beverages(string item, DollarAmount price) : base(item, price) { }
public DollarAmount Plus(DollarAmount amountToAdd) { int newTotal = this.totalAmountInCents + amountToAdd.totalAmountInCents; return(new DollarAmount(newTotal)); }
public DollarAmount Minus(DollarAmount amountToSubtract) { int difference = this.totalAmountInCents - amountToSubtract.totalAmountInCents; return(new DollarAmount(difference)); }