Advertisement
wingman007

C#_OOP_Enum_NestedClass_Generics_Human

May 27th, 2014
249
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 4.23 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 App2b
  8. {
  9.     class Human : Introducable
  10.     {
  11.         protected string name;
  12.         protected int age;
  13.         private double temp;
  14.         private string[] friends = new string[5];
  15.         public static int counter = 0;
  16.         private static string nationality = "Bugarian";
  17.         public const double PI = 3.14;
  18.         public static readonly double onlyRead = 5.4;
  19.         private string info;
  20.         public enum BrainSize {
  21.             Small = 1300, Normal = 1350, Large = 1400
  22.         }
  23.         private Brain brain;
  24.  
  25.         // public enum BrainSize {
  26.         //    small = 1350, middle = 1400, large = 1450
  27.         // };
  28.  
  29.         public static string Nationality
  30.         {
  31.             get { return nationality; }
  32.             set { nationality = value; }
  33.         }
  34.  
  35.         public string Name
  36.         {
  37.             get { return name; }
  38.             set { name = value; }
  39.         }
  40.  
  41.         public int Age
  42.         {
  43.             get { return age; }
  44.             set { age = value; }
  45.         }
  46.  
  47.         public double Balance
  48.         {
  49.             get {return name.Length * 2 * 2;}
  50.         }
  51.  
  52.         static Human() // a static constructor must be parametreess
  53.         {
  54.             onlyRead = 2.71;
  55.         }
  56.  
  57.         public Human()
  58.             : this("Default", 0, Human.BrainSize.Normal)
  59.         {
  60.             // this.name = "Default";
  61.             // this.age = 0;
  62.         }
  63.  
  64.         public Human(string name, int age, Human.BrainSize size)
  65.         {
  66.             this.name = name;
  67.             this.age = age;
  68.             counter++;
  69.             // onlyRead = 2.71; // non static
  70.             brain = new Brain(size);
  71.         }
  72.  
  73.         public Human(int age, string name, params string[] friends)
  74.             : this(name, age, Human.BrainSize.Normal)
  75.         {
  76.             // this.name = name;
  77.             // this.age = age;
  78.             int i = 0;
  79.             foreach (string friend in friends)
  80.             {
  81.                 this.friends[i] = friend;
  82.                 i++;
  83.             }
  84.         }
  85.  
  86.         public virtual void IntroduceYourSelf()
  87.         {
  88.             Console.WriteLine("My name is {0}. I am {1} years old! My Balance 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());
  89.         }
  90.  
  91.         public void IntroduceYourSelf(string verbous)
  92.         {
  93.             IntroduceYourSelf();
  94.             Console.WriteLine("I am {0}", verbous);
  95.         }
  96.  
  97.         public string GetFriendName(int index)
  98.         {
  99.             return friends[index];
  100.         }
  101.  
  102.         public static double CalculateNationlIncome()
  103.         {
  104.             return counter * 10000;
  105.         }
  106.  
  107.         public void Listen(string info)
  108.         {
  109.             this.info = info;
  110.         }
  111.  
  112.         public string Talk()
  113.         {
  114.             return info;
  115.         }
  116.  
  117.         private string GetMyFeelings()
  118.         {
  119.             if (age > 50) {
  120.                 return "sad";
  121.             }
  122.             return "happy";
  123.         }
  124.  
  125.         private class Brain
  126.         {
  127.             private Human.BrainSize size;
  128.  
  129.             public Human.BrainSize Size
  130.             {
  131.                 get { return size; }
  132.                 set { size = value; }
  133.             }
  134.  
  135.             public Brain()
  136.                 : this(Human.BrainSize.Normal)
  137.             { }
  138.  
  139.             public Brain(Human.BrainSize size)
  140.             {
  141.                 this.size = size;
  142.             }
  143.  
  144.             public string Think()
  145.             {
  146.                 if (size >= Human.BrainSize.Normal) {
  147.                     return "Smart";
  148.                 }
  149.                 return "Dumm";
  150.             }
  151.         }
  152.  
  153.         // public abstract void Run();
  154.  
  155.         /*
  156.         public string GetName()
  157.         {
  158.             return name;
  159.         }
  160.  
  161.         public void SetName(string name)
  162.         {
  163.             this.name = name;
  164.         }
  165.  
  166.         public int GetAge()
  167.         {
  168.             return age;
  169.         }
  170.  
  171.         public void SetAge(int age)
  172.         {
  173.             this.age = age;
  174.         }
  175.         */
  176.     }
  177. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement