Beispiel #1
0
        static void Main(string[] args)
        {
            var army = new Dictionary <string, ISoldier>();

            string[] info;

            while ((info = Console.ReadLine().Split(" ", StringSplitOptions.RemoveEmptyEntries))[0]
                   .ToLower() != "end")
            {
                string rank      = info[0];
                string id        = info[1];
                string firstName = info[2];
                string lastName  = info[3];

                switch (rank)
                {
                case "Private":
                    // "Private <id> <firstName> <lastName> <salary>
                    army.Add(id, new Private(id, firstName, lastName, decimal.Parse(info[4])));
                    break;

                case "LieutenantGeneral":
                    // LieutenantGeneral <id> <firstName> <lastName> <salary> <private1Id> <private2Id> … <privateNId>
                    var lieutenantGeneral = new LieutenantGeneral(id, firstName, lastName, decimal.Parse(info[4]));
                    lieutenantGeneral.Privates = info[5..].Select(i => army[i]).ToList();
Beispiel #2
0
        private static void FillList(List <Soldier> soldiers, string[] parts)
        {
            switch (parts[0])
            {
            case "Private":
                soldiers.Add(Private.Create(parts));
                break;

            case "LieutenantGeneral":
                soldiers.Add(LieutenantGeneral.Create(parts, soldiers));
                break;

            case "Engineer":
                soldiers.Add(Engineer.Create(parts));
                break;

            case "Commando":
                soldiers.Add(Commando.Create(parts));
                break;

            case "Spy":
                soldiers.Add(Spy.Create(parts));
                break;

            default:
                break;
            }
        }
Beispiel #3
0
        public static LieutenantGeneral Create(string[] parts, List <Soldier> soldiers)
        {
            LieutenantGeneral current = new LieutenantGeneral(parts[1], parts[2],
                                                              parts[3], decimal.Parse(parts[4]));

            current.AddPrivates(parts, soldiers);
            return(current);
        }
Beispiel #4
0
        private void AddLieutenantGeneral(string[] arr)
        {
            var general = new LieutenantGeneral(
                int.Parse(arr[0]),
                arr[1],
                arr[2],
                decimal.Parse(arr[3]),
                GetPrivate(arr.Skip(4).Select(int.Parse).ToArray()));

            solgers.Add(general);
        }
        public static void AddGeneral(List <Soldier> soldiers, string[] commandArray)
        {
            LieutenantGeneral general = new LieutenantGeneral(commandArray[1], commandArray[2], commandArray[3], decimal.Parse(commandArray[4]));

            for (int i = 5; i < commandArray.Length; i++)
            {
                Private pr = (Private)soldiers.Find(s => s.Id == commandArray[i]);
                general.Privates.Add(pr);
            }

            soldiers.Add(general);
        }
Beispiel #6
0
        private static void AddLeutenantGeneral(string[] tokens)
        {
            LieutenantGeneral general = new LieutenantGeneral(tokens[1], tokens[2], tokens[3], double.Parse(tokens[4]));

            for (int i = 5; i < tokens.Length; i++)
            {
                Private privat = (Private)soldiers.Single(s => s.Id == tokens[i]);
                general.AddPrivate(privat);
            }

            soldiers.Add(general);
        }
Beispiel #7
0
        private static void CreateLeutenantGeneral(List <Private> allPrivates, string[] tokens, int id, string firstName, string lastName, decimal salary)
        {
            List <IPrivate> currentLeutenantPrivatesLIst = new List <IPrivate>();

            for (int i = 5; i < tokens.Length; i++)
            {
                int     currentId      = int.Parse(tokens[i]);
                Private currentPrivate = allPrivates.FirstOrDefault(p => p.ID == currentId);
                currentLeutenantPrivatesLIst.Add(currentPrivate);
            }
            LieutenantGeneral lieutenantGeneral = new LieutenantGeneral(id, firstName, lastName, salary, currentLeutenantPrivatesLIst);

            Console.WriteLine(lieutenantGeneral.ToString());
        }
        public void Run()
        {
            string soldierInput = this.reader.ReadLine();

            while (soldierInput.ToLower() != "end")
            {
                string[] soldierArgs   = soldierInput.Split(' ').ToArray();
                string   soldierType   = soldierArgs[0];
                string[] soldierParams = soldierArgs.Skip(1).ToArray();

                try
                {
                    if (soldierType == "Private")
                    {
                        Private newPrivate = CreatePrivate(soldierParams);
                        soldiers.Add(newPrivate);
                    }
                    else if (soldierType == "LieutenantGeneral")
                    {
                        LieutenantGeneral lieutenantGeneral = CreateLieutenantGeneral(soldierParams);
                        soldiers.Add(lieutenantGeneral);
                    }
                    else if (soldierType == "Engineer")
                    {
                        Engineer engineer = CreateEngineer(soldierParams);
                        soldiers.Add(engineer);
                    }
                    else if (soldierType == "Commando")
                    {
                        Commando commando = CreateCommando(soldierParams);
                        soldiers.Add(commando);
                    }
                    else if (soldierType == "Spy")
                    {
                        Spy spy = CreateSpy(soldierParams);
                        soldiers.Add(spy);
                    }
                }
                catch (InvalidCastException)
                {
                }

                soldierInput = this.reader.ReadLine();
            }

            foreach (Soldier soldier in soldiers)
            {
                this.writer.WriteLine(soldier.ToString());
            }
        }
        private ISoldier AddGeneral(string[] cmdArgs, int id, string firstName, string lastName)
        {
            ISoldier           soldier;
            decimal            salary            = decimal.Parse(cmdArgs[4]);
            ILieutenantGeneral lieutenantGeneral = new LieutenantGeneral(id, firstName, lastName, salary);

            foreach (var pId in cmdArgs.Skip(5))
            {
                ISoldier @private = this.soldiers.First(s => s.Id == int.Parse(pId));

                lieutenantGeneral.AddPrivate(@private);
            }
            soldier = lieutenantGeneral;
            return(soldier);
        }
Beispiel #10
0
        private ISoldier AddGeneral(string[] commandArgs, int ID, string firstName, string lastName)
        {
            ISoldier soldier;
            decimal  salary = decimal.Parse(commandArgs[4]);

            LieutenantGeneral general = new LieutenantGeneral(ID, firstName, lastName, salary);

            foreach (var item in commandArgs.Skip(5))
            {
                ISoldier privateToAdd = soldiers.First(s => s.ID == int.Parse(item));

                general.AddPrivate(privateToAdd);
            }

            soldier = general;
            return(soldier);
        }
Beispiel #11
0
        static void Main(string[] args)
        {
            string command;
            var    allSoldiers = new List <Soldier>();

            while ((command = Console.ReadLine()) != "End")
            {
                var cmdArgs     = command.Split();
                var soldierType = cmdArgs[0];
                switch (soldierType)
                {
                case "Private":
                    var privateS = new Private(cmdArgs[1], cmdArgs[2], cmdArgs[3], decimal.Parse(cmdArgs[4]));
                    allSoldiers.Add(privateS);
                    break;

                case "LieutenantGeneral":
                    var lieutenantGeneral = new LieutenantGeneral(cmdArgs[1], cmdArgs[2], cmdArgs[3], decimal.Parse(cmdArgs[4]));
                    lieutenantGeneral.GetPrivates(cmdArgs, allSoldiers);
                    allSoldiers.Add(lieutenantGeneral);
                    break;

                case "Engineer":
                    var engineer = new Engineer();
                    engineer.ReadEngineer(cmdArgs, allSoldiers);
                    break;

                case "Commando":
                    var commando = new Commando();
                    commando.ReadCommando(cmdArgs, allSoldiers);
                    break;

                case "Spy":
                    var spy = new Spy(cmdArgs[1], cmdArgs[2], cmdArgs[3], int.Parse(cmdArgs[4]));
                    allSoldiers.Add(spy);
                    break;

                default:
                    break;
                }
            }
            Console.WriteLine(String.Join(Environment.NewLine, allSoldiers));
        }
Beispiel #12
0
        private void LieutenantGeneralCreator(string[] inputArr)
        {
            string  id                   = inputArr[1];
            string  firstName            = inputArr[2];
            string  lastName             = inputArr[3];
            decimal salary               = decimal.Parse(inputArr[4]);
            var     newLieutenantGeneral = new LieutenantGeneral(id, firstName, lastName, salary);

            for (int i = 5; i < inputArr.Length; i++)
            {
                if (soldiersList.Any(x => x.Id == inputArr[i]))
                {
                    Private toAdd = (Private)soldiersList.FirstOrDefault(x => x.Id == inputArr[i]);
                    newLieutenantGeneral.AddPrivate(toAdd);
                }
            }

            soldiersList.Add(newLieutenantGeneral);
        }
        private LieutenantGeneral CreateLieutenantGeneral(string[] soldierParams)
        {
            // LieutenantGeneral<id> < firstName > < lastName > < salary > < private1Id > < private2Id > … < privateNId >
            string  id        = soldierParams[0];
            string  firstName = soldierParams[1];
            string  lastName  = soldierParams[2];
            decimal salary    = decimal.Parse(soldierParams[3]);

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

            for (int i = 4; i < soldierParams.Length; i++)
            {
                string  newPrivateId = soldierParams[i];
                Private newPrivate   = (Private)this.soldiers.Where(s => s.Id == newPrivateId).FirstOrDefault();
                lieutenantGeneral.AddPrivate(newPrivate);
            }

            return(lieutenantGeneral);
        }
Beispiel #14
0
        private static LieutenantGeneral CreateLieutenant(
            string id,
            string firstName,
            string lastName,
            decimal salary,
            List <Private> privates,
            List <string> commandParts)
        {
            var lieutenantGeneral = new LieutenantGeneral(id, firstName, lastName, salary);

            foreach (var privateId in commandParts.Skip(5))
            {
                var privateSoldier = privates.Where(x => x.Id == privateId).FirstOrDefault();

                lieutenantGeneral?.AddPrivate(privateSoldier);
            }

            return(lieutenantGeneral);
        }
Beispiel #15
0
        static void Main()
        {
            var    privates = new Dictionary <string, Private>();
            string input;

            while ((input = Console.ReadLine()) != "End")
            {
                var     cmdArgs     = input.Split(new[] { ' ' }, StringSplitOptions.RemoveEmptyEntries);
                var     soldierType = cmdArgs[0];
                string  id;
                string  firstName;
                string  lastName;
                decimal salary;
                Corps   corps;

                switch (soldierType)
                {
                case "Private":
                    id        = cmdArgs[1];
                    firstName = cmdArgs[2];
                    lastName  = cmdArgs[3];
                    salary    = decimal.Parse(cmdArgs[4]);

                    var privateSoldier = new Private(firstName, lastName, id, salary);
                    privates.Add(id, privateSoldier);
                    Console.WriteLine(privateSoldier);
                    break;

                case "LieutenantGeneral":
                    id        = cmdArgs[1];
                    firstName = cmdArgs[2];
                    lastName  = cmdArgs[3];
                    salary    = decimal.Parse(cmdArgs[4]);
                    var leutenantGeneral = new LieutenantGeneral(firstName, lastName, id, salary);

                    if (cmdArgs.Length >= 5)
                    {
                        for (var i = 5; i < cmdArgs.Length; i++)
                        {
                            string privateId = cmdArgs[i];
                            privateSoldier = privates[privateId];

                            leutenantGeneral.Privates.Add(privateSoldier);
                        }
                    }
                    Console.WriteLine(leutenantGeneral);
                    break;

                case "Engineer":
                    id        = cmdArgs[1];
                    firstName = cmdArgs[2];
                    lastName  = cmdArgs[3];
                    salary    = decimal.Parse(cmdArgs[4]);

                    if (Enum.TryParse(cmdArgs[5], out corps))
                    {
                        var engineer = new Engineer(firstName, lastName, id);

                        if (cmdArgs.Length >= 6)
                        {
                            for (var i = 6; i < cmdArgs.Length; i += 2)
                            {
                                var repairPartName = cmdArgs[i];
                                var repairHours    = int.Parse(cmdArgs[i + 1]);

                                var repair = new Repair(repairPartName, repairHours);
                                engineer.Repairs.Add(repair);
                            }
                        }
                        Console.WriteLine(engineer);
                    }
                    break;

                case "Commando":
                    id        = cmdArgs[1];
                    firstName = cmdArgs[2];
                    lastName  = cmdArgs[3];
                    salary    = decimal.Parse(cmdArgs[4]);

                    if (Enum.TryParse(cmdArgs[5], out corps))
                    {
                        Commando commando = new Commando(firstName, lastName, id, salary, corps);

                        if (cmdArgs.Length > 6)
                        {
                            for (var i = 6; i < cmdArgs.Length; i += 2)
                            {
                                if (Enum.TryParse(cmdArgs[i + 1], out MissionState missionState))
                                {
                                    var missionName = cmdArgs[i];
                                    var mission     = new Mission(missionName, missionState);
                                    commando.Missions.Add(mission);
                                }
                            }
                            Console.WriteLine(commando.ToString());
                        }
                    }
                    break;

                case "Spy":
                    id        = cmdArgs[1];
                    firstName = cmdArgs[2];
                    lastName  = cmdArgs[3];
                    var codeNumber = int.Parse(cmdArgs[4]);

                    var spy = new Spy(id, firstName, lastName, codeNumber);
                    Console.WriteLine(spy);
                    break;

                default:
                    throw new ArgumentException("Invalid Type of Soldier!");
                }
            }
        }
Beispiel #16
0
        static void Main(string[] args)
        {
            var privateList = new List <Private>();

            while (true)
            {
                string[] input = Console.ReadLine().Split();

                if (input[0] == "End")
                {
                    break;
                }

                else if (input[0] == "Private")
                {
                    id        = int.Parse(input[1]);
                    firstName = input[2];
                    lastName  = input[3];
                    salary    = decimal.Parse(input[4]);

                    var privateSoldie = new Private(id, firstName, lastName, salary);
                    privateList.Add(privateSoldie);
                    Console.WriteLine(privateSoldie);
                }
                else if (input[0] == "Spy")
                {
                    id        = int.Parse(input[1]);
                    firstName = input[2];
                    lastName  = input[3];

                    int code = int.Parse(input[4]);


                    var spy = new Spy(id, firstName, lastName, code);
                    Console.WriteLine(spy);
                }
                else if (input[0] == "Engineer")
                {
                    id        = int.Parse(input[1]);
                    firstName = input[2];
                    lastName  = input[3];
                    salary    = decimal.Parse(input[4]);
                    corp      = input[5];
                    try
                    {
                        var engineer = new Engineer(id, firstName, lastName, salary, corp);
                        //string[] result = input.Skip(6).ToArray();
                        for (int i = 6; i < input.Length; i += 2)
                        {
                            string partname = input[i];
                            int    hours    = int.Parse(input[i + 1]);
                            var    repair   = new Repair(partname, hours);
                            engineer.Add(repair);
                        }
                        Console.WriteLine(engineer);
                    }
                    catch (ArgumentException)
                    {
                        //continue;
                    }
                }
                else if (input[0] == "Commando")
                {
                    id        = int.Parse(input[1]);
                    firstName = input[2];
                    lastName  = input[3];
                    salary    = decimal.Parse(input[4]);
                    corp      = input[5];

                    try
                    {
                        var commando = new Commando(id, firstName, lastName, salary, corp);
                        //string[] result = input.Skip(6).ToArray();

                        for (int i = 6; i < input.Length; i += 2)
                        {
                            string partname = input[i];
                            string state    = input[i + 1];
                            try
                            {
                                var repair = new Mission(partname, state);
                                commando.Add(repair);
                            }
                            catch (ArgumentException)
                            {
                                //continue;
                            }
                        }
                        Console.WriteLine(commando);
                    }
                    catch (ArgumentException)
                    {
                        //continue;
                    }
                }
                else if (input[0] == "LieutenantGeneral")
                {
                    id        = int.Parse(input[1]);
                    firstName = input[2];
                    lastName  = input[3];
                    salary    = decimal.Parse(input[4]);



                    var leutenant = new LieutenantGeneral(id, firstName, lastName, salary);
                    //string[] result = input.Skip(5).ToArray();

                    for (int i = 5; i < input.Length; i++)
                    {
                        int num = int.Parse(input[i]);
                        var currentPrivateSoldier = privateList.FirstOrDefault(x => x.Id == num);
                        leutenant.Add(currentPrivateSoldier);
                    }
                    Console.WriteLine(leutenant);
                }
            }
        }
Beispiel #17
0
        public static void Main(string[] args)
        {
            Dictionary <string, ISoldier> soldiersById = new Dictionary <string, ISoldier>();

            while (true)
            {
                string line = Console.ReadLine();

                if (line == "End")
                {
                    break;
                }

                string[] parts = line.Split();

                string type      = parts[0];
                string id        = parts[1];
                string firstName = parts[2];
                string lastName  = parts[3];


                if (type == nameof(Private))
                {
                    decimal salary = decimal.Parse(parts[4]);
                    soldiersById[id] = new Private(id, firstName, lastName, salary);
                }
                else if (type == nameof(LieutenantGeneral))
                {
                    decimal            salary            = decimal.Parse(parts[4]);
                    ILieutenantGeneral lieutenantGeneral = new LieutenantGeneral(id, firstName, lastName, salary);

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

                        if (!soldiersById.ContainsKey(privateId))
                        {
                            continue;
                        }

                        lieutenantGeneral.AddPrivate((IPrivate)soldiersById[privateId]);
                    }

                    soldiersById[id] = lieutenantGeneral;
                }
                else if (type == nameof(Engineer))
                {
                    decimal salary = decimal.Parse(parts[4]);

                    bool isCorpsValid = Enum.TryParse(parts[5], out Corps corps);

                    if (!isCorpsValid)
                    {
                        continue;
                    }

                    IEngineer engineer = new Engineer(id, firstName, lastName, salary, corps);

                    for (int i = 6; i < parts.Length; i += 2)
                    {
                        string part        = parts[i];
                        int    hoursWorked = int.Parse(parts[i + 1]);

                        IRepair repair = new Repair(part, hoursWorked);

                        engineer.AddRepair(repair);
                    }

                    soldiersById[id] = engineer;
                }
                else if (type == nameof(Commando))
                {
                    decimal salary = decimal.Parse(parts[4]);

                    bool isCorpsValid = Enum.TryParse(parts[5], out Corps corps);

                    if (!isCorpsValid)
                    {
                        continue;
                    }

                    ICommando commando = new Commando(id, firstName, lastName, salary, corps);

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

                        bool isMissionValid = Enum.TryParse(state, out MissionState missionState);

                        if (!isMissionValid)
                        {
                            continue;
                        }

                        IMission mission = new Mission(codeName, missionState);

                        commando.AddMission(mission);
                    }

                    soldiersById[id] = commando;
                }
                else if (type == nameof(Spy))
                {
                    int codeNumber = int.Parse(parts[4]);

                    ISpy spy = new Spy(id, firstName, lastName, codeNumber);

                    soldiersById[id] = spy;
                }
            }

            foreach (var soldier in soldiersById.Values)
            {
                Console.WriteLine(soldier);
            }
        }
        public static void Main(string[] args)
        {
            List <Soldier> soldiers = new List <Soldier>();

            while (true)
            {
                string soldier = Console.ReadLine();

                if (soldier == "End")
                {
                    break;
                }

                string[] soldierArgs = soldier.Split();

                string soldierType = soldierArgs[0];
                string id          = soldierArgs[1];
                string firstName   = soldierArgs[2];
                string lastName    = soldierArgs[3];

                if (soldierType == "Private")
                {
                    decimal salary = decimal.Parse(soldierArgs[4]);

                    Private @private = new Private(id, firstName, lastName, salary);

                    soldiers.Add(@private);
                }
                else if (soldierType == "Spy")
                {
                    int codeNumber = int.Parse(soldierArgs[4]);

                    Spy spy = new Spy(id, firstName, lastName, codeNumber);

                    soldiers.Add(spy);
                }
                else if (soldierType == "LieutenantGeneral")
                {
                    decimal salary = decimal.Parse(soldierArgs[4]);

                    // Turning the last elements of the input to List of Ids
                    List <string> ids = soldierArgs.Skip(5).ToList();

                    // Method that accepts List<string> ids and List<soldiers> soldiers => the one we created in the begging
                    // to hold all the types of soldiers
                    HashSet <Private> privates = GetPrivates(ids, soldiers);

                    LieutenantGeneral lieutenantGeneral = new LieutenantGeneral(id, firstName, lastName, salary, privates);

                    soldiers.Add(lieutenantGeneral);
                }
                else if (soldierType == "Engineer")
                {
                    decimal salary = decimal.Parse(soldierArgs[4]);
                    string  corps  = soldierArgs[5];

                    List <string> repairArgs = soldierArgs.Skip(6).ToList();

                    List <Repair> repairs = GetRepairs(repairArgs);

                    try
                    {
                        Engineer engineer = new Engineer(id, firstName, lastName, salary, corps, repairs);

                        soldiers.Add(engineer);
                    }
                    catch (Exception)
                    {
                        continue;
                    }
                }
                else if (soldierType == "Commando")
                {
                    decimal salary = decimal.Parse(soldierArgs[4]);
                    string  corps  = soldierArgs[5];

                    List <string> missionArgs = soldierArgs.Skip(6).ToList();

                    List <Mission> missions = GetMissions(missionArgs);

                    try
                    {
                        Commando commando = new Commando(id, firstName, lastName, salary, corps, missions);

                        soldiers.Add(commando);
                    }
                    catch (Exception)
                    {
                        continue;
                    }
                }
            }

            foreach (var soldier in soldiers)
            {
                Console.WriteLine(soldier);
            }
        }
Beispiel #19
0
        static void Main(string[] args)
        {
            List <ISoldier> soldiers = new List <ISoldier>();

            string[] input = Console.ReadLine().Split();
            while (input[0].ToLower() != "end")
            {
                string title     = input[0].ToLower();
                int    id        = int.Parse(input[1]);
                string firstName = input[2];
                string lastName  = input[3];
                if (title == "private")
                {
                    decimal salary   = decimal.Parse(input[4]);
                    Private @private = new Private(id, firstName, lastName, salary);
                    soldiers.Add(@private);
                }
                else if (title == "lieutenantgeneral")
                {
                    decimal           salary            = decimal.Parse(input[4]);
                    List <IPrivate>   privates          = GetLieutenantGeneralPrivates(input.Skip(5).ToArray(), soldiers);
                    LieutenantGeneral lieutenantGeneral = new LieutenantGeneral(id, firstName, lastName, salary, privates);
                    soldiers.Add(lieutenantGeneral);
                }
                else if (title == "engineer")
                {
                    decimal        salary  = decimal.Parse(input[4]);
                    string         corps   = input[5];
                    List <IRepair> repairs = GetEngineerRepairs(input.Skip(6).ToArray());
                    if (corps == "Airforces")
                    {
                        Engineer engineer = new Engineer(id, firstName, lastName, salary, SoldiersCorpsEnum.Airforces, repairs);
                        soldiers.Add(engineer);
                    }
                    else if (corps == "Marines")
                    {
                        Engineer engineer = new Engineer(id, firstName, lastName, salary, SoldiersCorpsEnum.Marines, repairs);
                        soldiers.Add(engineer);
                    }
                }
                else if (title == "commando")
                {
                    decimal         salary   = decimal.Parse(input[4]);
                    string          corps    = input[5];
                    List <IMission> missions = GetCommandoMissions(input.Skip(6).ToArray());
                    if (corps == "Airforces")
                    {
                        Commando commando = new Commando(id, firstName, lastName, salary, SoldiersCorpsEnum.Airforces, missions);
                        soldiers.Add(commando);
                    }
                    else if (corps == "Marines")
                    {
                        Commando commando = new Commando(id, firstName, lastName, salary, SoldiersCorpsEnum.Marines, missions);
                        soldiers.Add(commando);
                    }
                }
                else if (title == "spy")
                {
                    int codeNumber = int.Parse(input[4]);
                    Spy spy        = new Spy(id, firstName, lastName, codeNumber);
                    soldiers.Add(spy);
                }
                input = Console.ReadLine().Split();
            }
            foreach (var soldier in soldiers)
            {
                Console.WriteLine(soldier);
            }
        }
Beispiel #20
0
        static void Main(string[] args)
        {
            List <Private> privates = new List <Private>();

            while (true)
            {
                try
                {
                    string[] soldierArgs = Console.ReadLine().Split();
                    string   type        = soldierArgs[0];

                    if (type == "End")
                    {
                        break;
                    }
                    string id        = soldierArgs[1];
                    string firstName = soldierArgs[2];
                    string lastName  = soldierArgs[3];

                    if (type == "Spy")
                    {
                        int codeNumber = int.Parse(soldierArgs[4]);
                        var spy        = new Spy(id, firstName, lastName, codeNumber);
                        Console.WriteLine(spy);
                    }
                    else
                    {
                        decimal salary = decimal.Parse(soldierArgs[4]);
                        if (type == "Private")
                        {
                            var @private = new Private(id, firstName, lastName, salary);
                            privates.Add(@private);
                            Console.WriteLine(@private);
                        }
                        else if (type == "LieutenantGeneral")
                        {
                            var privatesGeneral = new List <Private>();
                            for (int i = 5; i < soldierArgs.Length; i++)
                            {
                                var currentPrivate = privates.FirstOrDefault(x => x.Id == soldierArgs[i]);
                                privatesGeneral.Add(currentPrivate);
                            }
                            var leutenant = new LieutenantGeneral(id, firstName, lastName, salary, privatesGeneral);
                            Console.WriteLine(leutenant);
                        }
                        else if (type == "Engineer")
                        {
                            var    repairs = new List <Repair>();
                            string corps   = soldierArgs[5];
                            for (int i = 6; i < soldierArgs.Length; i += 2)
                            {
                                string name   = soldierArgs[i];
                                int    hours  = int.Parse(soldierArgs[i + 1]);
                                var    repair = new Repair(name, hours);
                                repairs.Add(repair);
                            }
                            var engineer = new Engineer(id, firstName, lastName, salary, corps, repairs);
                            Console.WriteLine(engineer);
                        }
                        else if (type == "Commando")
                        {
                            var    missions = new List <Mission>();
                            string corps    = soldierArgs[5];

                            for (int i = 6; i < soldierArgs.Length; i += 2)
                            {
                                try
                                {
                                    string name    = soldierArgs[i];
                                    string state   = soldierArgs[i + 1];
                                    var    mission = new Mission(name, state);
                                    missions.Add(mission);
                                }
                                catch (Exception)
                                {
                                }
                            }
                            var commando = new Commando(id, firstName, lastName, salary, corps, missions);
                            Console.WriteLine(commando);
                        }
                    }
                }
                catch (Exception)
                {
                }
            }
        }
Beispiel #21
0
        static void Main(string[] args)
        {
            string input = Console.ReadLine();

            while (input != "End")
            {
                string[] splitted = input.Split();

                string  soldierType = splitted[0];
                int     id          = int.Parse(splitted[1]);
                string  firstName   = splitted[2];
                string  lastName    = splitted[3];
                decimal salary      = decimal.Parse(splitted[4]);

                ISoldier soldier = null;

                try
                {
                    switch (soldierType)
                    {
                    case "Private":
                        soldier = new Private(id, firstName, lastName, salary);
                        break;

                    case "Spy":
                        soldier = new Spy(id, firstName, lastName, int.Parse(splitted[4]));
                        break;

                    case "LieutenantGeneral":
                        LieutenantGeneral lieutenant = new LieutenantGeneral(id, firstName, lastName, salary);

                        for (int i = 5; i < splitted.Length; i++)
                        {
                            int      privateId      = int.Parse(splitted[i]);
                            ISoldier currentPrivate = soldiers
                                                      .FirstOrDefault(s => s.Id == privateId);
                            lieutenant.AddPrivate(currentPrivate);
                        }

                        soldier = lieutenant;
                        break;

                    case "Engineer":
                        string   engineerCorps = splitted[5];
                        Engineer engineer      = new Engineer(id, firstName, lastName, salary, engineerCorps);

                        for (int i = 6; i < splitted.Length; i += 2)
                        {
                            string  repairPart  = splitted[i];
                            int     repairHours = int.Parse(splitted[i + 1]);
                            IRepair repair      = new Repair(repairPart, repairHours);
                            engineer.AddRepair(repair);
                        }

                        soldier = engineer;
                        break;

                    case "Commando":
                        string   commandoCorps = splitted[5];
                        Commando commando      = new Commando(id, firstName, lastName, salary, commandoCorps);

                        for (int i = 6; i < splitted.Length; i += 2)
                        {
                            string missionCodeName = splitted[i];
                            string missionState    = splitted[i + 1];

                            try
                            {
                                IMission mission = new Mission(missionCodeName, missionState);
                                commando.AddMission(mission);
                            }
                            catch (ArgumentException) { }
                        }

                        soldier = commando;
                        break;

                    default:
                        throw new ArgumentException("Invalid soldier type!");
                    }
                    soldiers.Add(soldier);
                }
                catch (ArgumentException) { }

                input = Console.ReadLine();
            }

            foreach (var soldier in soldiers)
            {
                Console.WriteLine(soldier);
            }
        }
Beispiel #22
0
        static void Main()
        {
            string command;
            var    soldiers = new List <ISoldier>();

            while ((command = Console.ReadLine()) != "End")
            {
                string[] entry = command.Split(" ", StringSplitOptions.RemoveEmptyEntries);

                if (entry[0] == "Private")
                {
                    var newPrivate = new Private(entry[1], entry[2], entry[3], decimal.Parse(entry[4]));
                    soldiers.Add(newPrivate);
                }
                else if (entry[0] == "LieutenantGeneral")
                {
                    var newLtGen = new LieutenantGeneral(entry[1], entry[2], entry[3], decimal.Parse(entry[4]));

                    for (int i = 5; i < entry.Length; i++)
                    {
                        newLtGen.Privates.Add(soldiers.FirstOrDefault(x => x.Id == entry[i]));
                    }

                    soldiers.Add(newLtGen);
                }
                else if (entry[0] == "Engineer" && (entry[5] == "Marines" || entry[5] == "Airforces"))
                {
                    var newEngineer = new Engineer(entry[1], entry[2], entry[3], decimal.Parse(entry[4]), entry[5]);

                    for (int i = 6; i < entry.Length - 1; i += 2)
                    {
                        var newRepair = new Repair(entry[i], int.Parse(entry[i + 1]));
                        newEngineer.Repairs.Add(newRepair);
                    }

                    soldiers.Add(newEngineer);
                }
                else if (entry[0] == "Commando" && (entry[5] == "Marines" || entry[5] == "Airforces"))
                {
                    var newCommando = new Commando(entry[1], entry[2], entry[3], decimal.Parse(entry[4]), entry[5]);

                    for (int i = 6; i < entry.Length - 1; i += 2)
                    {
                        if (entry[i + 1] == "inProgress" || entry[i + 1] == "Finished")
                        {
                            var newMission = new Mission(entry[i], entry[i + 1]);
                            newCommando.Missions.Add(newMission);
                        }
                    }

                    soldiers.Add(newCommando);
                }
                else if (entry[0] == "Spy")
                {
                    var newSpy = new Spy(entry[1], entry[2], entry[3], int.Parse(entry[4]));
                    soldiers.Add(newSpy);
                }
            }

            Console.WriteLine(string.Join(Environment.NewLine, soldiers));
        }
Beispiel #23
0
        public void Run()
        {
            string line = Console.ReadLine();

            while (line != "End")
            {
                string[] args = line.Split(" ", StringSplitOptions.RemoveEmptyEntries);
                string   type = args[0];

                try
                {
                    switch (type)
                    {
                    case "Private":
                        Private privateSoldier = this.privateFactory.MakePrivateSoldier(args);
                        this.soldiers.Add(privateSoldier);
                        break;

                    case "LieutenantGeneral":
                        LieutenantGeneral lieutenantGeneral =
                            this.lieutenantGeneralFactory.MakeLieutenantGeneral(args);

                        for (int i = 5; i < args.Length; i++)
                        {
                            Private currentPrivate =
                                (Private)this.soldiers.FirstOrDefault(p => p.Id == int.Parse(args[i]));

                            lieutenantGeneral.AddPrivate(currentPrivate);
                        }

                        this.soldiers.Add(lieutenantGeneral);

                        break;

                    case "Engineer":
                        Engineer engineer = this.engineerFactory.MakeEngineer(args);

                        for (int i = 6; i < args.Length; i += 2)
                        {
                            string name   = args[i];
                            int    hours  = int.Parse(args[i + 1]);
                            Repair repair = this.repairFactory.MakeRepair(name, hours);
                            engineer.AddRepair(repair);
                        }

                        this.soldiers.Add(engineer);
                        break;

                    case "Commando":
                        Commando commando = this.commandoFactory.MakeCommando(args);

                        for (int i = 6; i < args.Length; i += 2)
                        {
                            string name  = args[i];
                            string state = args[i + 1];

                            Mission mission = this.missionFactory.MakeMission(name, state);
                            commando.AddMission(mission);
                        }

                        this.soldiers.Add(commando);
                        break;

                    case "Spy":
                        Spy spy = this.spyFactory.MakeSpy(args);
                        this.soldiers.Add(spy);
                        break;

                    default:
                        break;
                    }
                }
                catch (Exception)
                {
                }

                line = Console.ReadLine();
            }

            foreach (var soldier in this.soldiers)
            {
                Console.WriteLine(soldier.ToString());
            }
        }
Beispiel #24
0
        public static void Main()
        {
            List <Private> privates = new List <Private>();
            Corps          corps;

            while (true)
            {
                string[] token = Console.ReadLine().Split();

                if (token[0] == "End")
                {
                    break;
                }

                if (token[0] == "Private")
                {
                    Private privatee = new Private(token[1], token[2], token[3], decimal.Parse(token[4]));
                    privates.Add(privatee);
                    Console.WriteLine(privatee.ToString());
                }
                else if (token[0] == "LieutenantGeneral")
                {
                    LieutenantGeneral lieutenantGeneral = new LieutenantGeneral(token[1], token[2], token[3], decimal.Parse(token[4]));

                    if (token.Length >= 5)
                    {
                        for (int i = 5; i < token.Length; i++)
                        {
                            string  privateId = token[i];
                            Private privatee  = privates.FirstOrDefault(x => x.Id == privateId);
                            lieutenantGeneral.Privates.Add(privatee);
                        }
                    }

                    Console.WriteLine(lieutenantGeneral.ToString());
                }
                else if (token[0] == "Engineer")
                {
                    if (Enum.TryParse(token[5], out corps))
                    {
                        Engineer engineer = new Engineer(token[1], token[2], token[3], decimal.Parse(token[4]), corps);

                        if (token.Length >= 6)
                        {
                            for (int i = 6; i < token.Length; i += 2)
                            {
                                string repairPartName  = token[i];
                                int    repairPartHours = int.Parse(token[i + 1]);

                                Repair repair = new Repair(repairPartName, repairPartHours);
                                engineer.Repairs.Add(repair);
                            }
                        }

                        Console.WriteLine(engineer.ToString());
                    }
                }
                else if (token[0] == "Commando")
                {
                    if (Enum.TryParse(token[5], out corps))
                    {
                        Commando commando = new Commando(token[1], token[2], token[3], decimal.Parse(token[4]), corps);

                        if (token.Length >= 6)
                        {
                            for (int i = 6; i < token.Length; i += 2)
                            {
                                string missionName     = token[i];
                                string missionProgress = token[i + 1];

                                if (Enum.TryParse(missionProgress, out MissionState missionState))
                                {
                                    Mission mission = new Mission(missionName, missionState);
                                    commando.Missions.Add(mission);
                                }
                            }

                            Console.WriteLine(commando.ToString());
                        }
                    }
                }
                else if (token[0] == "Spy")
                {
                    Spy spy = new Spy(token[1], token[2], token[3], int.Parse(token[4]));
                    Console.WriteLine(spy);
                }
                else
                {
                    throw new ArgumentException("Invalid Type of Soldier!");
                }
            }
        }
Beispiel #25
0
        public static void Main(string[] args)
        {
            var input = Console.ReadLine();

            var list     = new List <ISoldier>();
            var privates = new List <Private>();

            // var general = new List<LieutenantGeneral>();

            while (input != "End")
            {
                var line = input.Split();

                if (line[0] == "Private")
                {
                    list.Add(new Private(line[1], line[2], line[3], decimal.Parse(line[4])));
                    privates.Add(new Private(line[1], line[2], line[3], decimal.Parse(line[4])));
                }
                if (line[0] == "Spy")
                {
                    list.Add(new Spy(line[1], line[2], line[3], int.Parse(line[4])));
                }
                if (line[0] == "LieutenantGeneral")
                {
                    var listPrivateIds = new List <string>();
                    var leit           = new LieutenantGeneral(line[1], line[2], line[3], decimal.Parse(line[4]));

                    if (line.Length > 4)
                    {
                        for (int i = 5; i < line.Length; i++)
                        {
                            foreach (var item in privates)
                            {
                                if (item.Id == line[i])
                                {
                                    leit.Privates.Add(item);
                                }
                            }
                        }

                        leit.ListPrivateIds.AddRange(listPrivateIds);
                    }
                    list.Add(leit);
                }

                if (line[0] == "Engineer")
                {
                    var eng     = new Engineer(line[1], line[2], line[3], decimal.Parse(line[4]), line[5]);
                    var repaits = new List <Repair>();

                    for (int i = 6; i < line.Length; i = i + 2)
                    {
                        repaits.Add(new Repair(line[i], int.Parse(line[i + 1])));
                    }

                    eng.Repairs.AddRange(repaits);
                    if (line[5] == "Airforces" || line[5] == "Marines")
                    {
                        list.Add(eng);
                    }
                }

                if (line[0] == "Commando")
                {
                    var comm     = new Commando(line[1], line[2], line[3], decimal.Parse(line[4]), line[5]);
                    var currList = new List <Mission>();

                    for (int i = 6; i < line.Length; i = i + 2)
                    {
                        if (line[i + 1] == "inProgress" || line[i + 1] == "Finished")
                        {
                            currList.Add(new Mission(line[i], line[i + 1]));
                        }
                    }

                    comm.Mission.AddRange(currList);
                    if (line[5] == "Airforces" || line[5] == "Marines")
                    {
                        list.Add(comm);
                    }
                }
                input = Console.ReadLine();
            }

            foreach (var item in list)
            {
                Console.WriteLine(item);
            }
        }
Beispiel #26
0
        static void Main(string[] args)
        {
            List <Soldier> army = new List <Soldier>();
            string         command;

            while ((command = Console.ReadLine()) != "End")
            {
                string[] curCommand  = command.Split(' ', StringSplitOptions.RemoveEmptyEntries).ToArray();
                string   soldierType = curCommand[0];
                int      Id          = int.Parse(curCommand[1]);
                string   firstName   = curCommand[2];
                string   lastName    = curCommand[3];

                switch (soldierType)
                {
                case "Private":
                    Private curPrivate = new Private(Id, firstName, lastName, decimal.Parse(curCommand[4]));
                    army.Add(curPrivate);
                    break;

                case "LieutenantGeneral":
                    LieutenantGeneral curLieutenantGeneral = new LieutenantGeneral(Id, firstName, lastName, decimal.Parse(curCommand[4]));


                    for (int i = 5; i < curCommand.Length; i++)
                    {
                        Soldier searchPrivate = army.First(el => el.Id == int.Parse(curCommand[i]) && el.GetType().Name == "Private");
                        curLieutenantGeneral.Add((Private)searchPrivate);
                    }

                    army.Add(curLieutenantGeneral);
                    break;

                case "Engineer":
                    try
                    {
                        Engineer curEngineer = new Engineer(Id, firstName, lastName, decimal.Parse(curCommand[4]), curCommand[5]);
                        string[] repairs     = curCommand.Skip(6).ToArray();
                        for (int i = 0; i < repairs.Length; i += 2)
                        {
                            Repair curRepair = new Repair(repairs[i], int.Parse(repairs[i + 1]));
                            curEngineer.Add(curRepair);
                        }

                        army.Add(curEngineer);
                    }
                    catch (Exception)
                    {
                        continue;
                    }

                    break;

                case "Commando":
                    try
                    {
                        Commando curCommando = new Commando(Id, firstName, lastName, decimal.Parse(curCommand[4]), curCommand[5]);
                        string[] missions    = curCommand.Skip(6).ToArray();
                        for (int i = 0; i < missions.Length; i += 2)
                        {
                            try
                            {
                                Mission curMission = new Mission(missions[i], missions[i + 1]);
                                curCommando.Add(curMission);
                            }
                            catch (Exception)
                            {
                                continue;
                            }
                        }

                        army.Add(curCommando);
                    }
                    catch (Exception)
                    {
                        continue;
                    }

                    break;

                case "Spy":
                    Spy curSpy = new Spy(Id, firstName, lastName, int.Parse(curCommand[4]));
                    army.Add(curSpy);
                    break;
                }
            }

            foreach (var item in army)
            {
                Console.WriteLine(item);
            }
        }
Beispiel #27
0
        public static void Main()
        {
            List <Soldier> soldiers = new List <Soldier>();

            string userInput = Console.ReadLine();

            while (userInput != "End")
            {
                string[] soldierInfo = userInput.Split(" ");

                string  soldierType = soldierInfo[0];
                int     id          = int.Parse(soldierInfo[1]);
                string  firstName   = soldierInfo[2];
                string  lastName    = soldierInfo[3];
                decimal salary;
                bool    isSalary = decimal.TryParse(soldierInfo[4], out salary);

                Soldier newSoldier;

                switch (soldierType)
                {
                case "Private":
                    newSoldier = new Private(id, firstName, lastName, salary);
                    soldiers.Add(newSoldier);
                    break;

                case "LieutenantGeneral":
                    int[]          privatesToAddIds = soldierInfo.Skip(5).Select(int.Parse).ToArray();
                    List <Private> privates         = GetPrivates(privatesToAddIds, soldiers);

                    newSoldier = new LieutenantGeneral(id, firstName, lastName, salary, privates);
                    soldiers.Add(newSoldier);

                    break;

                case "Spy":
                    int codeNumber = int.Parse(soldierInfo[4]);
                    Spy newSpy     = new Spy(id, firstName, lastName, codeNumber);
                    soldiers.Add(newSpy);

                    break;

                case "Engineer":
                    string        corps   = soldierInfo[5];
                    List <Repair> repairs = GetRepairs(soldierInfo);

                    try
                    {
                        Engineer newEngineer = new Engineer(id, firstName, lastName, salary, corps, repairs);
                        soldiers.Add(newEngineer);
                    }
                    catch
                    {
                        userInput = Console.ReadLine();
                        continue;
                    }

                    break;

                case "Commando":
                    string         commandoCorps = soldierInfo[5];
                    List <Mission> missions      = GetMissions(soldierInfo);

                    Commando newCommando = new Commando(id, firstName, lastName, salary, commandoCorps, missions);
                    soldiers.Add(newCommando);

                    break;
                }

                userInput = Console.ReadLine();
            }

            Console.WriteLine($"{string.Join(Environment.NewLine, soldiers)}");
        }
Beispiel #28
0
        static void Main(string[] args)
        {
            var privates = new List <Private>();

            while (true)
            {
                string[] command = Console.ReadLine().Split();
                string   member  = command[0];
                if (member == "End")
                {
                    break;
                }
                string id        = command[1];
                string firstName = command[2];
                string lastName  = command[3];
                if (member == "Private")
                {
                    decimal salary        = decimal.Parse(command[4]);
                    var     privateMember = new Private(id, firstName, lastName, salary);
                    Console.WriteLine(privateMember);
                    privates.Add(privateMember);
                }
                else if (member == "LieutenantGeneral")
                {
                    var     privateIds = new List <string>();
                    decimal salary     = decimal.Parse(command[4]);
                    foreach (var privateId in command.Skip(4))
                    {
                        privateIds.Add(privateId);
                    }

                    var lieutenantGeneral =
                        new LieutenantGeneral(id, firstName, lastName, salary, privateIds, privates);
                    Console.WriteLine(lieutenantGeneral);
                }
                else if (member == "Engineer")
                {
                    var     repairs = new List <Repair>();
                    decimal salary  = decimal.Parse(command[4]);
                    string  corps   = command[5];
                    if (corps != "Airforces" && corps != "Marines")
                    {
                        continue;
                    }
                    for (int i = 6; i < command.Length - 1; i += 2)
                    {
                        var repair = new Repair(command[i], int.Parse(command[i + 1]));
                        repairs.Add(repair);
                    }
                    var engeener = new Engineer(id, firstName, lastName, salary, corps, repairs);
                    Console.WriteLine(engeener);
                }
                else if (member == "Commando")
                {
                    var     missions = new List <Mission>();
                    decimal salary   = decimal.Parse(command[4]);
                    string  corps    = command[5];
                    if (corps != "Airforces" && corps != "Marines")
                    {
                        continue;
                    }
                    for (int i = 6; i < command.Length - 1; i += 2)
                    {
                        string codeName = command[i];
                        string state    = command[i + 1];
                        if (state == "Finished" || state == "inProgress")
                        {
                            var mission = new Mission(codeName, state);
                            missions.Add(mission);
                        }
                    }
                    var commando = new Commando(id, firstName, lastName, salary, corps, missions);
                    Console.WriteLine(commando);
                }
                else if (member == "Spy")
                {
                    int codeNumber = int.Parse(command[4]);
                    var spy        = new Spy(id, firstName, lastName, codeNumber);
                    Console.WriteLine(spy);
                }
            }
        }
Beispiel #29
0
        static void Main(string[] args)
        {
            List <ISoldier> list     = new List <ISoldier>();
            List <Private>  privates = new List <Private>();

            string[] input = Console.ReadLine().Split();

            while (input[0] != "End")
            {
                string soldier   = input[0];
                string id        = input[1];
                string firstName = input[2];
                string lastName  = input[3];

                switch (soldier)
                {
                case "Private":
                    decimal salary = decimal.Parse(input[4]);
                    Private privat = new Private(id, firstName, lastName, salary);
                    privates.Add(privat);
                    list.Add(privat);
                    break;

                case "LieutenantGeneral":
                    decimal           salaryLieut       = decimal.Parse(input[4]);
                    LieutenantGeneral lieutenantGeneral = new LieutenantGeneral(id, firstName, lastName, salaryLieut);
                    string[]          privatesIds       = input.Skip(5).ToArray();

                    for (int i = 0; i < privatesIds.Length; i++)
                    {
                        foreach (var privateSoldier in privates)
                        {
                            if (privateSoldier.Id == privatesIds[i])
                            {
                                lieutenantGeneral.AddPrivate(privateSoldier);
                            }
                        }
                    }
                    list.Add(lieutenantGeneral);
                    break;

                case "Engineer":
                    string corps = input[5];
                    if (corps == "Airforces" || corps == "Marines")
                    {
                        decimal  salaryEngi = decimal.Parse(input[4]);
                        Engineer engineer   = new Engineer(id, firstName, lastName, salaryEngi, corps);
                        string[] repairs    = input.Skip(6).ToArray();

                        for (int i = 0; i < repairs.Length; i += 2)
                        {
                            string partName    = repairs[i];
                            int    workedHours = int.Parse(repairs[i + 1]);

                            Repair repair = new Repair(partName, workedHours);
                            engineer.AddRepair(repair);
                        }
                        list.Add(engineer);
                    }

                    break;

                case "Commando":
                    string corpsComm = input[5];
                    if (corpsComm == "Airforces" || corpsComm == "Marines")
                    {
                        decimal  salaryComm = decimal.Parse(input[4]);
                        Commando commando   = new Commando(id, firstName, lastName, salaryComm, corpsComm);
                        string[] missions   = input.Skip(6).ToArray();

                        for (int i = 0; i < missions.Length; i += 2)
                        {
                            string codeName = missions[i];
                            string state    = missions[i + 1];

                            if (state == "inProgress" || state == "Finished")
                            {
                                Mission mission = new Mission(codeName, state);
                                commando.Missions.Add(mission);
                            }
                        }
                        list.Add(commando);
                    }
                    break;

                case "Spy":
                    int codeNumber = int.Parse(input[4]);
                    Spy spy        = new Spy(id, firstName, lastName, codeNumber);
                    list.Add(spy);
                    break;
                }


                input = Console.ReadLine().Split();
            }

            foreach (var soldier in list)
            {
                Console.WriteLine(soldier);
            }
        }
Beispiel #30
0
        public static void Main()
        {
            List <ISoldier> soldiers = new List <ISoldier>();
            string          command  = Console.ReadLine();

            while (command != "End")
            {
                string[] tokens    = command.Split(" ", StringSplitOptions.RemoveEmptyEntries);
                string   id        = tokens[1];
                string   firstName = tokens[2];
                string   lastName  = tokens[3];

                if (tokens[0] == "Private")
                {
                    decimal salary  = decimal.Parse(tokens[4]);
                    Private current = new Private(firstName, lastName, id, salary);
                    soldiers.Add(current);
                }
                else if (tokens[0] == "Commando")
                {
                    decimal  salary  = decimal.Parse(tokens[4]);
                    string   corps   = tokens[5];
                    Commando current = new Commando(firstName, lastName, id, salary, corps, tokens.Skip(6).ToArray());
                    if (current.Corps != null)
                    {
                        soldiers.Add(current);
                    }
                }
                else if (tokens[0] == "LieutenantGeneral")
                {
                    decimal        salary   = decimal.Parse(tokens[4]);
                    List <Private> privates = new List <Private>();
                    for (int i = 5; i < tokens.Length; i++)
                    {
                        Private soldier = (Private)soldiers.First(s => s.Id == tokens[i]);
                        privates.Add(soldier);
                    }

                    LieutenantGeneral current = new LieutenantGeneral(firstName, lastName, id, salary, privates);
                    soldiers.Add(current);
                }
                else if (tokens[0] == "Engineer")
                {
                    decimal  salary  = decimal.Parse(tokens[4]);
                    string   corps   = tokens[5];
                    Engineer current = new Engineer(firstName, lastName, id, salary, corps, tokens.Skip(6).ToArray());
                    if (current.Corps != null)
                    {
                        soldiers.Add(current);
                    }
                }
                else if (tokens[0] == "Spy")
                {
                    int codeNumber = int.Parse(tokens[4]);
                    Spy current    = new Spy(firstName, lastName, id, codeNumber);
                    soldiers.Add(current);
                }

                command = Console.ReadLine();
            }

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