Advertisement
wingman007

C#_OOP_Features_Human

Jun 5th, 2014
255
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 4.25 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 App1b
  8. {
  9.     // outer
  10.     class Human : Introducable
  11.     {
  12.         private string name;
  13.         private int age;
  14.         private double temp;
  15.         public static int counter = 0;
  16.         private static string nationality = "Bulgarian";
  17.         private string[] friends = new string[5] { "Default", "Default", "Default", "Default", "Default"};
  18.         public const double PI = 3.14;
  19.         public static readonly double onlyRead = 5.6;
  20.         public enum BrainSize {
  21.             Small = 1300, Normal = 1350, Large = 1400
  22.         }
  23.         private Brain brain;
  24.  
  25.         public MyDelgate onIntroduceYourSelf;
  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 int Age
  40.         {
  41.             get { return age; }
  42.             set { age = value; }
  43.         }
  44.  
  45.         static Human()
  46.         {
  47.             onlyRead = 2.71;
  48.         }
  49.  
  50.         public Human()
  51.             : this("Default", 0, Human.BrainSize.Normal)
  52.         {
  53.            // name = "Default";
  54.            // age = 0;
  55.         }
  56.  
  57.         public Human(string name, int age, Human.BrainSize size)
  58.         {
  59.             this.name = name;
  60.             this.age = age;
  61.             counter++;
  62.             // this.onlyRead = 2.7;
  63.             brain = new Brain(size);
  64.         }
  65.  
  66.         public Human(int age, string name, params string[] friends)
  67.             : this(name, age, Human.BrainSize.Normal)
  68.         {
  69.             // this.name = name;
  70.             // this.age = age;
  71.              int i = 0;
  72.             foreach (string friend in friends)
  73.             {
  74.                 this.friends[i] = friend;
  75.                 i++;
  76.             }
  77.         }
  78.  
  79.         public double Balance
  80.         {
  81.             get { return name.Length * 2 * 2; }
  82.         }
  83.  
  84.         public virtual void IntroduceYourSelf()
  85.         {
  86.             if (onIntroduceYourSelf != null) {
  87.                 onIntroduceYourSelf("Name: " + name + " Age: "+ age);
  88.             }
  89.             Console.WriteLine("My name is {0}. I am {1} years old. And My Banace is {2}. My nationality is {3}, And I am {4}. And my brain tells me I am {5}", name, age, Balance, nationality, GetMyFeelings(), brain.Think());
  90.         }
  91.  
  92.         public void IntroduceYourSelf(string verbous)
  93.         {
  94.             IntroduceYourSelf();
  95.             Console.WriteLine("I am told to be {0}", verbous);
  96.             // Console.WriteLine("My name is {0} And it is saved in a field. I am {1} years old. And My Banace is {2}. And I am told to be {3}", name, age, Balance, verbous);
  97.         }
  98.  
  99.         public string GetFriend(int index)
  100.         {
  101.             return this.friends[index];
  102.         }
  103.  
  104.         public static double CalculateNationalIncome()
  105.         {
  106.             return counter * 10000;
  107.         }
  108.  
  109.         private string GetMyFeelings()
  110.         {
  111.             if (age > 50) {
  112.                 return "sad";
  113.             }
  114.             return "happy";
  115.         }
  116.  
  117.  
  118.         // Inner
  119.         private class Brain
  120.         {
  121.             private Human.BrainSize size;
  122.  
  123.             public Human.BrainSize Size
  124.             {
  125.                 get { return size; }
  126.                 set { size = value; }
  127.             }
  128.  
  129.             public Brain()
  130.                 : this(Human.BrainSize.Normal)
  131.             { }
  132.  
  133.             public Brain(Human.BrainSize size)
  134.             {
  135.                 this.size = size;
  136.             }
  137.  
  138.             public string Think()
  139.             {
  140.                 if (size >= Human.BrainSize.Normal) {
  141.                     return "Smart";
  142.                 }
  143.                 return "Dumm";
  144.             }
  145.         }
  146. /*
  147.         public string GetName()
  148.         {
  149.             return name;
  150.         }
  151.  
  152.         public void SetName(string name)
  153.         {
  154.             this.name = name;
  155.         }
  156.  
  157.         public int GetAge()
  158.         {
  159.             return age;
  160.         }
  161.  
  162.         public void SetAge(int age)
  163.         {
  164.             this.age = age;
  165.         }
  166. */
  167.     }
  168. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement