Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Text;
- using System.Threading.Tasks;
- namespace ConsoleApp1
- {
- #region Klasa Osoba
- class Osoba
- {
- protected string imie;
- protected string nazwisko;
- protected string dataUrodzenia;
- public Osoba(string imie_, string nazwisko_, string dataUrodzenia_)
- {
- this.imie = imie_;
- this.nazwisko = nazwisko_;
- this.dataUrodzenia = dataUrodzenia_;
- }
- public virtual void WypiszInfo()
- {
- Console.WriteLine($"\nReprezentuje klase Osoby" +
- $"\n Imie {this.imie}" +
- $"\n Nazwisko {this.nazwisko}" +
- $"\n Urodzilem sie w {this.dataUrodzenia}");
- }
- }
- #endregion
- #region Klasa Student
- class Student : Osoba
- {
- private List<Ocena> oceny = new List<Ocena>();
- private int rok;
- public int Rok
- {
- get { return rok; }
- set { rok = value; }
- }
- private int grupa;
- public int Grupa
- {
- get { return grupa; }
- set { grupa = value; }
- }
- private int nrIndeksu;
- public int NrIndeksu
- {
- get { return nrIndeksu; }
- set { nrIndeksu = value; }
- }
- public Student(string imie_, string nazwisko_, string dataUrodzenia_, int rok_, int grupa_, int nrIndeksu_) : base(imie_, nazwisko_, dataUrodzenia_)
- {
- base.imie = imie_;
- base.nazwisko = nazwisko_;
- base.dataUrodzenia = dataUrodzenia_;
- this.rok = rok_;
- this.grupa = grupa_;
- this.nrIndeksu = nrIndeksu_;
- }
- public override void WypiszInfo()
- {
- Console.WriteLine($"\nReprezentuje klase Student" +
- $"\n Imie {base.imie}" +
- $"\n Nazwisko {base.nazwisko}" +
- $"\n Urodzilem sie w {base.dataUrodzenia}" +
- $"\n Jestem na {this.rok}. roku w grupie {this.grupa}" +
- $"\n Posiadam unikalny numer indeksu {this.nrIndeksu}" +
- $"\n Zdobyte oceny :");
- foreach(var ocena in oceny)
- {
- Console.Write($" [{ocena.Wartosc}] z przedmiotu [{ocena.NazwaPrzedmiotu}]\n");
- }
- }
- public void DodajOcene(string nazwaPrzedmiotu, string data, double wartosc)
- {
- var grade = new Ocena(nazwaPrzedmiotu,data,wartosc);
- oceny.Add(grade);
- }
- public void WypiszOceny()
- {
- Console.WriteLine($"\nStudent {base.imie} {base.nazwisko}.\n" +
- $"Ma oceny:\n");
- foreach (var ocena in oceny)
- {
- Console.WriteLine($"\tData: [{ocena.Data}] " +
- $"Ocena: [{ocena.Wartosc}] z przedmiotu [{ocena.NazwaPrzedmiotu}]");
- }
- }
- public void WypiszOceny(string nazwaPrzedmiotu)
- {
- foreach (var ocena in oceny)
- {
- if (ocena.NazwaPrzedmiotu == nazwaPrzedmiotu)
- {
- Console.WriteLine($"\nData: [{ocena.Data}]\n" +
- $"Student [{base.imie} {base.nazwisko}]\n" +
- $"Z przedmiotu [{ocena.NazwaPrzedmiotu}] ma ocene [{ocena.Wartosc}]\n");
- }
- }
- }
- public void UsunOcene(string nazwaPrzedmiotu, string data, double wartosc)
- {
- // Ja bym wolal uzyc ukochanej lambdy =)
- oceny.RemoveAll(ocena => ocena.NazwaPrzedmiotu == nazwaPrzedmiotu &&
- ocena.Data == data &&
- ocena.Wartosc == wartosc);
- //for (int i = 0; i < oceny.Count;)
- //{
- // Ocena o = oceny[i];
- // if (o.NazwaPrzedmiotu == nazwaPrzedmiotu && o.Data == data
- // && o.Wartosc == wartosc)
- // {
- // oceny.RemoveAt(i);
- // }
- // else
- // {
- // ++i;
- // }
- //}
- }
- public void UsunOceny() {
- oceny.Clear();
- }
- public void UsunOceny(string nazwaPrzedmiotu)
- {
- // Jako, ze tutaj nie było narzucone rozwiązanie to wrzucam lambdę
- oceny.RemoveAll(ocena => ocena.NazwaPrzedmiotu == nazwaPrzedmiotu);
- }
- }
- #endregion
- #region Klasa Pilkarz
- class Pilkarz : Osoba
- {
- private string pozycja;
- public string Pozycja
- {
- get { return pozycja; }
- set { pozycja = value; }
- }
- private string klub;
- public string Klub
- {
- get { return klub; }
- set { klub = value; }
- }
- private int liczbaGoli = 0;
- public int LiczbaGoli
- {
- get { return liczbaGoli; }
- set { liczbaGoli = value; }
- }
- public Pilkarz(string imie_, string nazwisko_, string dataUrodzenia_, string pozycja_, string klub_) : base(imie_, nazwisko_, dataUrodzenia_)
- {
- base.imie = imie_;
- base.nazwisko = nazwisko_;
- base.dataUrodzenia = dataUrodzenia_;
- this.pozycja = pozycja_;
- this.klub = klub_;
- }
- public override void WypiszInfo()
- {
- Console.WriteLine($"\nReprezentuje klase Pilkarza" +
- $"\n Imie {base.imie}" +
- $"\n Nazwisko {base.nazwisko}" +
- $"\n Urodzilem sie w {base.dataUrodzenia}" +
- $"\n Gram na pozycji {this.pozycja} dla klubu {this.klub}" +
- $"\n Strzelilem liczbe {this.liczbaGoli} goli w tym sezonie");
- }
- public virtual void StrzelGola()
- {
- ++liczbaGoli;
- Console.WriteLine("\n\n!!! GOL !!! GOL !!! GOL !!! GOL !!! GOL !!!");
- Console.WriteLine("" +
- " ------------\n" +
- " | _ |\n" +
- " o | _o = -- |\n" +
- " () o\n" +
- " /), \n");
- Console.WriteLine($"Pilkarz [{base.imie} {base.nazwisko}] strzela {liczbaGoli}. gola w tym sezonie!\n\n");
- }
- }
- #endregion
- #region Klasa PilkarzReczny
- class PilkarzReczny : Pilkarz
- {
- public Pilkarz(string imie_, string nazwisko_, string dataUrodzenia_, string pozycja_, string klub_)
- : base(imie_,nazwisko_,dataUrodzenia_,pozycja_,klub_)
- {
- base.imie = imie_;
- base.nazwisko = nazwisko_;
- base.dataUrodzenia = dataUrodzenia_;
- base.Pozycja = pozycja_;
- base.Klub = klub_;
- }
- public override void StrzelGola()
- {
- base.StrzelGola();
- }
- }
- #endregion
- #region Klasa PilkarzNozny
- class PilkarzNozny : Pilkarz
- {
- }
- #endregion
- #region Ocena
- class Ocena
- {
- private string nazwaPrzedmiotu;
- public string NazwaPrzedmiotu
- {
- get { return nazwaPrzedmiotu; }
- set { nazwaPrzedmiotu = value; }
- }
- private string data;
- public string Data
- {
- get { return data; }
- set { data = value; }
- }
- private double wartosc;
- public double Wartosc
- {
- get { return wartosc; }
- set { wartosc = value; }
- }
- public Ocena(string nazwaPrzedmiotu_, string data_, double wartosc_)
- {
- this.nazwaPrzedmiotu = nazwaPrzedmiotu_;
- this.data = data_;
- this.wartosc = wartosc_;
- }
- public void WypiszInfo()
- {
- Console.WriteLine("Nie wiem co tutaj wpisac :(");
- }
- }
- #endregion
- #region Main
- class Program
- {
- static void Main(string[] args)
- {
- #region Zadanie 1
- Console.WriteLine("\n### Zadanie 1 ###\n");
- var o = new Osoba("Adam", "Miś", "20.03.1980");
- var o2 = new Student("Michał", "Kot", "13.04.1990", 2, 1, 12345);
- var o3 = new Pilkarz("Mateusz", "Żbik", "20.03.1980", "obrońca", "FC Czestochowa");
- o.WypiszInfo();
- o2.WypiszInfo();
- o3.WypiszInfo();
- var s = new Student("Krzysztof", "Jeż", "22.12.1990", 2, 5, 54321);
- var p = new Pilkarz("Piotr", "Kos", "14.09.1984", "napastnik", "FC Politechnika");
- s.WypiszInfo();
- p.WypiszInfo();
- ((Pilkarz)o3).StrzelGola();
- p.StrzelGola();
- p.StrzelGola();
- o3.WypiszInfo();
- p.WypiszInfo();
- #endregion
- #region Zadanie 2
- Console.WriteLine("\n### Zadanie 2 ###\n");
- ((Student)o2).DodajOcene("PO", "20.02.2011", 5.0);
- ((Student)o2).DodajOcene("Bazy Danych", "13.02.2011", 4.0);
- // W skrypcie testowym nie było wywołań metod WypiszOceny, lecz użyłem je do przetestownia aplikacji
- o2.WypiszInfo();
- o2.WypiszOceny();
- s.DodajOcene("Bazy danych", "01.05.2011", 5.0);
- s.DodajOcene("AMWW", "11.05.2011", 4.0);
- s.DodajOcene("AMWW", "02.04.2011", 4.5);
- s.WypiszOceny();
- s.WypiszOceny("AMWW");
- s.WypiszOceny("Bazy danych");
- s.WypiszInfo();
- s.UsunOcene("AMWW", "02.04.2011", 4.5);
- s.WypiszOceny();
- s.WypiszInfo();
- s.DodajOcene("AMWW", "02.04.2011", 4.5);
- s.UsunOceny("AWW");
- s.WypiszInfo();
- s.DodajOcene("AMWW", "02.04.2011", 4.5);
- s.UsunOceny();
- s.WypiszInfo();
- #endregion
- Console.ReadKey();
- }
- }
- #endregion
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement