// /// <summary> /// Default Constructor for the machine. The constructor loads the files and populates the inventory. It also resets the sales log /// </summary> public VirtualVendingMachine() { // load it up! string directory = Environment.CurrentDirectory; string fullPath = Path.Combine(directory, "vendingmachine.csv"); inventory = FileFunctions.LoadMachine(fullPath); FileFunctions.ResetLog(); }
/// <summary> /// Method to return change from the vending machine /// </summary> /// <returns>A changedrawer object containing the change breakdown</returns> public ChangeDrawer ReturnChange() { // Log the transaction. Do it here since the CurrentBalance will change after MakeChange is called FileFunctions.LogTransaction("GIVE CHANGE", CurrentBalance, 0M); ChangeDrawer changeDrawer = new ChangeDrawer(); changeDrawer.MakeChange(CurrentBalance); return(changeDrawer); }
/// <summary> /// Public method to add money to the vending machine's balance /// </summary> /// <param name="dollars">Amount of dollars to add.</param> /// <returns>The machine balance after the money is added</returns> public decimal FeedMoney(int dollars) { try { _currentBalance += dollars; } catch (Exception e) { throw e; } // Log it FileFunctions.LogTransaction("FEED MONEY", (decimal)dollars, CurrentBalance); return(CurrentBalance); }
/// <summary> /// Public method to add money to the vending machine's balance /// </summary> /// <param name="dollars">Amount of dollars to add.</param> /// <returns>The machine balance after the money is added</returns> public decimal FeedMoney(int dollars) { // check for negative values. Need to check here in case this class is used elsewhere if (dollars < 0) { throw new InvalidDollarAmount(); } try { _currentBalance += dollars; } catch (Exception e) { throw e; } // Log it FileFunctions.LogTransaction("FEED MONEY", (decimal)dollars, CurrentBalance); return(CurrentBalance); }
/// <summary> /// Overloaded constructor to take in a file path incase we need a different file /// </summary> /// <param name="fullPath">Full path to inventory file</param> public VirtualVendingMachine(string fullPath) { inventory = FileFunctions.LoadMachine(fullPath); FileFunctions.ResetLog(); }