Advertisement
Gillito

Untitled

Jul 23rd, 2015
227
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 4.15 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 ConsoleApplication58
  8. {
  9.     class Program
  10.     {
  11.         static void Main(string[] args)
  12.         {
  13.             string personname = "James", middlename = "Paul", lastname = "Abbot";
  14.             string street = "Monster Hunter Ave.";
  15.             string cityName = "Chicago";
  16.             int house = 14, apartment = 301;
  17.             int area = 10000;
  18.             int population = 200000;
  19.  
  20.             CityInfo city = new CityInfo(cityName, area, population);
  21.             NameInfo name = new NameInfo(personname, middlename, lastname);
  22.             AdressInfo address = new AdressInfo(city, street, house, apartment);
  23.  
  24.             Person person = new Person(name, address, city);
  25.             name.WithMiddleName = true;
  26.             person.ShowInfo();
  27.             Console.WriteLine();
  28.  
  29.             Person person2 = new Person(personname, middlename, lastname, city, cityName, area, population, street, house, apartment);
  30.             name.WithMiddleName = false;
  31.             person2.ShowInfo();
  32.         }
  33.     }
  34.  
  35.     class CityInfo
  36.     {
  37.         public CityInfo(string name, int pop, int area)
  38.         {
  39.             CityName = name;
  40.             Population = pop;
  41.             Area = area;
  42.         }
  43.         public string CityName
  44.         {
  45.             get;
  46.             set;
  47.         }
  48.  
  49.         public int Population
  50.         {
  51.             get;
  52.             set;
  53.         }
  54.  
  55.         public int Area
  56.         {
  57.             get;
  58.             set;
  59.         }
  60.     }
  61.     class NameInfo
  62.     {
  63.         public NameInfo(string fName, string mName, string lName)
  64.         {
  65.             FirstName = fName;
  66.             MiddleName = mName;
  67.             LastName = lName;
  68.         }
  69.  
  70.         public string FirstName
  71.         {
  72.             get;
  73.             set;
  74.         }
  75.         public string MiddleName
  76.         {
  77.             get;
  78.             set;
  79.         }
  80.         public string LastName
  81.         {
  82.             get;
  83.             set;
  84.         }
  85.         public bool WithMiddleName
  86.         {
  87.             get;
  88.             set;
  89.         }
  90.         public string FullName
  91.         {
  92.             get
  93.             {
  94.                 string tempname = FirstName + " " + MiddleName + " " + LastName; ;
  95.                 if (WithMiddleName == false)
  96.                     tempname = FirstName + " " + LastName;
  97.                 return tempname;
  98.             }
  99.         }
  100.     }
  101.  
  102.     class AdressInfo
  103.     {
  104.         public AdressInfo(CityInfo city, string street, int house, int apartment)
  105.         {
  106.             cityinfo = city;
  107.             Street = street;
  108.             House = house;
  109.             Apartment = apartment;
  110.         }
  111.  
  112.         public CityInfo cityinfo
  113.         {
  114.             get;
  115.             set;
  116.         }
  117.  
  118.         public string Street
  119.         {
  120.             get;
  121.             set;
  122.         }
  123.  
  124.         public int House
  125.         {
  126.             get;
  127.             set;
  128.         }
  129.  
  130.         public int Apartment
  131.         {
  132.             get;
  133.             set;
  134.         }
  135.     }
  136.  
  137.     class Person
  138.     {
  139.         public NameInfo Name
  140.         {
  141.             get;
  142.             set;
  143.         }
  144.         public AdressInfo Address
  145.         {
  146.             get;
  147.             set;
  148.         }
  149.  
  150.         public CityInfo City
  151.         {
  152.             get;
  153.             set;
  154.         }
  155.  
  156.         public Person(string fName, string mName, string lName, CityInfo cityinfo, string cityname, int pop, int area, string street, int house, int apartment)
  157.         {
  158.             Name = new NameInfo(fName, mName, lName);
  159.             Address = new AdressInfo(cityinfo, street, house, apartment);
  160.             City = new CityInfo(cityname, area, pop);
  161.         }
  162.  
  163.         public Person(NameInfo name, AdressInfo address, CityInfo city)
  164.         {
  165.             Name = name;
  166.             Address = address;
  167.             City = city;
  168.         }
  169.  
  170.         public void ShowInfo()
  171.         {
  172.             Console.WriteLine(Name.FullName);
  173.             Console.WriteLine("{0} {1} {2} {3}", City.CityName, Address.Street, Address.House, Address.Apartment);
  174.         }
  175.     }
  176. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement