예제 #1
0
    public static void Main()
    {
        List <IBirthable> list = new List <IBirthable>();

        string input;

        while ((input = Console.ReadLine()) != "End")
        {
            var data = input.Split();

            IBirthable toAdd = null;

            if (data[0] == "Citizen")
            {
                toAdd = new Citizen(data[1], int.Parse(data[2]), data[4]);
            }
            else if (data[0] == "Pet")
            {
                toAdd = new Pet(data[1], data[2]);
            }
            else
            {
                continue;
            }

            list.Add(toAdd);
        }

        string ending = Console.ReadLine();

        foreach (var birthable in list.Where(b => b.Birthdate.Split('/').Last() == ending))
        {
            Console.WriteLine(birthable.Birthdate);
        }
    }
예제 #2
0
        public void Run()
        {
            while (this.isRunning)
            {
                string[] lineArgs = Console.ReadLine().Split();

                if (lineArgs[0] == "End")
                {
                    this.isRunning = false;
                    continue;
                }

                IBirthable newMember = SocietyMemberFactory.GetMember(lineArgs);

                if (newMember != null)
                {
                    manager.AddMember(newMember);
                }
            }

            // Get all members with birth year
            string birthYear = Console.ReadLine();

            // Print result
            Console.WriteLine(manager.GetMembersWithBirthYear(birthYear).Trim());
        }
예제 #3
0
    public static void Main()
    {
        var units = new List <IBirthable>();

        string input;

        while ((input = Console.ReadLine()) != "End")
        {
            var        tokens = input.Split();
            IBirthable unit   = null;
            if (tokens[0] == "Citizen")
            {
                unit = new Citizen(tokens[1], int.Parse(tokens[2]), tokens[3],
                                   DateTime.ParseExact(tokens[4], "dd/MM/yyyy", CultureInfo.InvariantCulture));
            }
            else if (tokens[0] == "Pet")
            {
                unit = new Pet(tokens[1],
                               DateTime.ParseExact(tokens[2], "dd/MM/yyyy", CultureInfo.InvariantCulture));
            }

            if (unit != null)
            {
                units.Add(unit);
            }
        }

        var yearOfBirth = Console.ReadLine();

        foreach (var unit in units.Where(u => u.CheckBirthYear(yearOfBirth)))
        {
            Console.WriteLine(unit.Birthdate.ToString("dd/MM/yyyy", CultureInfo.InvariantCulture));
        }
    }
예제 #4
0
        public static IBirthable Create(string[] elements)
        {
            IBirthable birthable = null;

            if (elements.Length == 5)
            {
                string name      = elements[1];
                int    age       = int.Parse(elements[2]);
                string id        = elements[3];
                string birthdate = elements[4];

                birthable = new Citizen(name, age, id, birthdate);
            }
            else if (elements.Length == 3 && elements.Contains("Pet"))
            {
                string name      = elements[1];
                string birthdate = elements[2];

                birthable = new Pet(name, birthdate);
            }
            else
            {
                throw new Exception();
            }

            return(birthable);
        }
        static void Main(string[] args)
        {
            IIdentifiable identifiable = Citizen.Create();
            IBirthable    birthable    = Citizen.Create();

            Console.WriteLine(identifiable.Id);
            Console.WriteLine(birthable.Birthdate);
            Console.ReadLine();
        }
예제 #6
0
        static void Main(string[] args)
        {
            string        name         = Console.ReadLine();
            int           age          = int.Parse(Console.ReadLine());
            string        id           = Console.ReadLine();
            string        birthdate    = Console.ReadLine();
            IIdentifiable identifiable = new Citizen(name, age, id, birthdate);
            IBirthable    birthable    = (IBirthable)identifiable;

            Console.WriteLine(identifiable.Id);
            Console.WriteLine(birthable.Birthdate);
        }
예제 #7
0
        static void Main(string[] args)
        {
            List <IBirthable> birthables = new List <IBirthable>();
            string            command;

            while ((command = Console.ReadLine()) != "End")
            {
                IBirthable birthable = null;
                string[]   cmdArgs   = command.Split();
                string     type      = cmdArgs[0];
                string     name      = cmdArgs[1];
                if (type == "Citizen")
                {
                    int    age       = int.Parse(cmdArgs[2]);
                    string id        = cmdArgs[3];
                    string birthdate = cmdArgs[4];
                    birthable = new Citizen(name, age, id, birthdate);
                }
                else if (type == "Pet")
                {
                    string birthdate = cmdArgs[2];
                    birthable = new Pet(name, birthdate);
                }
                if (birthable != null)
                {
                    birthables.Add(birthable);
                }
            }
            string year = Console.ReadLine();

            if (birthables.Any())
            {
                bool hasYear = false;
                foreach (var birthable in birthables)
                {
                    string currBirthDate = birthable.BirthDate;
                    string currYear      = currBirthDate.Substring(currBirthDate.Length - 4);
                    if (currYear == year)
                    {
                        hasYear = true;
                        Console.WriteLine(currBirthDate);
                    }
                }
                if (hasYear == false)
                {
                    Console.WriteLine("<empty output>");
                }
            }
        }
예제 #8
0
        static void Main(string[] args)
        {
            var        subjects = new List <IBirthable>();
            IBirthable member   = null;

            while (true)
            {
                var command = Console.ReadLine().Split();
                if (command[0] == "End")
                {
                    break;
                }

                switch (command[0])
                {
                case "Citizen":
                    var citizenName = command[1];
                    var age         = int.Parse(command[2]);
                    var id          = command[3];
                    var birthDate   = command[4];
                    member = new Citizen(citizenName, age, id, birthDate);
                    subjects.Add(member);
                    break;

                case "Pet":
                    var petName      = command[1];
                    var petBirthDate = command[2];
                    member = new Pet(petName, petBirthDate);
                    subjects.Add(member);
                    break;
                }
            }
            var year = Console.ReadLine();

            foreach (var subj in subjects)
            {
                if (subj.Birthdate.EndsWith(year))
                {
                    Console.WriteLine(subj.Birthdate);
                }
            }
        }
예제 #9
0
        static void Main(string[] args)
        {
            List <IBirthable> citizens = new List <IBirthable>();
            string            command  = string.Empty;

            while ((command = Console.ReadLine()) != "End")
            {
                string[]   tokens  = command.Split(" ", StringSplitOptions.RemoveEmptyEntries);
                IBirthable citizen = null;
                if (tokens[0] == "Citizen")
                {
                    string name      = tokens[1];
                    int    age       = int.Parse(tokens[2]);
                    string id        = tokens[3];
                    string birthdate = tokens[4];
                    citizen = new Citizen(name, age, id, birthdate);
                    citizens.Add(citizen);
                }
                else if (tokens[0] == "Pet")
                {
                    string name      = tokens[1];
                    string birthdate = tokens[2];
                    citizen = new Pet(name, birthdate);
                    citizens.Add(citizen);
                }
            }
            string year = Console.ReadLine();

            foreach (var citizen in citizens)
            {
                if (citizen.Birthdate == null)
                {
                    continue;
                }
                else if (citizen.Birthdate.Contains(year))
                {
                    Console.WriteLine(citizen.Birthdate);
                }
            }
        }
예제 #10
0
        public void Run()
        {
            string input = Console.ReadLine();

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

                string[] args = input.Split().Skip(1).ToArray();

                if (firstWord == "Citizen")
                {
                    birthDateCelebrator = new Citizen(args[0], int.Parse(args[1]), args[2], args[3]);
                }
                else if (firstWord == "Pet")
                {
                    birthDateCelebrator = new Pet(args[0], args[1]);
                }
                else
                {
                    birthDateCelebrator = null;
                }

                if (birthDateCelebrator != null)
                {
                    celebrators.Add(birthDateCelebrator);
                }

                input = Console.ReadLine();
            }

            input = Console.ReadLine();

            List <IBirthable> filteredCelebrators = this.celebrators.Where(x => x.BirthDate.EndsWith(input)).ToList();

            if (filteredCelebrators.Count != 0)
            {
                Console.WriteLine(string.Join(Environment.NewLine, filteredCelebrators.Select(s => s.BirthDate)));
            }
        }
예제 #11
0
        public static void Main()
        {
            var input           = Console.ReadLine();
            var citizensAndPets = new List <IBirthable>();

            while (input != "End")
            {
                var        tokens       = input.Split();
                IBirthable citizenOrPet = null;

                switch (tokens[0])
                {
                case "Citizen":
                    citizenOrPet = new Citizen(tokens[1], int.Parse(tokens[2]), tokens[3], tokens[4]);
                    break;

                case "Pet":
                    citizenOrPet = new Pet(tokens[1], tokens[2]);
                    break;

                default:
                    break;
                }

                if (citizenOrPet != null)
                {
                    citizensAndPets.Add(citizenOrPet);
                }

                input = Console.ReadLine();
            }

            var year = Console.ReadLine();

            foreach (var x in citizensAndPets.Where(x => x.Birthdate.EndsWith(year)))
            {
                Console.WriteLine(x.Birthdate);
            }
        }
예제 #12
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);
                }
            }
        }
예제 #13
0
 public void AddMember(IBirthable newMember)
 {
     this.societyMembers.Add(newMember);
 }
 public static bool CorrectYear(IBirthable inhabitant, string year)
 {
     return(inhabitant.Birthdate.EndsWith(year));
 }