public bool Withdraw(IReadOnlyCashTransaction cashTransaction) { bool isValid = true; foreach (var key in _billInventory.Keys) { isValid = isValid && (_billInventory[key] >= cashTransaction.BillCount(key)); if (isValid == false) { break; } } // Only set the inventory if the withdraw can happen. if (isValid == true) { foreach (var bill in UnitedStatesTender.GetAllDefinedTenders()) { if (_billInventory.ContainsKey(bill)) { _billInventory[bill] = _billInventory[bill] - cashTransaction.BillCount(bill); } } } return(isValid); }
public int GetBillCount(UnitedStatesTender tender) { if (_billInventory.ContainsKey(tender)) { return(_billInventory[tender]); } return(0); }
public int BillCount(UnitedStatesTender tender) { if (_details.ContainsKey(tender)) { return(_details[tender]); } return(0); }
public void ResetInventory(IReadOnlyCashTransaction restock) { foreach (var key in UnitedStatesTender.GetAllDefinedTenders()) { if (_billInventory.ContainsKey(key)) { _billInventory[key] = restock.BillCount(key); } } }
public AtmInventory() { _billInventory = new Dictionary <UnitedStatesTender, int>(); var allTenders = UnitedStatesTender.GetAllDefinedTenders(); foreach (var tender in allTenders) { _billInventory.Add(tender, 0); } }
public CashTransaction Add(UnitedStatesTender tender, int numberOfBills) { if (_details.ContainsKey(tender)) { _details[tender] += numberOfBills; } else { _details.Add(new KeyValuePair <UnitedStatesTender, int>(tender, numberOfBills)); } return(this); }
public static bool TryParse(string amount, out UnitedStatesTender bill) { var cleanAmount = amount; if (cleanAmount.StartsWith('$')) { cleanAmount = cleanAmount.Substring(1); } if (int.TryParse(cleanAmount, out int tenderValue)) { var allTenders = GetAllDefinedTenders(); foreach (var tender in allTenders) { if (tender.Value == tenderValue) { bill = tender; return(true); } } } bill = null; return(false); }