Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- Exercise4_1
- class Program
- {
- static void Main(string[] args)
- {
- //Persons
- Person BlackCoffee = new Person("Black Coffee", 38);
- Person Fjaak = new Person("Fjaak", 25);
- //Animals
- Animal Amelie = new Animal("Amelie", "Mantis");
- Animal Kobosil = new Animal("Kobosil", "Devil");
- Animal SethTroxler = new Animal("Seth Troxler", "Ferret");
- //BlackCoffee
- BlackCoffee.Pets.Add(Amelie);
- BlackCoffee.print();
- Console.WriteLine();
- Console.ReadKey();
- //Fjaak
- Fjaak.Pets.Add(Kobosil);
- Fjaak.print();
- Console.WriteLine();
- Fjaak.print();
- Console.WriteLine(Fjaak.Pets.Count);
- Console.ReadKey();
- }
- }
- class Person
- {
- private string name;
- private int age;
- private List<Animal> pets = new List<Animal>();
- public List<Animal> Pets
- {
- set { this.pets = value; }
- get { return this.pets; }
- }
- public Person(string _name, int _age)
- {
- name = _name;
- age = _age;
- }
- public void print()
- {
- Console.WriteLine("Name: {0} Age: {1} ", name, age);
- foreach(Animal a in pets)
- {
- a.print();
- }
- }
- public void celebrateBirthday()
- {
- age++;
- Console.WriteLine("Happy Birthday {0}",name);
- Console.WriteLine("You reached Level {0} ",age);
- }
- public string Name
- {
- get{ return this.name; }
- }
- public int Age
- {
- get { return this.age; }
- }
- }
- class Animal
- {
- private string name;
- private string species;
- public Animal(string _name, string _species)
- {
- name = _name;
- species = _species;
- }
- public void print()
- {
- Console.WriteLine("Pet: {0} the {1} ", name, species);
- }
- public string Name
- {
- get { return this.name; }
- }
- public string Species
- {
- get { return this.species; }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement