Advertisement
Gillito

Untitled

Jul 22nd, 2015
212
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 3.25 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 city = "Chicago", street = "Monster Hunter Ave.";
  15.             int house = 14, apartment = 301;
  16.  
  17.             NameInfo name = new NameInfo(personname, middlename, lastname);
  18.             AdressInfo address = new AdressInfo(city, street, house, apartment);
  19.  
  20.             Person person = new Person(name, address);
  21.             name.WithMiddleName = true;
  22.             person.ShowInfo();
  23.             Console.WriteLine();
  24.  
  25.             Person person2 = new Person(personname, middlename, lastname, city, street, house, apartment);
  26.             name.WithMiddleName = false;
  27.             person2.ShowInfo();
  28.         }
  29.     }
  30.  
  31.     class NameInfo
  32.     {
  33.         public NameInfo(string fName, string mName, string lName)
  34.         {
  35.             FirstName = fName;
  36.             MiddleName = mName;
  37.             LastName = lName;
  38.         }
  39.  
  40.         public string FirstName
  41.         {
  42.             get;
  43.             set;
  44.         }
  45.         public string MiddleName
  46.         {
  47.             get;
  48.             set;
  49.         }
  50.         public string LastName
  51.         {
  52.             get;
  53.             set;
  54.         }
  55.         public bool WithMiddleName
  56.         {
  57.             get;
  58.             set;
  59.         }
  60.         public string FullName
  61.         {
  62.             get
  63.             {
  64.                 string tempname = FirstName + " " + MiddleName + " " + LastName; ;
  65.                 if (WithMiddleName == false)
  66.                     tempname = FirstName + " " + LastName;
  67.                 return tempname;
  68.             }
  69.         }
  70.     }
  71.  
  72.     class AdressInfo
  73.     {
  74.         public AdressInfo(string city, string street, int house, int apartment)
  75.         {
  76.             City = city;
  77.             Street = street;
  78.             House = house;
  79.             Apartment = apartment;
  80.         }
  81.  
  82.         public string City
  83.         {
  84.             get;
  85.             set;
  86.         }
  87.         public string Street
  88.         {
  89.             get;
  90.             set;
  91.         }
  92.         public int House
  93.         {
  94.             get;
  95.             set;
  96.         }
  97.         public int Apartment
  98.         {
  99.             get;
  100.             set;
  101.         }
  102.     }
  103.  
  104.     class Person
  105.     {
  106.         public NameInfo Name
  107.         {
  108.             get;
  109.             set;
  110.         }
  111.         public AdressInfo Address
  112.         {
  113.             get;
  114.             set;
  115.         }
  116.  
  117.         public Person(string fName, string mName, string lName, string city, string street, int house, int apartment)
  118.         {
  119.             Name = new NameInfo(fName, mName, lName);
  120.             Address = new AdressInfo(city, street, house, apartment);
  121.         }
  122.  
  123.         public Person(NameInfo name, AdressInfo address)
  124.         {
  125.             Name = name;
  126.             Address = address;
  127.         }
  128.  
  129.         public void ShowInfo()
  130.         {
  131.             Console.WriteLine(Name.FullName);
  132.             Console.WriteLine("{0} {1} {2} {3}", Address.City, Address.Street, Address.House, Address.Apartment);
  133.         }
  134.     }
  135. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement