Advertisement
pabblo097

PO LAB5

Apr 4th, 2020
206
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 17.45 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3.  
  4. namespace Lab5
  5. {
  6.     interface IInfo
  7.     {
  8.         public void Wypiszinfo();
  9.     }
  10.  
  11.     abstract class Osoba: IInfo
  12.     {
  13.         protected string imie, nazwisko, dataUro;
  14.  
  15.         public Osoba()
  16.         {
  17.             imie = "";
  18.             nazwisko = "";
  19.         }
  20.  
  21.         public Osoba(string imie, string nazwisko, string dataUro)
  22.         {
  23.             this.imie = imie;
  24.             this.nazwisko = nazwisko;
  25.             this.dataUro = dataUro;
  26.         }
  27.  
  28.         public string Imie
  29.         {
  30.             get {return imie;}
  31.             set {imie = value;}
  32.         }
  33.  
  34.         public string Nazwisko
  35.         {
  36.             get {return nazwisko;}
  37.             set {nazwisko = value;}
  38.         }
  39.  
  40.         public virtual void Wypiszinfo()
  41.         {
  42.             Console.WriteLine("Imie: " + imie);
  43.             Console.WriteLine("Nazwisko: " + nazwisko);
  44.             Console.WriteLine("Data urodzenia: " + dataUro);
  45.         }
  46.     }
  47.  
  48.     class Student: Osoba
  49.     {
  50.         private string kierunek, specjalnosc;
  51.         private int rok, grupa, nrIndeksu;
  52.         private List<Ocenakoncowa> ocenyKoncowe = new List<Ocenakoncowa>();
  53.  
  54.         public Student():base()
  55.         {
  56.             kierunek = "";
  57.             specjalnosc = "";
  58.             rok = 0;
  59.             grupa = 0;
  60.             nrIndeksu = 0;
  61.         }
  62.  
  63.         public Student(string imie, string nazwisko, string dataUro, string kierunek, string specjalnosc, int rok, int grupa, int nrIndeksu):base(imie, nazwisko, dataUro)
  64.         {
  65.             this.kierunek = kierunek;
  66.             this.specjalnosc = specjalnosc;
  67.             this.rok = rok;
  68.             this.grupa = grupa;
  69.             this.nrIndeksu = nrIndeksu;
  70.         }
  71.  
  72.         public int NrIndeksu
  73.         {
  74.             get {return nrIndeksu;}
  75.             set {nrIndeksu = value;}
  76.         }
  77.  
  78.         public override void Wypiszinfo()
  79.         {
  80.             base.Wypiszinfo();
  81.             Console.WriteLine("Kierunek: " + kierunek);
  82.             Console.WriteLine("Specjalnosc: " + specjalnosc);
  83.             Console.WriteLine("Rok: " + rok);
  84.             Console.WriteLine("Grupa: " + grupa);
  85.             Console.WriteLine("Numer indeksu: " + nrIndeksu);
  86.             Console.WriteLine("");
  87.         }
  88.  
  89.         public void InfoOceny()
  90.         {
  91.             Console.WriteLine("Oceny:");
  92.             foreach (Ocenakoncowa ocena in ocenyKoncowe)
  93.             {
  94.                 ocena.Wypiszinfo();
  95.                 Console.WriteLine("");
  96.             }
  97.         }
  98.  
  99.         public void DodajOcene(Przedmiot przedmiot, double wartoscOceny, string data)
  100.         {
  101.             Ocenakoncowa tmp = new Ocenakoncowa(wartoscOceny, data, przedmiot);
  102.             ocenyKoncowe.Add(tmp);
  103.         }
  104.     }
  105.  
  106.     class Przedmiot: IInfo
  107.     {
  108.         private string nazwa, kierunek, specjalnosc;
  109.         private int semestr, ilGodz;
  110.  
  111.         public Przedmiot()
  112.         {
  113.             nazwa = "";
  114.             kierunek = "";
  115.             specjalnosc = "";
  116.             semestr = 0;
  117.             ilGodz = 0;
  118.         }
  119.  
  120.         public Przedmiot(string nazwa, string kierunek, string specjalnosc, int semestr, int ilGodz)
  121.         {
  122.             this.nazwa = nazwa;
  123.             this.kierunek = kierunek;
  124.             this.specjalnosc = specjalnosc;
  125.             this.semestr = semestr;
  126.             this.ilGodz = ilGodz;
  127.         }
  128.  
  129.         public string Nazwa
  130.         {
  131.             get {return nazwa;}
  132.             set {nazwa = value;}
  133.         }
  134.  
  135.         public void Wypiszinfo()
  136.         {
  137.             Console.WriteLine("Nazwa: " + nazwa);
  138.             Console.WriteLine("Kierunek: " + kierunek);
  139.             Console.WriteLine("Specjalnosc: " + specjalnosc);
  140.             Console.WriteLine("Semestr: " + semestr);
  141.             Console.WriteLine("Ilosc godzin: " + ilGodz);
  142.             Console.WriteLine("");
  143.         }
  144.     }
  145.  
  146.     class Ocenakoncowa:IInfo
  147.     {
  148.         private double wartosc;
  149.         private string data;
  150.         private Przedmiot przedmiot;
  151.  
  152.         public Ocenakoncowa()
  153.         {
  154.             wartosc = 0.0;
  155.             data = "";
  156.         }
  157.  
  158.         public Ocenakoncowa(double wartosc, string data, Przedmiot przedmiot)
  159.         {
  160.             this.wartosc = wartosc;
  161.             this.data = data;
  162.             this.przedmiot = przedmiot;
  163.         }
  164.  
  165.         public void Wypiszinfo()
  166.         {
  167.             Console.WriteLine("Wartosc: " + wartosc);
  168.             Console.WriteLine("Data: " + data);
  169.             Console.WriteLine("Przedmiot: " + przedmiot.Nazwa);
  170.             Console.WriteLine("");
  171.         }
  172.     }
  173.  
  174.     class Wykladowca: Osoba
  175.     {
  176.         private string tytulNaukowy, stanowisko;
  177.  
  178.         public Wykladowca():base()
  179.         {
  180.             tytulNaukowy = "";
  181.             stanowisko = "";
  182.         }
  183.  
  184.         public Wykladowca(string imie, string nazwisko, string dataUro, string tytulNaukowy, string stanowisko):
  185.             base(imie, nazwisko, dataUro)
  186.         {
  187.             this.tytulNaukowy = tytulNaukowy;
  188.             this.stanowisko = stanowisko;
  189.         }
  190.  
  191.         public override void Wypiszinfo()
  192.         {
  193.             base.Wypiszinfo();
  194.             Console.WriteLine("Tytul naukowy: " + tytulNaukowy);
  195.             Console.WriteLine("Stanowisko: " + stanowisko);
  196.             Console.WriteLine("");
  197.         }
  198.     }
  199.  
  200.     class Jednostka: IInfo
  201.     {
  202.         private string nazwa, adres;
  203.         private List<Wykladowca> wykladowcy = new List<Wykladowca>();
  204.  
  205.         public Jednostka()
  206.         {
  207.             nazwa = "";
  208.             adres = "";
  209.         }
  210.  
  211.         public Jednostka(string nazwa, string adres)
  212.         {
  213.             this.nazwa = nazwa;
  214.             this.adres = adres;
  215.         }
  216.  
  217.         public string Nazwa
  218.         {
  219.             get {return nazwa;}
  220.             set {nazwa = value;}
  221.         }
  222.  
  223.         public List<Wykladowca> Wykladowcy
  224.         {
  225.             get {return wykladowcy;}
  226.         }
  227.  
  228.         public void DodajWykladowce(Wykladowca wykladowca)
  229.         {
  230.             wykladowcy.Add(wykladowca);
  231.         }
  232.  
  233.         public bool UsunWykladowce(Wykladowca _wykladowca)
  234.         {
  235.             bool check = false;
  236.             Wykladowca tmpWykladowca = null;
  237.             foreach (Wykladowca wykladowca in wykladowcy)
  238.             {
  239.                 if(_wykladowca == wykladowca)
  240.                 {
  241.                     tmpWykladowca = wykladowca;
  242.                     check = true;
  243.                 }
  244.             }
  245.  
  246.             if(check)
  247.             {
  248.                 wykladowcy.Remove(tmpWykladowca);
  249.                 Console.WriteLine("Pomyslnie usunieto wykladowce!");
  250.                 return true;
  251.             }
  252.             else
  253.             {
  254.                 Console.WriteLine("Brak wykladowcy do usuniecia!");
  255.                 return false;
  256.             }
  257.         }
  258.  
  259.         public bool UsunWykladowce(string imie, string nazwisko)
  260.         {
  261.             bool check = false;
  262.             Wykladowca tmpWykladowca = null;
  263.             foreach (Wykladowca wykladowca in wykladowcy)
  264.             {
  265.                 if(wykladowca.Imie == imie && wykladowca.Nazwisko == nazwisko)
  266.                 {
  267.                     tmpWykladowca = wykladowca;
  268.                     check = true;
  269.                 }
  270.             }
  271.  
  272.             if(check)
  273.             {
  274.                 wykladowcy.Remove(tmpWykladowca);
  275.                 Console.WriteLine("Usunieto wykladowce!");
  276.                 return true;
  277.             }
  278.             else
  279.             {
  280.                 Console.WriteLine("Brak wykladowcy do usuniecia!");
  281.                 return false;
  282.             }
  283.         }
  284.  
  285.         public void InfoWykladowcy()
  286.         {
  287.             Console.WriteLine("Wykladowcy:");
  288.             foreach (Wykladowca wykladowca in wykladowcy)
  289.             {
  290.                 wykladowca.Wypiszinfo();
  291.             }
  292.         }
  293.  
  294.         public void Wypiszinfo()
  295.         {
  296.             Console.WriteLine("Nazwa jednostki: " + nazwa);
  297.             Console.WriteLine("Adres jednostki: " + adres);
  298.             Console.WriteLine("");
  299.         }
  300.     }
  301.  
  302.     class Wydzial
  303.     {
  304.         private List<Przedmiot> przedmioty;
  305.         private List<Student> studenci;
  306.         private List<Jednostka> jednostki;
  307.  
  308.         public Wydzial()
  309.         {
  310.             przedmioty = new List<Przedmiot>();
  311.             studenci = new List<Student>();
  312.             jednostki = new List<Jednostka>();
  313.         }
  314.  
  315.         public List<Jednostka> Jednostki
  316.         {
  317.             get {return jednostki;}
  318.         }
  319.  
  320.         public void DodajJednostke(string nazwaJednostki, string adresJednostki)
  321.         {
  322.             Jednostka tmp = new Jednostka(nazwaJednostki, adresJednostki);
  323.             jednostki.Add(tmp);
  324.         }
  325.  
  326.         public void DodajPrzedmiot(Przedmiot przedmiot)
  327.         {
  328.             przedmioty.Add(przedmiot);
  329.         }
  330.  
  331.         public void DodajStudenta(Student student)
  332.         {
  333.             studenci.Add(student);
  334.         }
  335.  
  336.         public bool DodajWykladowce(Wykladowca wykladowca, string nazwaJednostki)
  337.         {
  338.             bool check = false;
  339.             foreach (Jednostka jednostka in jednostki)
  340.             {
  341.                 if(jednostka.Nazwa == nazwaJednostki)
  342.                 {
  343.                     jednostka.DodajWykladowce(wykladowca);
  344.                     check = true;
  345.                 }
  346.             }
  347.  
  348.             if(check)
  349.             {
  350.                 Console.WriteLine("Dodano wykladowce!");
  351.                 return true;
  352.             }
  353.             else
  354.             {
  355.                 Console.WriteLine("Brak pasujacej jednostki!");
  356.                 return false;
  357.             }
  358.         }
  359.  
  360.         public void InfoStudenci(bool infoOceny)
  361.         {
  362.             Console.WriteLine("Studenci:");
  363.             foreach (Student student in studenci)
  364.             {
  365.                 if(infoOceny)
  366.                 {
  367.                     student.Wypiszinfo();
  368.                     student.InfoOceny();
  369.                 }
  370.                 else
  371.                     student.Wypiszinfo();
  372.             }
  373.         }
  374.  
  375.         public void InfoJednostki(bool infoWykladowcy)
  376.         {
  377.             Console.WriteLine("Jednostki:");
  378.             foreach (Jednostka jednostka in jednostki)
  379.             {
  380.                 if(infoWykladowcy)
  381.                 {
  382.                     jednostka.Wypiszinfo();
  383.                     jednostka.InfoWykladowcy();
  384.                 }
  385.                 else
  386.                     jednostka.Wypiszinfo();
  387.             }
  388.         }
  389.  
  390.         public void InfoPrzedmioty()
  391.         {
  392.             Console.WriteLine("Przedmioty:");
  393.             foreach (Przedmiot przedmiot in przedmioty)
  394.             {
  395.                 przedmiot.Wypiszinfo();
  396.             }
  397.         }
  398.  
  399.         public bool DodajOcene(int nrIndeksu, string nazwaPrzedmiotu, double wartoscOceny, string data)
  400.         {
  401.             bool checkPrzedmiot = false;
  402.             bool checkStudent = false;
  403.             Przedmiot tmpPrzedmiot = null;
  404.             Student tmpStudent = null;
  405.  
  406.             foreach (Przedmiot przedmiot in przedmioty)
  407.             {
  408.                 if(przedmiot.Nazwa == nazwaPrzedmiotu)
  409.                 {
  410.                     tmpPrzedmiot = przedmiot;
  411.                     checkPrzedmiot = true;
  412.                 }
  413.             }
  414.  
  415.             foreach (Student student in studenci)
  416.             {
  417.                 if(student.NrIndeksu == nrIndeksu)
  418.                 {
  419.                     tmpStudent = student;
  420.                     checkStudent = true;
  421.                 }
  422.             }
  423.  
  424.             if(checkPrzedmiot && checkStudent)
  425.             {
  426.                 tmpStudent.DodajOcene(tmpPrzedmiot, wartoscOceny, data);
  427.                 Console.WriteLine("Pomyslnie dodano ocene!");
  428.                 return true;
  429.             }
  430.             else
  431.             {
  432.                 Console.WriteLine("Nie udalo sie dodac oceny!");
  433.                 return false;
  434.             }
  435.         }
  436.  
  437.         public bool UsunStudenta(int nrIndeksu)
  438.         {
  439.             bool check = false;
  440.             Student tmpStudent = null;
  441.             foreach (Student student in studenci)
  442.             {
  443.                 if(student.NrIndeksu == nrIndeksu)
  444.                 {
  445.                     tmpStudent = student;
  446.                     check = true;
  447.                 }
  448.             }
  449.  
  450.             if(check)
  451.             {
  452.                 studenci.Remove(tmpStudent);
  453.                 Console.WriteLine("Usunieto studenta!");
  454.                 return true;
  455.             }
  456.             else
  457.             {
  458.                 Console.WriteLine("Brak studenta do usuniecia do usuniecia!");
  459.                 return false;
  460.             }
  461.         }
  462.  
  463.         public bool PrzeniesWykladowce(Wykladowca _wykladowca, string nazwaObecnejJednostki, string nazwaNowejJednostki)
  464.         {
  465.             bool checkObecnaJednostka = false;
  466.             bool checkNowaJednostka = false;
  467.             bool checkWykladowca = false;
  468.             Jednostka obecnaJednostka = null;
  469.             Jednostka nowaJednostka = null;
  470.             Wykladowca tmpWykladowca = null;
  471.  
  472.             foreach (Jednostka jednostka in jednostki)
  473.             {
  474.                 if(jednostka.Nazwa == nazwaObecnejJednostki)
  475.                 {
  476.                     obecnaJednostka = jednostka;
  477.                     checkObecnaJednostka = true;
  478.                     foreach (Wykladowca wykladowca in jednostka.Wykladowcy)
  479.                     {
  480.                         if(wykladowca == _wykladowca)
  481.                         {
  482.                             tmpWykladowca = wykladowca;
  483.                             checkWykladowca = true;
  484.                         }
  485.                     }
  486.                 }
  487.             }
  488.  
  489.             foreach (Jednostka jednostka in jednostki)
  490.             {
  491.                 if(jednostka.Nazwa == nazwaNowejJednostki)
  492.                 {
  493.                     nowaJednostka = jednostka;
  494.                     checkNowaJednostka = true;
  495.                 }
  496.             }
  497.  
  498.             if(checkObecnaJednostka && checkNowaJednostka && checkWykladowca)
  499.             {
  500.                 obecnaJednostka.Wykladowcy.Remove(tmpWykladowca);
  501.                 nowaJednostka.Wykladowcy.Add(tmpWykladowca);
  502.                 Console.WriteLine("Pomyslnie przeniesiono wykladowce!");
  503.                 return true;
  504.             }
  505.             else
  506.             {
  507.                 Console.WriteLine("Nie udalo sie przeniesc wykladowcy!");
  508.                 return false;
  509.             }
  510.         }
  511.     }
  512.  
  513.  
  514.     class Program
  515.     {
  516.         static void Main(string[] args)
  517.         {
  518.             Wydzial wydzial = new Wydzial();
  519.  
  520.             wydzial.DodajJednostke("Katedra Informatyki", "ul. Armii Krajowej 64");
  521.             wydzial.DodajJednostke("Katedra Mechaniki", "ul. Dabrowskiego 44");
  522.  
  523.             Wykladowca wykladowca1 = new Wykladowca("Piotr", "Nowak", "21.03.1983", "Doktor habilitowany", "Profesor uczelni");
  524.             Wykladowca wykladowca2 = new Wykladowca("Artur", "Kowalski", "03.07.1975", "Profesor", "Profesor");
  525.             Wykladowca wykladowca3 = new Wykladowca("Filip", "Kapusta", "12.04.1990", "Magister", "Wykladowca");
  526.             Wykladowca wykladowca4 = new Wykladowca("Mariusz", "Konieczny", "25.10.1970", "Profesor", "Profesor");
  527.             Wykladowca wykladowca5 = new Wykladowca("Adam", "Szpak", "30.06.1988", "Doktor", "Adiunkt");
  528.  
  529.             wydzial.DodajWykladowce(wykladowca1, "Katedra Informatyki");
  530.             wydzial.DodajWykladowce(wykladowca2, "Katedra Informatyki");
  531.             wydzial.DodajWykladowce(wykladowca3, "Katedra Informatyki");
  532.             wydzial.DodajWykladowce(wykladowca4, "Katedra Mechaniki");
  533.             wydzial.DodajWykladowce(wykladowca5, "Katedra Mechaniki");
  534.  
  535.             Przedmiot przedmiot1 = new Przedmiot("Programowanie obiektowe", "Informatyka", "Aplikacje WEBowe", 5, 30);
  536.             Przedmiot przedmiot2 = new Przedmiot("Bazy danych", "informatyka", "Aplikacje WEBowe", 5, 30);
  537.             Przedmiot przedmiot3 = new Przedmiot("Podstawy mechaniki", "Mechanika i budowa maszyn", "Silniki", 2, 30);
  538.  
  539.             wydzial.DodajPrzedmiot(przedmiot1);
  540.             wydzial.DodajPrzedmiot(przedmiot2);
  541.             wydzial.DodajPrzedmiot(przedmiot3);
  542.  
  543.             Student student1 = new Student("Andrzej", "Jarzabek", "19.03.1998", "Informatyka", "Aplikacje WEBowe", 3, 4, 123321);
  544.             Student student2 = new Student("Mateusz", "Kleta", "14.08.2000", "Mechanika i budowa maszyn", "Silniki", 1, 3, 321123);
  545.             Student student3 = new Student("Karol", "Milowicz", "12.12.1998", "Informatyka", "Aplikacje WEBowe", 3, 1, 246642);
  546.  
  547.             wydzial.DodajStudenta(student1);
  548.             wydzial.DodajStudenta(student2);
  549.             wydzial.DodajStudenta(student3);
  550.  
  551.             wydzial.DodajOcene(123321, "Programowanie obiektowe", 4.5, "21.04.2020");
  552.             wydzial.DodajOcene(123321, "Bazy danych", 3.0, "08.05.2020");
  553.             wydzial.DodajOcene(246642, "Programowanie obiektowe", 4.0, "21.04.2020");
  554.             wydzial.DodajOcene(246642, "Bazy danych", 3.5, "08.05.2020");
  555.             wydzial.DodajOcene(321123, "Podstawy mechaniki", 3.5, "22.04.2020");
  556.  
  557.             wydzial.InfoStudenci(true);
  558.             wydzial.InfoJednostki(true);
  559.  
  560.             wydzial.UsunStudenta(246642);
  561.             wydzial.PrzeniesWykladowce(wykladowca3, "Katedra Informatyki", "Katedra Mechaniki");
  562.             wydzial.Jednostki[0].UsunWykladowce(wykladowca1);
  563.  
  564.             wydzial.InfoStudenci(true);
  565.             wydzial.InfoJednostki(true);
  566.             wydzial.InfoPrzedmioty();
  567.  
  568.         }
  569.     }
  570. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement