Advertisement
Guest User

Untitled

a guest
Apr 23rd, 2020
31
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.07 KB | None | 0 0
  1. W Nauczycielu jest UsunOcene(Dziennik dziennik) i UsunOcene(Uczen uczen), obie metody działają, ale nie wiem, która semantycznie jest lepsza, lub czy jest to bez znaczenia. Proszę nie zwracać uwagi na returny, z tego co już zauważyłem to nie są potrzebne, bo obiektu nigdzie nie zwracam.
  2.  
  3. public abstract class Uzytkownik
  4. {
  5. public static int NextId { get; set; }
  6. public int uzytkownikId { get; set; }
  7. public uzytkownikTypOpcje uzytkownikTyp { get; set; }
  8. public string Login { get; set; }
  9. public string Haslo { get; set; }
  10. public string Imie { get; set; }
  11. public string Nazwisko { get; set; }
  12. }
  13.  
  14. public class Nauczyciel : Uzytkownik
  15. {
  16. public Nauczyciel()
  17. {
  18. uzytkownikId = 1;
  19. uzytkownikTyp = uzytkownikTypOpcje.Nauczyciel;
  20. Login = "Nauczyciel";
  21. Haslo = "Nauczyciel";
  22. Imie = "Bogdan";
  23. Nazwisko = "Bajek";
  24. PrzedmiotTyp = "Informatyka";
  25.  
  26. }
  27.  
  28. public string PrzedmiotTyp { get; set; }
  29.  
  30. public Dziennik DodajOcene(Dziennik dziennik)
  31. {
  32.  
  33. Console.WriteLine("Jaką ocenę chcesz dodać do dziennika?");
  34. int ocena = int.Parse(Console.ReadLine());
  35. var oceny = new List<int>
  36. {
  37. ocena
  38. };
  39. if (!dziennik.OcenyZPrzedmiotow.ContainsKey(PrzedmiotTyp))
  40. {
  41. dziennik.OcenyZPrzedmiotow.Add(PrzedmiotTyp, oceny);
  42. return dziennik;
  43. }
  44. else
  45. {
  46. var tmp = dziennik.OcenyZPrzedmiotow.GetValueOrDefault(PrzedmiotTyp);
  47. oceny = tmp.Concat(oceny).ToList();
  48. dziennik.OcenyZPrzedmiotow[PrzedmiotTyp] = oceny;
  49. return dziennik;
  50. }
  51.  
  52. }
  53.  
  54. public Dziennik UsunOcene(Dziennik dziennik)
  55. {
  56. Console.WriteLine("Którą ocenę z dziennika chcesz usunąć?");
  57. int ktoraOcena = int.Parse(Console.ReadLine());
  58.  
  59. var tmp = dziennik.OcenyZPrzedmiotow.GetValueOrDefault(PrzedmiotTyp);
  60. tmp.RemoveAt(ktoraOcena - 1);
  61. dziennik.OcenyZPrzedmiotow[PrzedmiotTyp] = tmp;
  62. return dziennik;
  63. }
  64.  
  65.  
  66. public void ZobaczOcenyUczniaZPrzedmiotu(Dziennik dziennik)
  67. {
  68. var listaOcenUcznia = dziennik.ListaOcenUczniaZPrzedmiotu(PrzedmiotTyp);
  69. Console.WriteLine("Lista ocen ucznia z przedmiotu");
  70. foreach (var ocena in listaOcenUcznia)
  71. {
  72. Console.Write(ocena + ", ");
  73. }
  74. }
  75.  
  76. public void UsunOcene(Uczen uczen)
  77. {
  78. Console.WriteLine("Którą ocenę z dziennika chcesz usunąć?");
  79. int ktoraOcena = int.Parse(Console.ReadLine());
  80.  
  81. var pobraneOceny = uczen.DziennikUcznia.OcenyZPrzedmiotow.GetValueOrDefault(PrzedmiotTyp);
  82. pobraneOceny.RemoveAt(ktoraOcena - 1);
  83. uczen.DziennikUcznia.OcenyZPrzedmiotow[PrzedmiotTyp] = pobraneOceny;
  84. }
  85. }
  86.  
  87. public class Uczen : Uzytkownik
  88. {
  89. public Uczen(string login, string haslo, string imie, string nazwisko)
  90. {
  91. uzytkownikId = NextId++;
  92. uzytkownikTyp = uzytkownikTypOpcje.Uczen;
  93. Login = login;
  94. Haslo = haslo;
  95. Imie = imie;
  96. Nazwisko = nazwisko;
  97. DziennikUcznia = new Dziennik(uzytkownikId);
  98.  
  99. }
  100. public Dziennik DziennikUcznia { get; set; }
  101. }
  102.  
  103. public class Dziennik
  104. {
  105. public Dziennik(int uczenId)
  106. {
  107. this.uczenId = uczenId;
  108. OcenyZPrzedmiotow = new Dictionary<string, List<int>>();
  109. }
  110.  
  111. public int uczenId { get; set; }
  112. public Dictionary<string, List<int>> OcenyZPrzedmiotow { get; set; }
  113.  
  114. public List<int> ListaOcenUczniaZPrzedmiotu(string przedmiot)
  115. {
  116. var oceny = OcenyZPrzedmiotow.GetValueOrDefault(przedmiot);
  117. return oceny;
  118. }
  119. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement