コード例 #1
0
        public string GetChange()   //CODE REVIEW: returning string is bad - better to return ChangeMachine Object with properties - string writing should be handled by UI classes
        {                           //CODE REIVEW: Also make method name more descriptive - it is also writing the log!
            string   result          = "";
            double   oldBalance      = CurrentBalance;
            DateTime currentDateTime = DateTime.Now;

            result        += MoneyMachine.ChangeConverter(oldBalance);
            CurrentBalance = 0;
            string oldBalanceString = oldBalance.ToString("c");


            string feedMoneyLog = currentDateTime.ToString() + " GET CHANGE: " + "\t" + oldBalanceString + "\t" + "$0.00";

            this.PurchaseLog.Add(feedMoneyLog);


            return(result);
        }
コード例 #2
0
        //Methods
        public void AddMoney(double amountOfMoney)
        {
            double   oldBalance      = CurrentBalance;
            DateTime currentDateTime = DateTime.Now;


            //amountOfMoney = CheckInput.PickAnInteger ("Machine only accepts the following bills: $1, $2, $5, $10, $20");
            if (MoneyMachine.BillCheck(amountOfMoney))
            {
                CurrentBalance += amountOfMoney;

                string oldBalanceString = oldBalance.ToString("c");
                double newBalance       = CurrentBalance;
                string newBalanceString = newBalance.ToString("c");

                string feedMoneyLog = currentDateTime.ToString() + " FEED MONEY:" + "\t" + oldBalanceString + "\t" + newBalanceString;
                this.PurchaseLog.Add(feedMoneyLog);
            }
            else
            {
                throw new Exception("INVALID INPUT... Please enter an accepted bill value...");
            }
        }