wingman007

2015_OOP_Static_Person

Apr 15th, 2015
551
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 3.02 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
  10.     {
  11.         private string name;
  12.         private 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.  
  21.         public static int Counter
  22.         {
  23.             get { return counter; }
  24.         }
  25.  
  26.         public static string Nationality
  27.         {
  28.             get { return nationality; }
  29.             set { nationality = value; }
  30.         }
  31.  
  32.         public string Name
  33.         {
  34.             get { return name; }
  35.             set { name = value; }
  36.         }
  37.  
  38.         public double Balance
  39.         {
  40.             get { return 2 * age * temp; }
  41.         }
  42.  
  43.         public string[] Freinds
  44.         {
  45.             get { return friends; }
  46.         }
  47.  
  48.  
  49.         // Automatic property
  50.         // public string Name { get; set; }
  51.  
  52.         public int Age
  53.         {
  54.             get { return age; }
  55.             set { age = value; }
  56.         }
  57.  
  58.         static Person()
  59.         {
  60.             onlyRead = 5.4;
  61.         }
  62.  
  63.         // Workign Horse
  64.         public Person(string name, int age = 0)
  65.         {
  66.             this.name = name;
  67.             this.age = age;
  68.             counter++;
  69.             // onlyRead = 2.71;
  70.         }
  71.  
  72.         public Person()
  73.             : this("Default", 0)
  74.         {
  75.            // this.name = "Default";
  76.            // this.age = 0;
  77.         }
  78.  
  79.         public Person(int age, string name, params string[] friends)
  80.             : this(name, age)
  81.         {
  82.             // this.name = name;
  83.             // this.age = age;
  84.             int i = 0;
  85.             // if (friends.Length > COUNTER)
  86.             // {
  87.             //    return;
  88.             // }
  89.             foreach (string friend in friends) {
  90.                 if (i > (COUNTER - 1)) break;
  91.                 this.friends[i] = friend;
  92.                 i++;
  93.             }
  94.  
  95.         }
  96.  
  97.         public void IntroduceYourSelf()
  98.         {
  99.             Console.WriteLine("My name is {0}! I am {1} years old! My balance is {2}. My nationality is {3}",
  100.                 name, age, Balance, nationality);
  101.            foreach(string friend in friends) {
  102.                 Console.WriteLine("My friend: {0}", friend);
  103.            }
  104.  
  105.         }
  106.  
  107.         public static double GetNationalIncome()
  108.         {
  109.             return 10000 * counter;
  110.         }
  111.         /*
  112.         public string GetName()
  113.         {
  114.             return name;
  115.         }
  116.  
  117.         public void SetName(string name)
  118.         {
  119.             this.name = name;
  120.         }
  121.  
  122.         public int GetAge()
  123.         {
  124.             return age;
  125.         }
  126.  
  127.         public void SetAge(int age)
  128.         {
  129.             this.age = age;
  130.         }
  131.         */
  132.     }
  133. }
Advertisement
Add Comment
Please, Sign In to add comment