Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections.Generic;
- namespace Lab5
- {
- interface IInfo
- {
- public void Wypiszinfo();
- }
- abstract class Osoba: IInfo
- {
- protected string imie, nazwisko, dataUro;
- public Osoba()
- {
- imie = "";
- nazwisko = "";
- }
- public Osoba(string imie, string nazwisko, string dataUro)
- {
- this.imie = imie;
- this.nazwisko = nazwisko;
- this.dataUro = dataUro;
- }
- public string Imie
- {
- get {return imie;}
- set {imie = value;}
- }
- public string Nazwisko
- {
- get {return nazwisko;}
- set {nazwisko = value;}
- }
- public virtual void Wypiszinfo()
- {
- Console.WriteLine("Imie: " + imie);
- Console.WriteLine("Nazwisko: " + nazwisko);
- Console.WriteLine("Data urodzenia: " + dataUro);
- }
- }
- class Student: Osoba
- {
- private string kierunek, specjalnosc;
- private int rok, grupa, nrIndeksu;
- private List<Ocenakoncowa> ocenyKoncowe = new List<Ocenakoncowa>();
- public Student():base()
- {
- kierunek = "";
- specjalnosc = "";
- rok = 0;
- grupa = 0;
- nrIndeksu = 0;
- }
- public Student(string imie, string nazwisko, string dataUro, string kierunek, string specjalnosc, int rok, int grupa, int nrIndeksu):base(imie, nazwisko, dataUro)
- {
- this.kierunek = kierunek;
- this.specjalnosc = specjalnosc;
- this.rok = rok;
- this.grupa = grupa;
- this.nrIndeksu = nrIndeksu;
- }
- public int NrIndeksu
- {
- get {return nrIndeksu;}
- set {nrIndeksu = value;}
- }
- public override void Wypiszinfo()
- {
- base.Wypiszinfo();
- Console.WriteLine("Kierunek: " + kierunek);
- Console.WriteLine("Specjalnosc: " + specjalnosc);
- Console.WriteLine("Rok: " + rok);
- Console.WriteLine("Grupa: " + grupa);
- Console.WriteLine("Numer indeksu: " + nrIndeksu);
- Console.WriteLine("");
- }
- public void InfoOceny()
- {
- Console.WriteLine("Oceny:");
- foreach (Ocenakoncowa ocena in ocenyKoncowe)
- {
- ocena.Wypiszinfo();
- Console.WriteLine("");
- }
- }
- public void DodajOcene(Przedmiot przedmiot, double wartoscOceny, string data)
- {
- Ocenakoncowa tmp = new Ocenakoncowa(wartoscOceny, data, przedmiot);
- ocenyKoncowe.Add(tmp);
- }
- }
- class Przedmiot: IInfo
- {
- private string nazwa, kierunek, specjalnosc;
- private int semestr, ilGodz;
- public Przedmiot()
- {
- nazwa = "";
- kierunek = "";
- specjalnosc = "";
- semestr = 0;
- ilGodz = 0;
- }
- public Przedmiot(string nazwa, string kierunek, string specjalnosc, int semestr, int ilGodz)
- {
- this.nazwa = nazwa;
- this.kierunek = kierunek;
- this.specjalnosc = specjalnosc;
- this.semestr = semestr;
- this.ilGodz = ilGodz;
- }
- public string Nazwa
- {
- get {return nazwa;}
- set {nazwa = value;}
- }
- public void Wypiszinfo()
- {
- Console.WriteLine("Nazwa: " + nazwa);
- Console.WriteLine("Kierunek: " + kierunek);
- Console.WriteLine("Specjalnosc: " + specjalnosc);
- Console.WriteLine("Semestr: " + semestr);
- Console.WriteLine("Ilosc godzin: " + ilGodz);
- Console.WriteLine("");
- }
- }
- class Ocenakoncowa:IInfo
- {
- private double wartosc;
- private string data;
- private Przedmiot przedmiot;
- public Ocenakoncowa()
- {
- wartosc = 0.0;
- data = "";
- }
- public Ocenakoncowa(double wartosc, string data, Przedmiot przedmiot)
- {
- this.wartosc = wartosc;
- this.data = data;
- this.przedmiot = przedmiot;
- }
- public void Wypiszinfo()
- {
- Console.WriteLine("Wartosc: " + wartosc);
- Console.WriteLine("Data: " + data);
- Console.WriteLine("Przedmiot: " + przedmiot.Nazwa);
- Console.WriteLine("");
- }
- }
- class Wykladowca: Osoba
- {
- private string tytulNaukowy, stanowisko;
- public Wykladowca():base()
- {
- tytulNaukowy = "";
- stanowisko = "";
- }
- public Wykladowca(string imie, string nazwisko, string dataUro, string tytulNaukowy, string stanowisko):
- base(imie, nazwisko, dataUro)
- {
- this.tytulNaukowy = tytulNaukowy;
- this.stanowisko = stanowisko;
- }
- public override void Wypiszinfo()
- {
- base.Wypiszinfo();
- Console.WriteLine("Tytul naukowy: " + tytulNaukowy);
- Console.WriteLine("Stanowisko: " + stanowisko);
- Console.WriteLine("");
- }
- }
- class Jednostka: IInfo
- {
- private string nazwa, adres;
- private List<Wykladowca> wykladowcy = new List<Wykladowca>();
- public Jednostka()
- {
- nazwa = "";
- adres = "";
- }
- public Jednostka(string nazwa, string adres)
- {
- this.nazwa = nazwa;
- this.adres = adres;
- }
- public string Nazwa
- {
- get {return nazwa;}
- set {nazwa = value;}
- }
- public List<Wykladowca> Wykladowcy
- {
- get {return wykladowcy;}
- }
- public void DodajWykladowce(Wykladowca wykladowca)
- {
- wykladowcy.Add(wykladowca);
- }
- public bool UsunWykladowce(Wykladowca _wykladowca)
- {
- bool check = false;
- Wykladowca tmpWykladowca = null;
- foreach (Wykladowca wykladowca in wykladowcy)
- {
- if(_wykladowca == wykladowca)
- {
- tmpWykladowca = wykladowca;
- check = true;
- }
- }
- if(check)
- {
- wykladowcy.Remove(tmpWykladowca);
- Console.WriteLine("Pomyslnie usunieto wykladowce!");
- return true;
- }
- else
- {
- Console.WriteLine("Brak wykladowcy do usuniecia!");
- return false;
- }
- }
- public bool UsunWykladowce(string imie, string nazwisko)
- {
- bool check = false;
- Wykladowca tmpWykladowca = null;
- foreach (Wykladowca wykladowca in wykladowcy)
- {
- if(wykladowca.Imie == imie && wykladowca.Nazwisko == nazwisko)
- {
- tmpWykladowca = wykladowca;
- check = true;
- }
- }
- if(check)
- {
- wykladowcy.Remove(tmpWykladowca);
- Console.WriteLine("Usunieto wykladowce!");
- return true;
- }
- else
- {
- Console.WriteLine("Brak wykladowcy do usuniecia!");
- return false;
- }
- }
- public void InfoWykladowcy()
- {
- Console.WriteLine("Wykladowcy:");
- foreach (Wykladowca wykladowca in wykladowcy)
- {
- wykladowca.Wypiszinfo();
- }
- }
- public void Wypiszinfo()
- {
- Console.WriteLine("Nazwa jednostki: " + nazwa);
- Console.WriteLine("Adres jednostki: " + adres);
- Console.WriteLine("");
- }
- }
- class Wydzial
- {
- private List<Przedmiot> przedmioty;
- private List<Student> studenci;
- private List<Jednostka> jednostki;
- public Wydzial()
- {
- przedmioty = new List<Przedmiot>();
- studenci = new List<Student>();
- jednostki = new List<Jednostka>();
- }
- public List<Jednostka> Jednostki
- {
- get {return jednostki;}
- }
- public void DodajJednostke(string nazwaJednostki, string adresJednostki)
- {
- Jednostka tmp = new Jednostka(nazwaJednostki, adresJednostki);
- jednostki.Add(tmp);
- }
- public void DodajPrzedmiot(Przedmiot przedmiot)
- {
- przedmioty.Add(przedmiot);
- }
- public void DodajStudenta(Student student)
- {
- studenci.Add(student);
- }
- public bool DodajWykladowce(Wykladowca wykladowca, string nazwaJednostki)
- {
- bool check = false;
- foreach (Jednostka jednostka in jednostki)
- {
- if(jednostka.Nazwa == nazwaJednostki)
- {
- jednostka.DodajWykladowce(wykladowca);
- check = true;
- }
- }
- if(check)
- {
- Console.WriteLine("Dodano wykladowce!");
- return true;
- }
- else
- {
- Console.WriteLine("Brak pasujacej jednostki!");
- return false;
- }
- }
- public void InfoStudenci(bool infoOceny)
- {
- Console.WriteLine("Studenci:");
- foreach (Student student in studenci)
- {
- if(infoOceny)
- {
- student.Wypiszinfo();
- student.InfoOceny();
- }
- else
- student.Wypiszinfo();
- }
- }
- public void InfoJednostki(bool infoWykladowcy)
- {
- Console.WriteLine("Jednostki:");
- foreach (Jednostka jednostka in jednostki)
- {
- if(infoWykladowcy)
- {
- jednostka.Wypiszinfo();
- jednostka.InfoWykladowcy();
- }
- else
- jednostka.Wypiszinfo();
- }
- }
- public void InfoPrzedmioty()
- {
- Console.WriteLine("Przedmioty:");
- foreach (Przedmiot przedmiot in przedmioty)
- {
- przedmiot.Wypiszinfo();
- }
- }
- public bool DodajOcene(int nrIndeksu, string nazwaPrzedmiotu, double wartoscOceny, string data)
- {
- bool checkPrzedmiot = false;
- bool checkStudent = false;
- Przedmiot tmpPrzedmiot = null;
- Student tmpStudent = null;
- foreach (Przedmiot przedmiot in przedmioty)
- {
- if(przedmiot.Nazwa == nazwaPrzedmiotu)
- {
- tmpPrzedmiot = przedmiot;
- checkPrzedmiot = true;
- }
- }
- foreach (Student student in studenci)
- {
- if(student.NrIndeksu == nrIndeksu)
- {
- tmpStudent = student;
- checkStudent = true;
- }
- }
- if(checkPrzedmiot && checkStudent)
- {
- tmpStudent.DodajOcene(tmpPrzedmiot, wartoscOceny, data);
- Console.WriteLine("Pomyslnie dodano ocene!");
- return true;
- }
- else
- {
- Console.WriteLine("Nie udalo sie dodac oceny!");
- return false;
- }
- }
- public bool UsunStudenta(int nrIndeksu)
- {
- bool check = false;
- Student tmpStudent = null;
- foreach (Student student in studenci)
- {
- if(student.NrIndeksu == nrIndeksu)
- {
- tmpStudent = student;
- check = true;
- }
- }
- if(check)
- {
- studenci.Remove(tmpStudent);
- Console.WriteLine("Usunieto studenta!");
- return true;
- }
- else
- {
- Console.WriteLine("Brak studenta do usuniecia do usuniecia!");
- return false;
- }
- }
- public bool PrzeniesWykladowce(Wykladowca _wykladowca, string nazwaObecnejJednostki, string nazwaNowejJednostki)
- {
- bool checkObecnaJednostka = false;
- bool checkNowaJednostka = false;
- bool checkWykladowca = false;
- Jednostka obecnaJednostka = null;
- Jednostka nowaJednostka = null;
- Wykladowca tmpWykladowca = null;
- foreach (Jednostka jednostka in jednostki)
- {
- if(jednostka.Nazwa == nazwaObecnejJednostki)
- {
- obecnaJednostka = jednostka;
- checkObecnaJednostka = true;
- foreach (Wykladowca wykladowca in jednostka.Wykladowcy)
- {
- if(wykladowca == _wykladowca)
- {
- tmpWykladowca = wykladowca;
- checkWykladowca = true;
- }
- }
- }
- }
- foreach (Jednostka jednostka in jednostki)
- {
- if(jednostka.Nazwa == nazwaNowejJednostki)
- {
- nowaJednostka = jednostka;
- checkNowaJednostka = true;
- }
- }
- if(checkObecnaJednostka && checkNowaJednostka && checkWykladowca)
- {
- obecnaJednostka.Wykladowcy.Remove(tmpWykladowca);
- nowaJednostka.Wykladowcy.Add(tmpWykladowca);
- Console.WriteLine("Pomyslnie przeniesiono wykladowce!");
- return true;
- }
- else
- {
- Console.WriteLine("Nie udalo sie przeniesc wykladowcy!");
- return false;
- }
- }
- }
- class Program
- {
- static void Main(string[] args)
- {
- Wydzial wydzial = new Wydzial();
- wydzial.DodajJednostke("Katedra Informatyki", "ul. Armii Krajowej 64");
- wydzial.DodajJednostke("Katedra Mechaniki", "ul. Dabrowskiego 44");
- Wykladowca wykladowca1 = new Wykladowca("Piotr", "Nowak", "21.03.1983", "Doktor habilitowany", "Profesor uczelni");
- Wykladowca wykladowca2 = new Wykladowca("Artur", "Kowalski", "03.07.1975", "Profesor", "Profesor");
- Wykladowca wykladowca3 = new Wykladowca("Filip", "Kapusta", "12.04.1990", "Magister", "Wykladowca");
- Wykladowca wykladowca4 = new Wykladowca("Mariusz", "Konieczny", "25.10.1970", "Profesor", "Profesor");
- Wykladowca wykladowca5 = new Wykladowca("Adam", "Szpak", "30.06.1988", "Doktor", "Adiunkt");
- wydzial.DodajWykladowce(wykladowca1, "Katedra Informatyki");
- wydzial.DodajWykladowce(wykladowca2, "Katedra Informatyki");
- wydzial.DodajWykladowce(wykladowca3, "Katedra Informatyki");
- wydzial.DodajWykladowce(wykladowca4, "Katedra Mechaniki");
- wydzial.DodajWykladowce(wykladowca5, "Katedra Mechaniki");
- Przedmiot przedmiot1 = new Przedmiot("Programowanie obiektowe", "Informatyka", "Aplikacje WEBowe", 5, 30);
- Przedmiot przedmiot2 = new Przedmiot("Bazy danych", "informatyka", "Aplikacje WEBowe", 5, 30);
- Przedmiot przedmiot3 = new Przedmiot("Podstawy mechaniki", "Mechanika i budowa maszyn", "Silniki", 2, 30);
- wydzial.DodajPrzedmiot(przedmiot1);
- wydzial.DodajPrzedmiot(przedmiot2);
- wydzial.DodajPrzedmiot(przedmiot3);
- Student student1 = new Student("Andrzej", "Jarzabek", "19.03.1998", "Informatyka", "Aplikacje WEBowe", 3, 4, 123321);
- Student student2 = new Student("Mateusz", "Kleta", "14.08.2000", "Mechanika i budowa maszyn", "Silniki", 1, 3, 321123);
- Student student3 = new Student("Karol", "Milowicz", "12.12.1998", "Informatyka", "Aplikacje WEBowe", 3, 1, 246642);
- wydzial.DodajStudenta(student1);
- wydzial.DodajStudenta(student2);
- wydzial.DodajStudenta(student3);
- wydzial.DodajOcene(123321, "Programowanie obiektowe", 4.5, "21.04.2020");
- wydzial.DodajOcene(123321, "Bazy danych", 3.0, "08.05.2020");
- wydzial.DodajOcene(246642, "Programowanie obiektowe", 4.0, "21.04.2020");
- wydzial.DodajOcene(246642, "Bazy danych", 3.5, "08.05.2020");
- wydzial.DodajOcene(321123, "Podstawy mechaniki", 3.5, "22.04.2020");
- wydzial.InfoStudenci(true);
- wydzial.InfoJednostki(true);
- wydzial.UsunStudenta(246642);
- wydzial.PrzeniesWykladowce(wykladowca3, "Katedra Informatyki", "Katedra Mechaniki");
- wydzial.Jednostki[0].UsunWykladowce(wykladowca1);
- wydzial.InfoStudenci(true);
- wydzial.InfoJednostki(true);
- wydzial.InfoPrzedmioty();
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement