Advertisement
wingman007

C#_OOP_Abstraction_Encapsulation_Polymorphism_Human.cs

May 20th, 2014
128
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 3.30 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.  
  21.         // public enum BrainSize {
  22.         //    small = 1350, middle = 1400, large = 1450
  23.         // };
  24.  
  25.         public static string Nationality
  26.         {
  27.             get { return nationality; }
  28.             set { nationality = value; }
  29.         }
  30.  
  31.         public string Name
  32.         {
  33.             get { return name; }
  34.             set { name = value; }
  35.         }
  36.  
  37.         public int Age
  38.         {
  39.             get { return age; }
  40.             set { age = value; }
  41.         }
  42.  
  43.         public double Balance
  44.         {
  45.             get {return name.Length * 2 * 2;}
  46.         }
  47.  
  48.         static Human() // a static constructor must be parametreess
  49.         {
  50.             onlyRead = 2.71;
  51.         }
  52.  
  53.         public Human()
  54.             : this("Default", 0)
  55.         {
  56.             // this.name = "Default";
  57.             // this.age = 0;
  58.         }
  59.  
  60.         public Human(string name, int age)
  61.         {
  62.             this.name = name;
  63.             this.age = age;
  64.             counter++;
  65.             // onlyRead = 2.71; // non static
  66.         }
  67.  
  68.         public Human(int age, string name, params string[] friends)
  69.             : this(name, age)
  70.         {
  71.             // this.name = name;
  72.             // this.age = age;
  73.             int i = 0;
  74.             foreach (string friend in friends)
  75.             {
  76.                 this.friends[i] = friend;
  77.                 i++;
  78.             }
  79.         }
  80.  
  81.         public virtual void IntroduceYourSelf()
  82.         {
  83.             Console.WriteLine("My name is {0}. I am {1} years old! My Balance is {2}. My nationality is {3}. And I am {4}", name, age, Balance, nationality, GetMyFeelings());
  84.         }
  85.  
  86.         public void IntroduceYourSelf(string verbous)
  87.         {
  88.             IntroduceYourSelf();
  89.             Console.WriteLine("I am {0}", verbous);
  90.         }
  91.  
  92.         public string GetFriendName(int index)
  93.         {
  94.             return friends[index];
  95.         }
  96.  
  97.         public static double CalculateNationlIncome()
  98.         {
  99.             return counter * 10000;
  100.         }
  101.  
  102.         public void Listen(string info)
  103.         {
  104.             this.info = info;
  105.         }
  106.  
  107.         public string Talk()
  108.         {
  109.             return info;
  110.         }
  111.  
  112.         private string GetMyFeelings()
  113.         {
  114.             if (age > 50) {
  115.                 return "sad";
  116.             }
  117.             return "happy";
  118.         }
  119.  
  120.         // public abstract void Run();
  121.  
  122.         /*
  123.         public string GetName()
  124.         {
  125.             return name;
  126.         }
  127.  
  128.         public void SetName(string name)
  129.         {
  130.             this.name = name;
  131.         }
  132.  
  133.         public int GetAge()
  134.         {
  135.             return age;
  136.         }
  137.  
  138.         public void SetAge(int age)
  139.         {
  140.             this.age = age;
  141.         }
  142.         */
  143.     }
  144. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement