static MoneyAmount Reserve(MoneyAmount cost) { decimal factor = 1; if (IsHappyHour) { factor = .5M; } Console.WriteLine("Reserving an item that costs {0},", cost); return(cost * factor); }
static void Buy(MoneyAmount wallet, MoneyAmount cost) { bool enoughMoney = wallet.Amount >= cost.Amount; MoneyAmount finalCost = Reserve(cost); bool enoughFinalMoney = wallet.Amount >= finalCost.Amount; if (enoughMoney && enoughFinalMoney) { Console.WriteLine("You will pay {0} with your {1}.", cost, wallet); } else if (enoughFinalMoney) { Console.WriteLine("This time, {0} will be enough to pay {1}.", wallet, finalCost); } else { Console.WriteLine("You cannot pay {0} with your {1}.", cost, wallet); } }