Advertisement
wingman007

C#_OOP_1b_Inheritance_Human.cs

Apr 24th, 2014
183
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 2.74 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 App1a
  8. {
  9.     class Human
  10.     {
  11.         private string name;
  12.         private int age;
  13.         private double temp;
  14.         private string[] friends = new string[5] { "Default", "Default", "Default", "Default", "Default" };
  15.         public static int counter = 0;
  16.         private static string nationality = "Bulgarian";
  17.         public const double PI = 3.14;
  18.         public static readonly double onlyRead = 5.6;
  19.  
  20.  
  21.         public static string Nationality
  22.         {
  23.             get { return nationality; }
  24.             set { nationality = value; }
  25.         }
  26.  
  27.         public string Name
  28.         {
  29.             get { return name; }
  30.             set { name = value; }
  31.         }
  32.  
  33.         public int Age
  34.         {
  35.             get { return age; }
  36.             set { age = value; }
  37.         }
  38.  
  39.         public double Balance
  40.         {
  41.             get { return name.Length * 2 * 2; }
  42.         }
  43.  
  44.         static Human()
  45.         {
  46.             onlyRead = 2.71;
  47.         }
  48.  
  49.         public Human()
  50.             : this("Default", 0)
  51.         {
  52.             // this.name = "Default";
  53.             // this.age = 0;
  54.         }
  55.  
  56.         public Human(string name, int age)
  57.         {
  58.             this.name = name;
  59.             this.age = age;
  60.             counter++;
  61.             // this.onlyRead = 2.71;
  62.         }
  63.  
  64.         public Human(int age, string name, params string[] friends)
  65.             : this(name, age)
  66.         {
  67.            // this.name = name;
  68.            // this.age = age;
  69.             int i = 0;
  70.             foreach (string friend in friends) {
  71.                 this.friends[i] = friend;
  72.                 i++;
  73.             }
  74.         }
  75.  
  76.         public virtual void IntroduceYourself()
  77.         {
  78.             Console.WriteLine("My name is {0}. I am {1} years old! My Balance is {2}. My nationality is {3}", name, age, Balance, nationality);
  79.         }
  80.  
  81.         public void IntroduceYourself(string verbous)
  82.         {
  83.             IntroduceYourself();
  84.             Console.WriteLine(" I have been told {0}", verbous);
  85.         }
  86.  
  87.         public string GetFriend(int index)
  88.         {
  89.             return this.friends[index];
  90.         }
  91.  
  92.         public static double CalculateNationalIncome()
  93.         {
  94.             return counter * 10000;
  95.         }
  96.  
  97.         /*
  98.         public string GetName()
  99.         {
  100.             return name;
  101.         }
  102.  
  103.         public void SetName(string name)
  104.         {
  105.             this.name = name;
  106.         }
  107.  
  108.         public int GetAge()
  109.         {
  110.             return age;
  111.         }
  112.  
  113.         public void SetAge(int age)
  114.         {
  115.             this.age = age;
  116.         }
  117.         */
  118.     }
  119. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement