Pp9

Untitled

Pp9
Apr 16th, 2018
71
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 5.73 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. using kartoteka.impl;
  8.  
  9. namespace kartoteka
  10. {
  11. class Osoba
  12. {
  13. string imie = "Gall";
  14. string nazwisko = "Anonim";
  15.  
  16. public Osoba(string im, string na)
  17. {
  18. imie = im;
  19. nazwisko = na;
  20. }
  21.  
  22. public Osoba() { }
  23.  
  24. public string getImie()
  25. {
  26. return this.imie;
  27. }
  28. public string getNazwisko()
  29. {
  30. return this.nazwisko;
  31. }
  32. }
  33.  
  34. namespace mockup
  35. {
  36. class Kartoteka
  37. {
  38. List<Osoba> lista = new List<Osoba>();
  39.  
  40. //dodaje osoby do listy
  41. public static void dodaj(kartoteka.Osoba o)
  42. {
  43.  
  44. }
  45.  
  46. //usuwa osoby z listy
  47. public static void usun(kartoteka.Osoba o)
  48. {
  49.  
  50. }
  51.  
  52. //pobiera rozmiar kartoteki
  53. public static int rozmiar()
  54. {
  55. return 1;
  56. }
  57.  
  58. //zwraca prawde jezeli osoba jest w liscie
  59. public static bool czyZawiera(Osoba o)
  60. {
  61. return true;
  62. }
  63.  
  64. //pobiera n-ta osobe
  65. public static Osoba pobierz(int n)
  66. {
  67. Console.WriteLine("Gall Anonim");
  68. return new Osoba();
  69. }
  70. }
  71.  
  72. }
  73.  
  74. namespace impl
  75. {
  76. class Kartoteka
  77. {
  78. public static List<Osoba> lista = new List<Osoba>();
  79.  
  80. //dodaje osoby do listy
  81. public static void dodaj(Osoba o)
  82. {
  83. lista.Add(o);
  84. }
  85.  
  86. //usuwa osoby z listy
  87. public static void usun(Osoba o)
  88. {
  89. lista.Remove(o);
  90. }
  91.  
  92. //pobiera rozmiar kartoteki
  93. public static int rozmiar()
  94. {
  95. return lista.Count;
  96. }
  97.  
  98. //zwraca prawde jezeli osoba jest w liscie
  99. public static bool czyZawiera(Osoba o)
  100. {
  101. return lista.Contains(o);
  102. }
  103.  
  104. //pobiera n-ta osobe
  105. public static Osoba pobierz(int n)
  106. {
  107. Console.WriteLine(lista[n - 1].getImie() + " " + lista[n - 1].getNazwisko());
  108. return new Osoba(lista[n - 1].getImie(), lista[n - 1].getNazwisko());
  109. }
  110. }
  111.  
  112. }
  113.  
  114. }
  115.  
  116.  
  117. namespace Z5
  118. {
  119.  
  120. class Program
  121. {
  122. static void Main(string[] args)
  123. {
  124. int wybor=10;
  125. System.Console.WriteLine("MENU:");
  126. System.Console.WriteLine("0. Wyjście!");
  127. System.Console.WriteLine("1. Dodaj osobę.");
  128. System.Console.WriteLine("2. Usuń osobę.");
  129. System.Console.WriteLine("3. Sprawdź rozmiar kartoteki.");
  130. System.Console.WriteLine("4. Sprawdź czy zawiera osobę.");
  131. System.Console.WriteLine("5. Pobierz osobę.");
  132. System.Console.WriteLine("");
  133.  
  134. while (wybor!=0) {
  135. System.Console.WriteLine("Którą opcję wybierasz?(0-5)");
  136.  
  137. wybor = int.Parse(Console.ReadLine());
  138.  
  139. switch (wybor)
  140. {
  141. case 0:
  142. break;
  143. case 1:
  144. Console.WriteLine("Podaj imię i nazwisko osoby, którą chcesz dodać (oddziel je enterem): ");
  145. string ii = Console.ReadLine();
  146. string nn = Console.ReadLine();
  147. kartoteka.Osoba t = new kartoteka.Osoba(ii, nn);
  148. Kartoteka.dodaj(t);
  149. break;
  150. case 2:
  151. Console.WriteLine("Podaj imię i nazwisko osoby, którą chcesz usunąć (oddziel je enterem): ");
  152. string _imie = Console.ReadLine();
  153. string _nazwisko = Console.ReadLine();
  154. kartoteka.Osoba y = new kartoteka.Osoba(_imie, _nazwisko);
  155. Kartoteka.usun(y);
  156. break;
  157. case 3:
  158. int nr = Kartoteka.rozmiar();
  159. Console.WriteLine("Rozmiar kartoteki: "+nr);
  160. break;
  161. case 4:
  162. Console.WriteLine("Podaj imię i nazwisko osoby, którą chcesz sprawdzić (oddziel je enterem): ");
  163. string name = Console.ReadLine();
  164. string surname = Console.ReadLine();
  165. kartoteka.Osoba u = new kartoteka.Osoba(name, surname);
  166. if (Kartoteka.czyZawiera(u)) Console.WriteLine("Kartoteka zawiera tę osobę!");
  167. else Console.WriteLine("Kartoteka nie zawiera tej osoby!");
  168.  
  169. break;
  170. case 5:
  171. Console.WriteLine("Ktorą z kolei osobę chcesz wypisać?");
  172. int kolej = int.Parse(Console.ReadLine());
  173. int max = Kartoteka.rozmiar();
  174. if (kolej <= max)
  175. {
  176. Kartoteka.pobierz(kolej);
  177. }
  178. else Console.WriteLine("Nie ma tyle osób w kartotece!");
  179. break;
  180. default:
  181. System.Console.WriteLine("Błąd danych!");
  182. break;
  183.  
  184.  
  185. }
  186. }
  187. System.Console.WriteLine("Koniec programu! :(");
  188. }
  189. }
  190. }
Advertisement
Add Comment
Please, Sign In to add comment