Beispiel #1
0
    private static void EditExistingPerson(string[] personInfo, List <Person> people, Person person)
    {
        if (personInfo[1] == "company")
        {
            Person.Company company = new Person.Company(personInfo[2], personInfo[3], double.Parse(personInfo[4]));

            people[people.IndexOf(person)].company = company;
        }
        if (personInfo[1] == "pokemon")
        {
            Person.Pokemon pokemon = new Person.Pokemon(personInfo[2], personInfo[3]);

            people[people.IndexOf(person)].AddPokemon(pokemon);
        }
        if (personInfo[1] == "parents")
        {
            Person.Parent parent = new Person.Parent(personInfo[2], personInfo[3]);

            people[people.IndexOf(person)].AddParent(parent);
        }
        if (personInfo[1] == "children")
        {
            Person.Child child = new Person.Child(personInfo[2], personInfo[3]);

            people[people.IndexOf(person)].AddChild(child);
        }
        if (personInfo[1] == "car")
        {
            Person.Car car = new Person.Car(personInfo[2], int.Parse(personInfo[3]));

            people[people.IndexOf(person)].car = car;
        }
    }
Beispiel #2
0
        private static void AddPokemon(string[] inputTokens, Person person)
        {
            var name = inputTokens[2];
            var type = inputTokens[3];

            var pokemon = new Person.Pokemon(name, type);

            person.Pokemons.Add(pokemon);
        }
Beispiel #3
0
    private static void GetPersonalInfo(string[] info, Person person)
    {
        var infoType = info[1];

        switch (infoType)
        {
        case "company":
            person.TheCompany.Name       = info[2];
            person.TheCompany.Department = info[3];
            person.TheCompany.Counter    = 1;
            person.TheCompany.Salary     = decimal.Parse(info[4]);
            break;

        case "car":
            person.TheCar.Model   = info[2];
            person.TheCar.Speed   = info[3];
            person.TheCar.Counter = 1;
            break;

        case "pokemon":
            var pokemon = new Person.Pokemon();
            pokemon.Name = info[2];
            pokemon.Type = info[3];
            person.Pokemons.Add(pokemon);
            break;

        case "parents":
            var parent = new Person.Parent();
            parent.Name     = info[2];
            parent.Birthday = info[3];
            person.Parents.Add(parent);
            break;

        case "children":
            var child = new Person.Child();
            child.Name     = info[2];
            child.Birthday = info[3];
            person.Children.Add(child);
            break;

        default:
            break;
        }
    }
Beispiel #4
0
    private static void CreateNewPerson(string[] personInfo, List <Person> people, string personName)
    {
        if (personInfo[1] == "company")
        {
            Person.Company company = new Person.Company(personInfo[2], personInfo[3], double.Parse(personInfo[4]));

            Person newPerson = new Person(personName, company);

            people.Add(newPerson);
        }
        if (personInfo[1] == "pokemon")
        {
            Person.Pokemon pokemon = new Person.Pokemon(personInfo[2], personInfo[3]);

            Person newPerson = new Person(personName, pokemon);

            people.Add(newPerson);
        }
        if (personInfo[1] == "parents")
        {
            Person.Parent parent = new Person.Parent(personInfo[2], personInfo[3]);

            Person newPerson = new Person(personName, parent);

            people.Add(newPerson);
        }
        if (personInfo[1] == "children")
        {
            Person.Child child = new Person.Child(personInfo[2], personInfo[3]);

            Person newPerson = new Person(personName, child);

            people.Add(newPerson);
        }
        if (personInfo[1] == "car")
        {
            Person.Car car = new Person.Car(personInfo[2], int.Parse(personInfo[3]));

            Person newPerson = new Person(personName, car);

            people.Add(newPerson);
        }
    }
Beispiel #5
0
    static void Main()
    {
        var    persons = new Dictionary <string, Person>();
        string input;

        while ((input = Console.ReadLine()) != "End")
        {
            List <string> info = input
                                 .Split(new char[] { ' ' }, StringSplitOptions.RemoveEmptyEntries)
                                 .ToList();

            string name   = info[0];
            Person person = new Person(name);
            if (!persons.ContainsKey(name))
            {
                persons[name] = new Person(name);
            }
            if (info[1] == "company")
            {
                string  companyName = info[2];
                string  department  = info[3];
                decimal salary      = decimal.Parse(info[4]);
                persons[name].CompanyName.Name       = companyName;
                persons[name].CompanyName.Department = department;
                persons[name].CompanyName.Salary     = salary;
            }
            else if (info[1] == "pokemon")
            {
                string         pokemonName = info[2];
                string         pokemonType = info[3];
                Person.Pokemon pokemon     = new Person.Pokemon(pokemonName, pokemonType);
                persons[name].Pokemons.Add(pokemon);
            }
            else if (info[1] == "parents")
            {
                string        parentName = info[2];
                string        birthday   = info[3];
                Person.Parent parent     = new Person.Parent(parentName, birthday);
                persons[name].Parents.Add(parent);
            }
            else if (info[1] == "children")
            {
                string          childrenName = info[2];
                string          birthday     = info[3];
                Person.Children child        = new Person.Children(childrenName, birthday);
                persons[name].Childrens.Add(child);
            }
            else if (info[1] == "car")
            {
                string model = info[2];
                int    speed = int.Parse(info[3]);
                persons[name].CarModel.Model = model;
                persons[name].CarModel.Speed = speed;
            }
        }

        Person currentPerson = persons[Console.ReadLine()];

        Person.Company         currentCompany = currentPerson.CompanyName;
        Person.Car             currentCar     = currentPerson.CarModel;
        List <Person.Pokemon>  pokemons       = currentPerson.Pokemons;
        List <Person.Parent>   parents        = currentPerson.Parents;
        List <Person.Children> childrens      = currentPerson.Childrens;

        Console.WriteLine(currentPerson.Name);
        Console.WriteLine("Company:");
        if (currentCompany.Salary != 0)
        {
            Console.WriteLine($"{currentCompany.Name} {currentCompany.Department} {currentCompany.Salary:f2}");
        }
        Console.WriteLine("Car:");
        if (currentCar.Speed != 0)
        {
            Console.WriteLine($"{currentCar.Model} {currentCar.Speed}");
        }
        Console.WriteLine("Pokemon:");
        foreach (var pokemon in pokemons)
        {
            Console.WriteLine($"{pokemon.Name} {pokemon.Type}");
        }
        Console.WriteLine("Parents:");
        foreach (var parent in parents)
        {
            Console.WriteLine($"{parent.Name} {parent.Birthday}");
        }
        Console.WriteLine($"Children:");
        foreach (var child in childrens)
        {
            Console.WriteLine($"{child.Name} {child.Birthday}");
        }
    }