wingman007

2015_OOP_AbstractionEncapsulationPolymorphism_Person

May 20th, 2015
488
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 3.50 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 World1
  8. {
  9.     class  Person : IIntroducable // : Object
  10.     {
  11.         protected string name;
  12.         protected int age;
  13.         private double temp = 0.23;
  14.         private const int COUNTER = 3;
  15.         private string[] friends = new String[COUNTER];
  16.         private static int counter = 0;
  17.         private static string nationality = "Bulgarian";
  18.         public const double PI = 3.14;
  19.         public static readonly double onlyRead;
  20.         private string expression;
  21.  
  22.         public static int Counter
  23.         {
  24.             get { return counter; }
  25.         }
  26.  
  27.         public static string Nationality
  28.         {
  29.             get { return nationality; }
  30.             set { nationality = value; }
  31.         }
  32.  
  33.         public string Name
  34.         {
  35.             get { return name; }
  36.             set { name = value; }
  37.         }
  38.  
  39.         public double Balance
  40.         {
  41.             get { return 2 * age * temp; }
  42.         }
  43.  
  44.         public string[] Freinds
  45.         {
  46.             get { return friends; }
  47.         }
  48.  
  49.  
  50.         // Automatic property
  51.         // public string Name { get; set; }
  52.  
  53.         public int Age
  54.         {
  55.             get { return age; }
  56.             set { age = value; }
  57.         }
  58.  
  59.         static Person()
  60.         {
  61.             onlyRead = 5.4;
  62.         }
  63.  
  64.         // Workign Horse
  65.         public Person(string name, int age = 0)
  66.         {
  67.             this.name = name;
  68.             this.age = age;
  69.             counter++;
  70.             // onlyRead = 2.71;
  71.         }
  72.  
  73.         public Person()
  74.             : this("Default", 0)
  75.         {
  76.            // this.name = "Default";
  77.            // this.age = 0;
  78.         }
  79.  
  80.         public Person(int age, string name, params string[] friends)
  81.             : this(name, age)
  82.         {
  83.             // this.name = name;
  84.             // this.age = age;
  85.             int i = 0;
  86.             // if (friends.Length > COUNTER)
  87.             // {
  88.             //    return;
  89.             // }
  90.             foreach (string friend in friends) {
  91.                 if (i > (COUNTER - 1)) break;
  92.                 this.friends[i] = friend;
  93.                 i++;
  94.             }
  95.  
  96.         }
  97.  
  98.         public virtual void IntroduceYourSelf()
  99.         {
  100.             Console.WriteLine("My name is {0}! I am {1} years old! My balance is {2}. My nationality is {3}. I am feeling {4}",
  101.                 name, age, Balance, nationality, GetMyFeelings());
  102.            foreach(string friend in friends) {
  103.                 Console.WriteLine("My friend: {0}", friend);
  104.            }
  105.  
  106.         }
  107.  
  108.         public static double GetNationalIncome()
  109.         {
  110.             return 10000 * counter;
  111.         }
  112.  
  113.         public void Listen(string expression)
  114.         {
  115.             this.expression = expression;
  116.         }
  117.  
  118.         public string Talk()
  119.         {
  120.             return this.expression;
  121.         }
  122.  
  123.         private string GetMyFeelings()
  124.         {
  125.             if (age > 50) {
  126.                 return "sad";
  127.             }
  128.             return "happy";
  129.         }
  130.  
  131.         /*
  132.         public string GetName()
  133.         {
  134.             return name;
  135.         }
  136.  
  137.         public void SetName(string name)
  138.         {
  139.             this.name = name;
  140.         }
  141.  
  142.         public int GetAge()
  143.         {
  144.             return age;
  145.         }
  146.  
  147.         public void SetAge(int age)
  148.         {
  149.             this.age = age;
  150.         }
  151.         */
  152.     }
  153. }
Advertisement
Add Comment
Please, Sign In to add comment