wingman007

2015_OOP_Features_Person

May 27th, 2015
529
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 4.62 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.         public enum BrainSize {
  22.             Small = 1300, Normal = 1350, Large = 1400
  23.         }
  24.  
  25.         private Brain brain;
  26.  
  27.         // public event MyDelegate onIntroduce;
  28.         public MyDelegate onIntroduce;
  29.  
  30.         public static int Counter
  31.         {
  32.             get { return counter; }
  33.         }
  34.  
  35.         public static string Nationality
  36.         {
  37.             get { return nationality; }
  38.             set { nationality = value; }
  39.         }
  40.  
  41.         public string Name
  42.         {
  43.             get { return name; }
  44.             set { name = value; }
  45.         }
  46.  
  47.         public double Balance
  48.         {
  49.             get { return 2 * age * temp; }
  50.         }
  51.  
  52.         public string[] Freinds
  53.         {
  54.             get { return friends; }
  55.         }
  56.  
  57.  
  58.         // Automatic property
  59.         // public string Name { get; set; }
  60.  
  61.         public int Age
  62.         {
  63.             get { return age; }
  64.             set { age = value; }
  65.         }
  66.  
  67.         static Person()
  68.         {
  69.             onlyRead = 5.4;
  70.         }
  71.  
  72.         // Workign Horse
  73.         public Person(string name, int age = 0, Person.BrainSize size = Person.BrainSize.Normal)
  74.         {
  75.             this.name = name;
  76.             this.age = age;
  77.             this.brain = new Brain(size);
  78.             counter++;
  79.             // onlyRead = 2.71;
  80.         }
  81.  
  82.         public Person()
  83.             : this("Default", 0)
  84.         {
  85.            // this.name = "Default";
  86.            // this.age = 0;
  87.         }
  88.  
  89.         public Person(int age, string name, params string[] friends)
  90.             : this(name, age)
  91.         {
  92.             // this.name = name;
  93.             // this.age = age;
  94.             int i = 0;
  95.             // if (friends.Length > COUNTER)
  96.             // {
  97.             //    return;
  98.             // }
  99.             foreach (string friend in friends) {
  100.                 if (i > (COUNTER - 1)) break;
  101.                 this.friends[i] = friend;
  102.                 i++;
  103.             }
  104.  
  105.         }
  106.  
  107.         public virtual void IntroduceYourSelf()
  108.         {
  109.             if (onIntroduce != null) {
  110.                 onIntroduce("Name = " + Name + " Age = " + Age);
  111.             }
  112.  
  113.             Console.WriteLine("My name is {0}! I am {1} years old! My balance is {2}. My nationality is {3}. I am feeling {4}. My brain tells me I am {5}",
  114.                 name, age, Balance, nationality, GetMyFeelings(), brain.Think());
  115.            foreach(string friend in friends) {
  116.                 Console.WriteLine("My friend: {0}", friend);
  117.            }
  118.         }
  119.  
  120.         public static double GetNationalIncome()
  121.         {
  122.             return 10000 * counter;
  123.         }
  124.  
  125.         public void Listen(string expression)
  126.         {
  127.             this.expression = expression;
  128.         }
  129.  
  130.         public string Talk()
  131.         {
  132.             return this.expression;
  133.         }
  134.  
  135.         private string GetMyFeelings()
  136.         {
  137.             if (age > 50) {
  138.                 return "sad";
  139.             }
  140.             return "happy";
  141.         }
  142.  
  143.         /*
  144.         public string GetName()
  145.         {
  146.             return name;
  147.         }
  148.  
  149.         public void SetName(string name)
  150.         {
  151.             this.name = name;
  152.         }
  153.  
  154.         public int GetAge()
  155.         {
  156.             return age;
  157.         }
  158.  
  159.         public void SetAge(int age)
  160.         {
  161.             this.age = age;
  162.         }
  163.         */
  164.  
  165.         private class Brain
  166.         {
  167.             private Person.BrainSize size;
  168.  
  169.             public Person.BrainSize Size
  170.             {
  171.                 get { return size; }
  172.                 set { size = value; }
  173.             }
  174.  
  175.             public Brain()
  176.                 : this(Person.BrainSize.Normal)
  177.             { }
  178.             public Brain(Person.BrainSize size)
  179.             {
  180.                 this.size = size;
  181.             }
  182.  
  183.             public string Think()
  184.             {
  185.                 if (size >= Person.BrainSize.Normal) {
  186.                     return "smart";
  187.                 }
  188.                 return "dumm";
  189.             }
  190.         }
  191.     }
  192. }
Advertisement
Add Comment
Please, Sign In to add comment