Advertisement
Guest User

Untitled

a guest
Mar 23rd, 2017
59
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.39 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. using System.Threading.Tasks;
  6.  
  7. namespace ConsoleApplication2
  8. {
  9.  
  10. class Animal
  11. {
  12.  
  13. //Class Variables
  14. public static int Count = 0;
  15.  
  16. public string name;
  17. public int age;
  18. public float happiness;
  19.  
  20. // Class Constructor
  21.  
  22. public Animal ()
  23. {
  24. name = "Spotty";
  25. age = 6;
  26. happiness = 0.5f;
  27.  
  28. Count++;
  29.  
  30. }
  31.  
  32. public Animal(string _name, int _age, float _happiness)
  33. {
  34. name = _name;
  35. age = -age;
  36. happiness = _happiness;
  37.  
  38. Count++;
  39.  
  40. }
  41. //Class Methods
  42. public void Print ()
  43. {
  44. Console.WriteLine("Name: " + name);
  45. Console.WriteLine("Age: " + age);
  46. Console.WriteLine("Happiness Level: " + happiness);
  47. }
  48. }
  49.  
  50. class Program
  51. {
  52. static void Main(string[] args)
  53. {
  54. Animal dog = new Animal ();
  55. dog.Print();
  56.  
  57. Console.WriteLine();
  58.  
  59. Animal cat = new Animal("MrBeans", 10, 0.8f);
  60. cat.Print();
  61.  
  62. Console.WriteLine();
  63. Console.WriteLine("Number of animals: " + Animal.Count );
  64.  
  65.  
  66.  
  67. Console.ReadKey();
  68. }
  69. }
  70. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement