Exemplo n.º 1
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();
            }
        }
Exemplo n.º 2
0
        private static void CreateSpy(int id, string firstName, string lastName, int codeNumber)
        {
            Spy spy = new Spy(id, firstName, lastName, codeNumber);

            Console.WriteLine(spy.ToString());
        }
Exemplo n.º 3
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;
            }
            }
        }