wingman007

2015_OOP_Person

Apr 8th, 2015
615
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 2.32 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.  
  17.         public string Name
  18.         {
  19.             get { return name; }
  20.             set { name = value; }
  21.         }
  22.  
  23.         public double Balance
  24.         {
  25.             get { return 2 * age * temp; }
  26.         }
  27.  
  28.         public string[] Freinds
  29.         {
  30.             get { return friends; }
  31.         }
  32.  
  33.  
  34.         // Automatic property
  35.         // public string Name { get; set; }
  36.  
  37.         public int Age
  38.         {
  39.             get { return age; }
  40.             set { age = value; }
  41.         }
  42.  
  43.         // Workign Horse
  44.         public Person(string name, int age = 0)
  45.         {
  46.             this.name = name;
  47.             this.age = age;
  48.         }
  49.  
  50.         public Person()
  51.             : this("Default", 0)
  52.         {
  53.            // this.name = "Default";
  54.            // this.age = 0;
  55.         }
  56.  
  57.         public Person(int age, string name, params string[] friends)
  58.             : this(name, age)
  59.         {
  60.             // this.name = name;
  61.             // this.age = age;
  62.             int i = 0;
  63.             // if (friends.Length > COUNTER)
  64.             // {
  65.             //    return;
  66.             // }
  67.             foreach (string friend in friends) {
  68.                 if (i > (COUNTER - 1)) break;
  69.                 this.friends[i] = friend;
  70.                 i++;
  71.             }
  72.  
  73.         }
  74.  
  75.         public void IntroduceYourSelf()
  76.         {
  77.             Console.WriteLine("My name is {0}! I am {1} years old! My balance is {2}",
  78.                 name, age, Balance);
  79.            foreach(string friend in friends) {
  80.                 Console.WriteLine("My friend: {0}", friend);
  81.            }
  82.  
  83.         }
  84.  
  85.         /*
  86.         public string GetName()
  87.         {
  88.             return name;
  89.         }
  90.  
  91.         public void SetName(string name)
  92.         {
  93.             this.name = name;
  94.         }
  95.  
  96.         public int GetAge()
  97.         {
  98.             return age;
  99.         }
  100.  
  101.         public void SetAge(int age)
  102.         {
  103.             this.age = age;
  104.         }
  105.         */
  106.     }
  107. }
Advertisement
Add Comment
Please, Sign In to add comment