wingman007

2015_OOP_EnumNestedGeneric_Person

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