Advertisement
Guest User

Untitled

a guest
May 22nd, 2019
93
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.34 KB | None | 0 0
  1. Exercise4_1
  2.  
  3. class Program
  4. {
  5. static void Main(string[] args)
  6. {
  7. //Persons
  8. Person BlackCoffee = new Person("Black Coffee", 38);
  9. Person Fjaak = new Person("Fjaak", 25);
  10. //Animals
  11. Animal Amelie = new Animal("Amelie", "Mantis");
  12. Animal Kobosil = new Animal("Kobosil", "Devil");
  13. Animal SethTroxler = new Animal("Seth Troxler", "Ferret");
  14.  
  15. //BlackCoffee
  16. BlackCoffee.Pets.Add(Amelie);
  17. BlackCoffee.print();
  18. Console.WriteLine();
  19. Console.ReadKey();
  20.  
  21. //Fjaak
  22. Fjaak.Pets.Add(Kobosil);
  23. Fjaak.print();
  24. Console.WriteLine();
  25. Fjaak.print();
  26.  
  27. Console.WriteLine(Fjaak.Pets.Count);
  28. Console.ReadKey();
  29. }
  30. }
  31. class Person
  32. {
  33. private string name;
  34. private int age;
  35. private List<Animal> pets = new List<Animal>();
  36.  
  37. public List<Animal> Pets
  38. {
  39. set { this.pets = value; }
  40. get { return this.pets; }
  41. }
  42.  
  43. public Person(string _name, int _age)
  44. {
  45. name = _name;
  46. age = _age;
  47. }
  48. public void print()
  49. {
  50. Console.WriteLine("Name: {0} Age: {1} ", name, age);
  51. foreach(Animal a in pets)
  52. {
  53. a.print();
  54. }
  55. }
  56. public void celebrateBirthday()
  57. {
  58. age++;
  59. Console.WriteLine("Happy Birthday {0}",name);
  60. Console.WriteLine("You reached Level {0} ",age);
  61. }
  62. public string Name
  63. {
  64. get{ return this.name; }
  65. }
  66. public int Age
  67. {
  68. get { return this.age; }
  69. }
  70. }
  71. class Animal
  72. {
  73. private string name;
  74. private string species;
  75. public Animal(string _name, string _species)
  76. {
  77. name = _name;
  78. species = _species;
  79. }
  80. public void print()
  81. {
  82. Console.WriteLine("Pet: {0} the {1} ", name, species);
  83. }
  84. public string Name
  85. {
  86. get { return this.name; }
  87. }
  88. public string Species
  89. {
  90. get { return this.species; }
  91. }
  92. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement