Esempio n. 1
0
        public void Run()
        {
            while (true)
            {
                string[] input   = Console.ReadLine().Split();
                string   command = input[0];

                if (command == "End")
                {
                    return;
                }

                switch (command)
                {
                case "Job":
                    string    jobName      = input[1];
                    int       hours        = int.Parse(input[2]);
                    string    employeeName = input[3];
                    IEmployee employee     = this.employees.FirstOrDefault(e => e.Name == employeeName);
                    jobManager.CreateJob(jobName, hours, employee);
                    break;

                case "StandardEmployee":
                    employeeName = input[1];
                    IEmployee newEmployee = new StandardEmployee(employeeName);
                    this.employees.Add(newEmployee);
                    break;

                case "PartTimeEmployee":
                    employeeName = input[1];
                    newEmployee  = new PartTimeEmployee(employeeName);
                    this.employees.Add(newEmployee);
                    break;

                case "Pass":
                    jobManager.PassWeek();
                    break;

                case "Status":
                    jobManager.GetStats();
                    break;

                default:
                    break;
                }
            }
        }
        static void Main(string[] args)
        {
            var input      = Console.ReadLine();
            var allWorkers = new List <IEmployee>();
            var allJobs    = new List <Job>();

            while (input != "End")
            {
                var currentInput = input.Split();
                var commandType  = currentInput[0];

                switch (commandType)
                {
                case "StandardEmployee":
                    var standardEmployee = new StandardEmployee(currentInput[1]);
                    allWorkers.Add(standardEmployee);
                    break;

                case "PartTimeEmployee":
                    var partTimeEmployee = new PartTimeEmployee(currentInput[1]);
                    allWorkers.Add(partTimeEmployee);
                    break;

                case "Job":
                    var jobName             = currentInput[1];
                    var hoursOfWorkRequired = int.Parse(currentInput[2]);
                    var employeeName        = currentInput[3];
                    var currentEmplpoyee    = allWorkers.FirstOrDefault(x => x.Name == employeeName);
                    var currentJob          = new Job(currentEmplpoyee, jobName, hoursOfWorkRequired);
                    allJobs.Add(currentJob);
                    break;

                case "Pass":
                    PassWeek(allJobs);
                    break;

                case "Status":
                    CheckJobStatus(allJobs);
                    break;
                }


                input = Console.ReadLine();
            }
        }
        private static void AddEmployee(string[] commandArgs, List <IEmployee> employees)
        {
            string employeeType = commandArgs[0];
            string employeeName = commandArgs[1];

            IEmployee employee = null;

            switch (employeeType)
            {
            case "StandardEmployee":
                employee = new StandardEmployee(employeeName);
                break;

            case "PartTimeEmployee":
                employee = new PartTimeEmployee(employeeName);
                break;
            }

            employees.Add(employee);
        }