public ATM() { //creating handlers, setting initial state of ATM bills50s = new CurrencyBill(50, 1); bills100s = new CurrencyBill(100, 2); bills200s = new CurrencyBill(200, 3); bills500s = new CurrencyBill(500, 2); bills1000s = new CurrencyBill(1000, 4); bills2000s = new CurrencyBill(2000, 1); bills5000s = new CurrencyBill(5000, 1); bills50s .RegisterNext(bills100s) .RegisterNext(bills200s) .RegisterNext(bills500s) .RegisterNext(bills1000s) .RegisterNext(bills2000s) .RegisterNext(bills5000s); mode = "authorization"; maxNotesAmount = 15; currNotesAmount = 0; }
public int ExecuteWithdraw(bool isSmallMode, bool isLargeMode, int amount) { var currCashState = getCurrCashInATM(); Dictionary <int, int> source = new Dictionary <int, int>(currCashState); CurrencyBill firstHandler = null; if (isSmallMode) { //set proper handlers pipeline bills50s .RegisterNext(bills100s) .RegisterNext(bills200s) .RegisterNext(bills500s) .RegisterNext(bills1000s) .RegisterNext(bills2000s) .RegisterNext(bills5000s); firstHandler = bills50s; } else if (isLargeMode) { //set proper handlers pipeline bills5000s .RegisterNext(bills2000s) .RegisterNext(bills1000s) .RegisterNext(bills500s) .RegisterNext(bills200s) .RegisterNext(bills100s) .RegisterNext(bills50s); firstHandler = bills5000s; } int sum_dispense = 0; doWithdraw(amount, firstHandler, ref sum_dispense); return(sum_dispense); }