Advertisement
wingman007

2018_OOP_Person_Static_Elements

Apr 12th, 2018
314
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 2.19 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 WorldMI
  8. {
  9.   class Person
  10.   {
  11.     private string name;
  12.     private int age;
  13.     private decimal balance;
  14.     private string[] friends;
  15.     private static int counter = 0;
  16.     public const double PI = 3.14 * 2;
  17.     public static readonly double only4Read = 2.71;
  18.  
  19.     public static int Counter
  20.     {
  21.       get { return counter; }
  22.     }
  23.  
  24.  
  25.     public string this[int i]
  26.     {
  27.       get { return friends[i]; }
  28.       set { friends[i] = 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 {
  41.         if (value > 120 || value < 0) value = 0;
  42.         age = value;
  43.       }
  44.     }
  45.  
  46.     static Person()
  47.     {
  48.       only4Read = 546;
  49.     }
  50.     public Person()
  51.       :this("Default", 0)
  52.     {
  53.       //this.name = "Default";
  54.       //this.age = 0;
  55.     }
  56.  
  57.     // working horse
  58.     public Person(string name, int age, decimal balance = 0.0M, params string[] friends)
  59.     {
  60.       this.name = name;
  61.       this.age = age;
  62.       this.balance = balance;
  63.       this.friends = friends;
  64.       counter++;
  65.       // only4Read = age * 111;
  66.     }
  67.  
  68.     public Person(int age, string name)
  69.       :this(name, age)
  70.     {
  71.       //this.name = name;
  72.       //this.age = age;
  73.     }
  74.  
  75.     //public string GetName()
  76.     //{
  77.     //  return name;
  78.     //}
  79.  
  80.     //public void SetName(string name)
  81.     //{
  82.     //  this.name = name;
  83.     //}
  84.  
  85.     //public int GetAge()
  86.     //{
  87.     //  return age;
  88.     //}
  89.  
  90.     //public void SetAge(int age)
  91.     //{
  92.     //  if(age > 120 || age < 0)
  93.     //  {
  94.     //    age = 0;
  95.     //  }
  96.     //  this.age = age;
  97.     //}
  98.  
  99.     public void IntroduceYourSelf()
  100.     {
  101.       Console.WriteLine("My name is {0}. I am {1} years old! Last year I was {2} years old!", name, age, GetLastYearAge(age));
  102.       CalculateNationalIncome();
  103.     }
  104.  
  105.     private int GetLastYearAge(int age)
  106.     {
  107.       return age - 1;
  108.     }
  109.  
  110.     public static double CalculateNationalIncome()
  111.     {
  112.       return counter * 1000;
  113.     }
  114.  
  115.   }
  116. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement