Exemplo n.º 1
0
    static void Main(string[] args)
    {
        CashRegister cr = new CashRegister();

        string[] denoms = ("'PENNY': .01,'NICKEL': .05,'DIME': .10,'QUARTER': .25,'HALF DOLLAR': .50,'ONE':" +
                            "1.00,'TWO': 2.00,'FIVE': 5.00,'TEN': 10.00,'TWENTY': 20.00,'FIFTY': 50.00,'ONE HUNDRED': 100.00").Split(',');

        foreach (string s in denoms)
        {
            string[] split = s.Split(':');

            string name = split[0].Substring(1, split[0].Length - 2);
            decimal value = decimal.Parse(split[1].Trim());

            cr.AddCash(new Currency(name, value));
        }

        using (StreamReader reader = File.OpenText(args[0]))
            while (!reader.EndOfStream)
            {
                string line = reader.ReadLine();
                if (line == null) continue;

                decimal[] values = line.Split(';').Select(x => decimal.Parse(x)).ToArray();

                Console.WriteLine(cr.GetChange(values));
            }
    }