Ejemplo n.º 1
0
        private static void CreatePrivate(List <Private> allPrivates, int id, string firstName, string lastName, decimal salary)
        {
            Private privateSoldier = new Private(id, firstName, lastName, salary);

            Console.WriteLine(privateSoldier.ToString());

            allPrivates.Add(privateSoldier);
        }
Ejemplo n.º 2
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!");
                }
            }
        }
Ejemplo n.º 3
0
        public static void Main()
        {
            var command  = Console.ReadLine();
            var privates = new List <Private>();

            while (command != "End")
            {
                try
                {
                    var commandParts = command.Split(new string[] { " " }, StringSplitOptions.RemoveEmptyEntries).ToList();
                    var soldier      = commandParts[0];
                    var id           = commandParts[1];
                    var firstName    = commandParts[2];
                    var lastName     = commandParts[3];

                    if (soldier == "Spy")
                    {
                        var codeNumber = int.Parse(commandParts[4]);

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

                        Console.WriteLine(spy.ToString());

                        command = Console.ReadLine();
                        continue;
                    }

                    var salary = decimal.Parse(commandParts[4]);

                    if (soldier == "Private")
                    {
                        var privateSoldier = new Private(id, firstName, lastName, salary);
                        privates.Add(privateSoldier);

                        Console.WriteLine(privateSoldier.ToString());
                    }
                    else if (soldier == "LieutenantGeneral")
                    {
                        var lieutenantGeneral = CreateLieutenant(id, firstName, lastName, salary, privates, commandParts);

                        Console.WriteLine(lieutenantGeneral.ToString());
                    }
                    else if (soldier == "Engineer")
                    {
                        var corps = commandParts[5];

                        var engineer = CreateEngineer(id, firstName, lastName, salary, corps, commandParts);

                        Console.WriteLine(engineer.ToString());
                    }
                    else if (soldier == "Commando")
                    {
                        var corps = commandParts[5];

                        var commando = CreateCommando(id, firstName, lastName, salary, corps, commandParts);

                        Console.WriteLine(commando.ToString());
                    }
                }
                catch
                {
                }

                command = Console.ReadLine();
            }
        }
Ejemplo n.º 4
0
        private static void GetAndPrintCurArmyMan(List <Private> privates, string[] tokens)
        {
            switch (tokens[0])
            {
            case "Private":
            {
                Private privatex = new Private
                                       (int.Parse(tokens[1]), tokens[2], tokens[3], decimal.Parse(tokens[4]));
                privates.Add(privatex);

                Console.WriteLine(privatex.ToString());

                break;
            }

            case "LieutenantGeneral":
            {
                LieutenantGeneral general = new LieutenantGeneral
                                                (int.Parse(tokens[1]), tokens[2], tokens[3], decimal.Parse(tokens[4]));

                for (int i = 5; i < tokens.Length; i++)
                {
                    var privateToAdd = privates.Find(x => x.Id == int.Parse(tokens[i]));
                    general.Privates.Add(privateToAdd);
                }

                Console.WriteLine(general.ToString());
                break;
            }

            case "Engineer":
            {
                try
                {
                    Engineer engineer = new Engineer
                                            (int.Parse(tokens[1]), tokens[2], tokens[3], decimal.Parse(tokens[4]), tokens[5]);

                    GetRepairs(tokens, engineer);

                    Console.WriteLine(engineer.ToString());
                    break;
                }
                catch (ArgumentException)
                {
                    break;
                }
            }

            case "Commando":
            {
                try
                {
                    Commando commando = new Commando
                                            (int.Parse(tokens[1]), tokens[2], tokens[3], decimal.Parse(tokens[4]), tokens[5]);

                    GetMissions(tokens, commando);

                    Console.WriteLine(commando.ToString());
                    break;
                }
                catch (ArgumentException)
                {
                    break;
                }
            }

            case "Spy":
            {
                Spy spy = new Spy
                              (int.Parse(tokens[1]), tokens[2], tokens[3], int.Parse(tokens[4]));

                Console.WriteLine(spy.ToString());

                break;
            }
            }
        }