예제 #1
0
 private static void AddRepairs(IEngineer e, string[] repair)
 {
     for (int i = 0; i < repair.Length; i += 2)
     {
         string  partName = repair[i];
         int     houres   = int.Parse(repair[i + 1]);
         IRepair r        = new Repair(partName, houres);
         e.AddRepair(r);
     }
 }
예제 #2
0
 private static void Addrepairs(IEngineer engineer, string[] repairArgs)
 {
     for (int i = 0; i < repairArgs.Length; i += 2)
     {
         string  partName = repairArgs[i];
         int     hours    = int.Parse(repairArgs[i + 1]);
         IRepair repair   = new Repair(partName, hours);
         engineer.AddRepair(repair);
     }
 }
예제 #3
0
 private static void CreateEngineer(string[] soldierArgs, IEngineer engineer)
 {
     string[] repairs = soldierArgs
                        .Skip(6)
                        .ToArray();
     for (int i = 0; i < repairs.Length; i += 2)
     {
         IRepair repair = new Repair(repairs[i], int.Parse(repairs[i + 1]));
         engineer.AddRepair(repair);
     }
 }
예제 #4
0
        private static IEngineer GetRepairs(string[] dataArr, IEngineer engineer)
        {
            for (int i = 7; i < dataArr.Length; i += 2)
            {
                string  part        = dataArr[i - 1];
                string  hoursWorket = dataArr[i];
                IRepair repair      = new Repair(part, int.Parse(hoursWorket));
                engineer.AddRepair(repair);
            }

            return(engineer);
        }
예제 #5
0
        private static void AddRepairs(string[] repairArgs, IEngineer engineer)
        {
            for (int i = 0; i < repairArgs.Length; i += 2)
            {
                var partName = repairArgs[i];
                var hours    = int.Parse(repairArgs[i + 1]);

                var repair = new Repair(partName, hours);

                engineer.AddRepair(repair);
            }
        }
        private static void AddPepairs(IEngineer engineer, string[] repearTokens)
        {
            for (int i = 0; i < repearTokens.Length; i += 2)
            {
                string partName    = repearTokens[i];
                int    hoursWorked = int.Parse(repearTokens[i + 1]);

                IRepair repair = new Repair(partName, hoursWorked);

                engineer.AddRepair(repair);
            }
        }
        public void Run()
        {
            List <ISoldier> soldiers = new List <ISoldier>();

            string input = string.Empty;

            while ((input = Console.ReadLine()) != "End")
            {
                string[] elements = input
                                    .Split(" ", StringSplitOptions.RemoveEmptyEntries)
                                    .ToArray();

                string typeSoldier = elements[0];
                string id          = elements[1];
                string firstName   = elements[2];
                string lastName    = elements[3];

                ISoldier soldier = null;

                if (typeSoldier == "Private")
                {
                    decimal salary = decimal.Parse(elements[4]);

                    soldier = new Private(id, firstName, lastName, salary);
                }
                else if (typeSoldier == "LieutenantGeneral")
                {
                    decimal salary = decimal.Parse(elements[4]);

                    soldier = new LieutenantGeneral(id, firstName, lastName, salary);

                    for (int i = 5; i < elements.Length; i++)
                    {
                        string targetId = elements[i];

                        IPrivate @private = (IPrivate)soldiers
                                            .FirstOrDefault(x => x.Id == targetId);

                        ILieutenantGeneral lieutenantGeneral = soldier as ILieutenantGeneral;
                        lieutenantGeneral.AddPrivate(@private);
                    }
                }
                else if (typeSoldier == "Engineer")
                {
                    decimal salary     = decimal.Parse(elements[4]);
                    string  targetCorp = elements[5];

                    bool isCorpValid = Enum.TryParse <Corp>(targetCorp, out Corp corp);
                    if (!isCorpValid)
                    {
                        continue;
                    }

                    soldier = new Engineer(id, firstName, lastName, salary, corp);

                    IEngineer engineer = soldier as IEngineer;

                    for (int i = 6; i < elements.Length; i += 2)
                    {
                        string partName = elements[i];
                        int    hours    = int.Parse(elements[i + 1]);

                        IRepair repair = new Repair(partName, hours);
                        engineer.AddRepair(repair);
                    }
                }
                else if (typeSoldier == "Commando")
                {
                    decimal salary     = decimal.Parse(elements[4]);
                    string  targetCorp = elements[5];

                    bool isCorpValid = Enum.TryParse <Corp>(targetCorp, out Corp corp);
                    if (!isCorpValid)
                    {
                        continue;
                    }

                    soldier = new Commando(id, firstName, lastName, salary, corp);

                    ICommando commando = soldier as ICommando;

                    for (int i = 6; i < elements.Length; i += 2)
                    {
                        string codeName           = elements[i];
                        string targetMissionState = elements[i + 1];

                        bool isMissionStateValid = Enum.TryParse <MissionState>(targetMissionState, out MissionState missionState);
                        if (!isMissionStateValid)
                        {
                            continue;
                        }

                        IMission mission = new Mission(codeName, missionState);
                        commando.AddMission(mission);
                    }
                }
                else if (typeSoldier == "Spy")
                {
                    int codeNumber = int.Parse(elements[4]);

                    soldier = new Spy(id, firstName, lastName, codeNumber);
                }

                soldiers.Add(soldier);
            }

            foreach (ISoldier soldier in soldiers)
            {
                Console.WriteLine(soldier);
            }
        }