Example #1
0
        static void Main(string[] args)
        {
            try
            {
                string   data = Console.ReadLine();
                string[] str  = data.Split(' ');
                if (str.Length != 4)
                {
                    throw new Exception();
                }
                string workType = str[0].ToLower();
                if (workType != "p" && workType != "f")
                {
                    throw new Exception();
                }
                int rate = int.Parse(str[2]);
                if (rate < 0)
                {
                    throw new Exception();
                }
                int hours = int.Parse(str[3]);
                if (hours < 0)
                {
                    throw new Exception();
                }

                if (workType == "p")
                {
                    PartTime pt = new PartTime(str[1], rate, hours); //TODO
                    Console.Write("PartTime {0} {1}", str[1].ToString(), pt.salary());
                }
                if (workType == "f")
                {
                    FullTime ft = new FullTime(str[1], rate, hours); //TODO
                    Console.Write("FullTime {0} {1}", str[1].ToString(), ft.salary());
                }
            }
            catch
            {
                Console.Write("error");
            }
            Console.ReadKey();
        }
Example #2
0
        static double calculateTotalSalary(int pRate, int fRate)
        {
            string[] lines = System.IO.File.ReadAllLines("read.txt");
            string[] tokens;
            char     workType;
            string   name;
            int      hours;
            clerk    clerk       = null;
            double   salaryTotal = 0;

            foreach (string line in lines)
            {
                tokens   = line.Split(',');
                workType = tokens[0][0];
                name     = tokens[1];
                hours    = int.Parse(tokens[2]);
                switch (workType)
                {
                case 'm':
                    clerk           = new FullTime(name, fRate, hours);
                    clerk.isManager = true;
                    break;

                case 'f':
                    clerk           = new FullTime(name, fRate, hours);
                    clerk.isManager = false;
                    break;

                case 'p':
                    clerk = new PartTime(name, pRate, hours);
                    break;
                }
                salaryTotal += clerk.salary();
                //Console.WriteLine("{0} => {1}", line, clerk.salary());
            }
            return(salaryTotal);
        }