コード例 #1
0
        public static void Main(string[] args)
        {
            var denominationsInRegister = new List <ICurrencyDenomination>
            {
                new UsCurrencyDenomination(1, "Penny", "Pennies"),
                new UsCurrencyDenomination(5, "Nickel", "Nickels"),
                new UsCurrencyDenomination(10, "Dime", "Dimes"),
                new UsCurrencyDenomination(25, "Quarter", "Quarters"),
                new UsCurrencyDenomination(100, "Dollar Bill", "Dollar Bills"),
                new UsCurrencyDenomination(500, "Five Dollar Bill", "Five Dollar Bills"),
                new UsCurrencyDenomination(1000, "Ten Dollar Bill", "Ten Dollar Bills"),
                new UsCurrencyDenomination(2000, "Twenty Dollar Bill", "Twenty Dollar Bills"),
                new UsCurrencyDenomination(10000, "Hundred Dollar Bill", "Hundred Dollar Bills")
            };

            IChangeCalculationStrategy randomizedChangeStrategy = new RandomizedChangeCalculationStrategy();
            CashRegister randomCashRegister = new CashRegister(denominationsInRegister, randomizedChangeStrategy);

            string filePath = @"c:\CashRegisterTestInput.txt";
            IPurchaseTransactionImporter      purchaseTransactionFileImporter = new PurchaseTransactionFileImporter(filePath);
            IEnumerable <PurchaseTransaction> purchaseTransactions            = purchaseTransactionFileImporter.GetPurchaseTransactions();

            foreach (PurchaseTransaction transaction in purchaseTransactions)
            {
                OutputChange(randomCashRegister, transaction);
            }

            Console.ReadLine();
        }
コード例 #2
0
            static void Main(string[] args)
            {
                Dictionary <string, decimal> test = new Dictionary <string, decimal>
                {
                    { "Hundred", 100m },
                    { "Fifty", 50m },
                    { "Twenty", 20m },
                    { "Ten", 10m },
                    { "Five", 5m },
                    { "Two", 2m },
                    { "One", 1m },
                    { "50 cent", 0.5m },
                    { "twenty cent", .20m },
                    { "25 cent", .25m },
                    { "ten cent", .1m },
                    { "0.05 cent", 0.05m },
                    { "0.02 cent", 0.02m },
                    { "0.01", 0.01m }
                };
                var bins = SeedCashRegister(50m, test);

                foreach (var bin in bins)
                {
                    Console.WriteLine("{0}\t {1}\t {2}", bin.Money.Denomination, bin.Money.Value, bin.Unit);
                }
                var mon = new Money
                {
                    Denomination = "50 Cent",
                    Value        = 0.5m
                };
                var mo = new Money
                {
                    Denomination = "One",
                    Value        = 1m
                };

                var li = new List <Bin>
                {
                    new Bin
                    {
                        Money = mon,
                        Unit  = 2
                    },
                    new Bin
                    {
                        Money = mo,
                        Unit  = 3
                    }
                };

                var cashRegister = new CashRegister(bins);
                var str          = cashRegister.TransactionExecution(10m, li, bins);

                Console.WriteLine(str);
                Console.ReadKey();
            }
コード例 #3
0
        static void Main(string[] args)
        {
            _cashRegister = new CashRegister();
            SetPredifinedData();
            DisplayAvailableItemsAndCouponsInStore();

            Console.WriteLine("\n-------------------------------------");
            string option = string.Empty;

            option = GetUserOptionSelection();
            ExitIfNecessary(option);

            if (option == START_SCANNING)
            {
                ManageUserInteraction();
            }

            Console.ReadLine();
        }
コード例 #4
0
ファイル: Program.cs プロジェクト: GreenJT/CashRegister
        static void Main(string[] args)
        {
            bool isDivisibleBy3 = false;
            var  register       = new CashRegister();

            try
            {
                var           inputPath               = ConfigurationManager.AppSettings["InputPath"];
                var           outputPath              = ConfigurationManager.AppSettings["OutputPath"];
                var           fileUtil                = new FileProcessorUtil(@inputPath);
                var           denominationNames       = GetDenominationNames("DenominationName");
                var           pluralDenominationNames = GetDenominationNames("DenominationNamePlural");
                var           denominationValues      = GetDenominationValues();
                StringBuilder output = new StringBuilder();

                //loop through each transaction from the input file and determine how change should be dispersed.
                foreach (string sale in fileUtil.Transactions)
                {
                    var transactionSet = sale.Split(',');
                    register.Action            = new Sale();
                    register.Action.Cost       = (int)(Convert.ToDouble(transactionSet[0]) * 100);
                    register.Action.AmountPaid = (int)Convert.ToDouble(transactionSet[1]) * 100;

                    isDivisibleBy3 = register.Action.Cost % 3 == 0 ? true : false;
                    var change    = register.Action.PerformTransaction();
                    var moneyUsed = CreateChange(change, denominationValues, denominationNames, isDivisibleBy3);
                    output.Append(GenerateOutput(denominationNames, pluralDenominationNames, moneyUsed));
                }

                fileUtil.Change = output.ToString();
                fileUtil.WriteToFile(@outputPath);
            }
            catch (Exception ex)
            {
                string errorLogPath = AppDomain.CurrentDomain.BaseDirectory +
                                      "ErrorLog " + DateTime.Now.Date.Month + "-" +
                                      DateTime.Now.Date.Day + "-" + DateTime.Now.Date.Year + " " +
                                      DateTime.Now.TimeOfDay.Hours + "H" + DateTime.Now.TimeOfDay.Minutes + "M" + ".txt";
                ErrorLog log = new ErrorLog(errorLogPath);
                log.WriteError(ex.Message);
            }
        }
コード例 #5
0
        static void Main(string[] args)
        {
            //for the initial amount.
            const double TOTAL_AMOUNT = 100;
            IAction      action       = null;

            //register the cash register.
            CashRegister cashRegister = new CashRegister(TOTAL_AMOUNT);

            // open the cash register.
            cashRegister.OpenRegister();

            // operate transaction.
            cashRegister.DoTransactionLine(action);

            //cloes the cash register.
            cashRegister.CloseRegister();

            Console.ReadKey();
        }
コード例 #6
0
        public static void Main(string[] args)
        {
            // declare a new CashRegister object
            CashRegister myRegister = new CashRegister(0.06);

            // add several dollar amounts
            myRegister.add(20.00);
            myRegister.add(15.50);
            myRegister.add(3.75);

            CashRegister.setCurrencyType("EURO");
            Console.WriteLine("The current currency type: " + CashRegister.getCurrencyType());

            // display the current cash balance and tax info
            Console.WriteLine("The register has: " + myRegister.report().ToString("C"));
            double taxCollected = myRegister.getSalesTax() * myRegister.report();

            Console.WriteLine("Sales tax rate: " + myRegister.getSalesTax().ToString("P"));
            Console.WriteLine("Sales tax collected: " + taxCollected.ToString("C"));
            Console.ReadLine();
        }
コード例 #7
0
 private static void OutputChange(CashRegister cashRegister, PurchaseTransaction transaction)
 {
     Console.WriteLine(cashRegister.CalculateChange(transaction));
 }