예제 #1
0
        public void Run()
        {
            int numberInputs = int.Parse(Console.ReadLine());

            for (int i = 0; i < numberInputs; i++)
            {
                string[] commandArgs = Console.ReadLine().Split();

                if (commandArgs.Length == 4)
                {
                    IBuyer citizen = CitizenFactory.CreateCitizen(commandArgs);

                    population.Add(citizen);
                }
                else if (commandArgs.Length == 3)
                {
                    IBuyer rebel = RebelFactory.CreateRebel(commandArgs);

                    population.Add(rebel);
                }
            }


            while (true)
            {
                string input = Console.ReadLine();
                if (input == "End")
                {
                    break;
                }

                IBuyer buyer = population.FirstOrDefault(b => b.Name == input);

                if (buyer != null)
                {
                    buyer.BuyFood();
                }
            }

            Console.WriteLine(population.Sum(b => b.Food));
        }
예제 #2
0
        public void Run()
        {
            while (true)
            {
                string input = Console.ReadLine();
                if (input == "End")
                {
                    break;
                }

                string[] commandArgs = input.Split();
                string   individ     = commandArgs[0];

                if (individ == "Citizen")
                {
                    IBirthable citizen = CitizenFactory.CreateCitizen(commandArgs.Skip(1).ToArray());

                    population.Add(citizen);
                }
                else if (individ == "Pet")
                {
                    IBirthable pet = PetFactory.CreatePet(commandArgs.Skip(1).ToArray());

                    population.Add(pet);
                }
            }

            string yearToShow = Console.ReadLine();

            foreach (var birthable in population)
            {
                if (birthable.Birthdate.EndsWith(yearToShow))
                {
                    Console.WriteLine(birthable.Birthdate);
                }
            }
        }
예제 #3
0
        public void Run()
        {
            while (true)
            {
                string input = Console.ReadLine();
                if (input == "End")
                {
                    break;
                }

                string[] commandArgs = input.Split();

                if (commandArgs.Length == 3)
                {
                    IIdentifiable citizen = CitizenFactory.CreateCitizen(commandArgs);

                    population.Add(citizen);
                }
                else if (commandArgs.Length == 2)
                {
                    IIdentifiable robot = RobotFactory.CreateRobot(commandArgs);

                    population.Add(robot);
                }
            }

            string fakeIdEnd = Console.ReadLine();

            foreach (var identifiable in population)
            {
                if (identifiable.Id.EndsWith(fakeIdEnd))
                {
                    Console.WriteLine(identifiable.Id);
                }
            }
        }