Example #1
0
        public string EngageMachine(string selectedPilotName, string selectedMachineName)
        {
            if (!this.pilots.ContainsKey(selectedPilotName))
            {
                return(string.Format(OutputMessages.PilotNotFound, selectedPilotName));
            }

            if (!this.machines.ContainsKey(selectedMachineName))
            {
                return(string.Format(OutputMessages.MachineNotFound, selectedMachineName));
            }

            Pilot    pilot   = this.pilots[selectedPilotName] as Pilot;
            IMachine machine = this.machines[selectedMachineName];

            if (machine.Pilot != null)
            {
                return(string.Format(OutputMessages.MachineHasPilotAlready, selectedMachineName));
            }
            else
            {
                machine.Pilot = pilot;
                pilot.AddMachine(machine);
                return(string.Format(OutputMessages.MachineEngaged, selectedPilotName, selectedMachineName));
            }
        }
Example #2
0
        public string EngageMachine(string selectedPilotName, string selectedMachineName)
        {
            var  pilot  = new Pilot(selectedPilotName);
            bool cheker = false;

            for (int i = 0; i < pilots.Count; i++)
            {
                Pilot curerent = (Pilot)pilots[i];
                if (curerent.Name == selectedPilotName)
                {
                    cheker = true;
                }
            }
            if (!cheker)
            {
                return($"Pilot {pilot.Name} could not be found");
            }
            for (int i = 0; i < machines.Count; i++)
            {
                if (machines[i].Name == selectedMachineName)
                {
                    if (machines[i].Pilot != null)
                    {
                        return($"Machine {selectedMachineName} is already occupied");
                    }
                    else
                    {
                        machines[i].Pilot = pilot;
                        pilot.AddMachine(machines[i]);
                        return($"Pilot {selectedPilotName} engaged machine {selectedMachineName}");
                    }
                }
            }
            return($"Machine {selectedMachineName} could not be found");
        }