Advertisement
Guest User

Untitled

a guest
May 24th, 2019
125
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.58 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5.  
  6. namespace Kadry
  7. {
  8. class Adres
  9. {
  10. private string miejscowosc;
  11. private string kod;
  12. private string nazwaUlicy;
  13. private int numerDomu;
  14. private int? numerMieszkania;
  15.  
  16. public Adres(int numerDomu, int? numerMieszkania, string nazwaUlicy, string kod, string miejscowosc)
  17. {
  18. this.numerDomu = numerDomu;
  19. this.numerMieszkania = numerMieszkania;
  20. this.nazwaUlicy = nazwaUlicy;
  21. this.kod = kod;
  22. this.miejscowosc = miejscowosc;
  23. }
  24.  
  25. public Adres(int numerDomu, int? numerMieszkania, string nazwaUlicy)
  26. : this(numerDomu, numerMieszkania, nazwaUlicy, "02-222", "Warszawa")
  27. { }
  28.  
  29. public Adres(int numerDomu, int? numerMieszkania)
  30. : this(numerDomu, numerMieszkania, "Aleje Jerozolimskie")
  31. { }
  32.  
  33. public Adres(int numerDomu)
  34. : this(numerDomu, null)
  35. { }
  36.  
  37. public Adres(Adres adres)
  38. : this(adres.numerDomu, adres.numerMieszkania, adres.nazwaUlicy, adres.kod, adres.miejscowosc)
  39. { }
  40.  
  41. public string ZwrocInformacjeAdresowe()
  42. {
  43. return numerMieszkania != null ?
  44. string.Format("{0} {1} ul. {2} {3} m. {4}",
  45. kod, miejscowosc, nazwaUlicy, numerDomu, numerMieszkania) :
  46. string.Format("{0} {1} ul. {2} {3}", kod, miejscowosc, nazwaUlicy, numerDomu);
  47. }
  48.  
  49. public string ZwrocMiejscowosc()
  50. {
  51. return miejscowosc;
  52. }
  53.  
  54. public string ZwrocNazweUlicy()
  55. {
  56. return nazwaUlicy;
  57. }
  58.  
  59. public string ZwrocKod()
  60. {
  61. return kod;
  62. }
  63.  
  64. public int ZwrocNumerDomu()
  65. {
  66. return numerDomu;
  67. }
  68.  
  69. public int? ZwrocNumerMieszkania()
  70. {
  71. return numerMieszkania;
  72. }
  73.  
  74. public void ZmienAdres()
  75. {
  76. Console.Write("Podaj nazwę miejscowości: ");
  77. miejscowosc = Console.ReadLine();
  78.  
  79. Console.Write("Podaj kod: ");
  80. kod = Console.ReadLine();
  81.  
  82. Console.Write("Podaj nazwę ulicy: ");
  83. nazwaUlicy = Console.ReadLine();
  84.  
  85. do
  86. {
  87. Console.Write("Podaj numer domu: ");
  88. }
  89. while (!int.TryParse(Console.ReadLine(), out numerDomu));
  90.  
  91. Console.Write("Czy jest numer mieszkania <t/n>: ");
  92. char c = Console.ReadKey().KeyChar;
  93. if (c == 't')
  94. {
  95. Console.WriteLine();
  96. int i;
  97. do
  98. {
  99. Console.Write("Podaj numer mieszkania: ");
  100. }
  101. while (!int.TryParse(Console.ReadLine(), out i));
  102. numerMieszkania = i;
  103. }
  104. else
  105. {
  106. numerMieszkania = null;
  107. }
  108. }
  109. }
  110.  
  111. class Osoba
  112. {
  113. private string nazwisko;
  114. private string imie;
  115. private int numerEwidencyjny;
  116. private Adres adresZamieszkania;
  117.  
  118.  
  119. public Osoba(int numerEwidencyjny, string imie, string nazwisko, string kod, string miejscowosc)
  120. {
  121. this.numerEwidencyjny = numerEwidencyjny;
  122. this.imie = imie;
  123. this.nazwisko = nazwisko;
  124. adresZamieszkania = new Adres(numerDomu, numerMieszkania, nazwaUlicy, kod, miejscowosc);
  125. }
  126. }
  127. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement