Advertisement
Guest User

DZiwnyKonstruktor

a guest
Nov 19th, 2019
100
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 10.14 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. namespace ConsoleApp1
  8. {
  9.     #region Klasa Osoba
  10.     class Osoba
  11.     {
  12.  
  13.         protected string imie;
  14.         protected string nazwisko;
  15.         protected string dataUrodzenia;
  16.  
  17.         public Osoba(string imie_, string nazwisko_, string dataUrodzenia_)
  18.         {
  19.             this.imie = imie_;
  20.             this.nazwisko = nazwisko_;
  21.             this.dataUrodzenia = dataUrodzenia_;
  22.         }
  23.  
  24.         public virtual void WypiszInfo()
  25.         {
  26.             Console.WriteLine($"\nReprezentuje klase Osoby" +
  27.                 $"\n Imie {this.imie}" +
  28.                 $"\n Nazwisko {this.nazwisko}" +
  29.                 $"\n Urodzilem sie w {this.dataUrodzenia}");
  30.         }
  31.  
  32.  
  33.  
  34.     }
  35.     #endregion
  36.  
  37.     #region Klasa Student
  38.     class Student : Osoba
  39.     {
  40.         private List<Ocena> oceny = new List<Ocena>();
  41.  
  42.         private int rok;
  43.  
  44.         public int Rok
  45.         {
  46.             get { return rok; }
  47.             set { rok = value; }
  48.         }
  49.  
  50.         private int grupa;
  51.  
  52.         public int Grupa
  53.         {
  54.             get { return grupa; }
  55.             set { grupa = value; }
  56.         }
  57.  
  58.         private int nrIndeksu;
  59.  
  60.         public int NrIndeksu
  61.         {
  62.             get { return nrIndeksu; }
  63.             set { nrIndeksu = value; }
  64.         }
  65.  
  66.         public Student(string imie_, string nazwisko_, string dataUrodzenia_, int rok_, int grupa_, int nrIndeksu_) : base(imie_, nazwisko_, dataUrodzenia_)
  67.         {
  68.             base.imie = imie_;
  69.             base.nazwisko = nazwisko_;
  70.             base.dataUrodzenia = dataUrodzenia_;
  71.             this.rok = rok_;
  72.             this.grupa = grupa_;
  73.             this.nrIndeksu = nrIndeksu_;
  74.         }
  75.  
  76.         public override void WypiszInfo()
  77.         {
  78.             Console.WriteLine($"\nReprezentuje klase Student" +
  79.                 $"\n Imie {base.imie}" +
  80.                 $"\n Nazwisko {base.nazwisko}" +
  81.                 $"\n Urodzilem sie w {base.dataUrodzenia}" +
  82.                 $"\n Jestem na {this.rok}. roku w grupie {this.grupa}" +
  83.                 $"\n Posiadam unikalny numer indeksu {this.nrIndeksu}" +
  84.                 $"\n Zdobyte oceny :");
  85.             foreach(var ocena in oceny)
  86.             {
  87.                 Console.Write($" [{ocena.Wartosc}] z przedmiotu [{ocena.NazwaPrzedmiotu}]\n");
  88.             }
  89.         }
  90.  
  91.         public void DodajOcene(string nazwaPrzedmiotu, string data, double wartosc)
  92.         {
  93.             var grade = new Ocena(nazwaPrzedmiotu,data,wartosc);
  94.             oceny.Add(grade);
  95.         }
  96.  
  97.         public void WypiszOceny()
  98.         {
  99.             Console.WriteLine($"\nStudent {base.imie} {base.nazwisko}.\n" +
  100.                 $"Ma oceny:\n");
  101.             foreach (var ocena in oceny)
  102.             {
  103.                 Console.WriteLine($"\tData: [{ocena.Data}] " +
  104.                     $"Ocena: [{ocena.Wartosc}] z przedmiotu [{ocena.NazwaPrzedmiotu}]");
  105.             }
  106.         }
  107.         public void WypiszOceny(string nazwaPrzedmiotu)
  108.         {
  109.             foreach (var ocena in oceny)
  110.             {
  111.                 if (ocena.NazwaPrzedmiotu == nazwaPrzedmiotu)
  112.                 {
  113.                     Console.WriteLine($"\nData: [{ocena.Data}]\n" +
  114.                         $"Student [{base.imie} {base.nazwisko}]\n" +
  115.                         $"Z przedmiotu [{ocena.NazwaPrzedmiotu}] ma ocene [{ocena.Wartosc}]\n");
  116.                 }
  117.             }
  118.         }
  119.  
  120.         public void UsunOcene(string nazwaPrzedmiotu, string data, double wartosc)
  121.         {
  122.             // Ja bym wolal uzyc ukochanej lambdy =)
  123.  
  124.             oceny.RemoveAll(ocena => ocena.NazwaPrzedmiotu == nazwaPrzedmiotu &&
  125.                 ocena.Data == data &&
  126.                 ocena.Wartosc == wartosc);
  127.  
  128.             //for (int i = 0; i < oceny.Count;)
  129.             //{
  130.             //    Ocena o = oceny[i];
  131.             //    if (o.NazwaPrzedmiotu == nazwaPrzedmiotu && o.Data == data
  132.             //        && o.Wartosc == wartosc)
  133.             //    {
  134.             //        oceny.RemoveAt(i);
  135.             //    }
  136.             //    else
  137.             //    {
  138.             //        ++i;
  139.             //    }
  140.             //}
  141.         }
  142.  
  143.         public void UsunOceny() {
  144.             oceny.Clear();
  145.         }
  146.         public void UsunOceny(string nazwaPrzedmiotu)
  147.         {
  148.             // Jako, ze tutaj nie było narzucone rozwiązanie to wrzucam lambdę
  149.             oceny.RemoveAll(ocena => ocena.NazwaPrzedmiotu == nazwaPrzedmiotu);
  150.         }
  151.  
  152.  
  153.     }
  154.     #endregion
  155.  
  156.     #region Klasa Pilkarz
  157.     class Pilkarz : Osoba
  158.     {
  159.         private string pozycja;
  160.  
  161.         public string Pozycja
  162.         {
  163.             get { return pozycja; }
  164.             set { pozycja = value; }
  165.         }
  166.  
  167.         private string klub;
  168.  
  169.         public string Klub
  170.         {
  171.             get { return klub; }
  172.             set { klub = value; }
  173.         }
  174.  
  175.         private int liczbaGoli = 0;
  176.  
  177.         public int LiczbaGoli
  178.         {
  179.             get { return liczbaGoli; }
  180.             set { liczbaGoli = value; }
  181.         }
  182.  
  183.         public Pilkarz(string imie_, string nazwisko_, string dataUrodzenia_, string pozycja_, string klub_) : base(imie_, nazwisko_, dataUrodzenia_)
  184.         {
  185.             base.imie = imie_;
  186.             base.nazwisko = nazwisko_;
  187.             base.dataUrodzenia = dataUrodzenia_;
  188.             this.pozycja = pozycja_;
  189.             this.klub = klub_;
  190.         }
  191.  
  192.         public override void WypiszInfo()
  193.         {
  194.             Console.WriteLine($"\nReprezentuje klase Pilkarza" +
  195.                 $"\n Imie {base.imie}" +
  196.                 $"\n Nazwisko {base.nazwisko}" +
  197.                 $"\n Urodzilem sie w {base.dataUrodzenia}" +
  198.                 $"\n Gram na pozycji {this.pozycja} dla klubu {this.klub}" +
  199.                 $"\n Strzelilem liczbe {this.liczbaGoli} goli w tym sezonie");
  200.         }
  201.  
  202.         public virtual void StrzelGola()
  203.         {
  204.             ++liczbaGoli;
  205.             Console.WriteLine("\n\n!!! GOL !!! GOL !!! GOL !!! GOL !!! GOL !!!");
  206.             Console.WriteLine("" +
  207.                 "                      ------------\n" +
  208.                 "                      | _        |\n" +
  209.                 "  o                   | _o = --  |\n" +
  210.                 " ()    o\n" +
  211.                 " /), \n");
  212.             Console.WriteLine($"Pilkarz [{base.imie} {base.nazwisko}] strzela {liczbaGoli}. gola w tym sezonie!\n\n");
  213.  
  214.         }
  215.  
  216.  
  217.     }
  218.     #endregion
  219.  
  220.     #region Klasa PilkarzReczny
  221.     class PilkarzReczny : Pilkarz
  222.     {
  223.  
  224.         public Pilkarz(string imie_, string nazwisko_, string dataUrodzenia_, string pozycja_, string klub_)
  225.             : base(imie_,nazwisko_,dataUrodzenia_,pozycja_,klub_)
  226.         {
  227.             base.imie = imie_;
  228.             base.nazwisko = nazwisko_;
  229.             base.dataUrodzenia = dataUrodzenia_;
  230.             base.Pozycja = pozycja_;
  231.             base.Klub = klub_;
  232.         }
  233.         public override void StrzelGola()
  234.         {
  235.             base.StrzelGola();
  236.         }
  237.     }
  238.     #endregion
  239.  
  240.     #region Klasa PilkarzNozny
  241.     class PilkarzNozny : Pilkarz
  242.     {
  243.  
  244.     }
  245.     #endregion
  246.  
  247.     #region Ocena
  248.     class Ocena
  249.     {
  250.         private string nazwaPrzedmiotu;
  251.  
  252.         public string NazwaPrzedmiotu
  253.         {
  254.             get { return nazwaPrzedmiotu; }
  255.             set { nazwaPrzedmiotu = value; }
  256.         }
  257.  
  258.         private string data;
  259.  
  260.         public string Data
  261.         {
  262.             get { return data; }
  263.             set { data = value; }
  264.         }
  265.  
  266.         private double wartosc;
  267.  
  268.         public double Wartosc
  269.         {
  270.             get { return wartosc; }
  271.             set { wartosc = value; }
  272.         }
  273.  
  274.         public Ocena(string nazwaPrzedmiotu_, string data_, double wartosc_)
  275.         {
  276.             this.nazwaPrzedmiotu = nazwaPrzedmiotu_;
  277.             this.data = data_;
  278.             this.wartosc = wartosc_;
  279.         }
  280.  
  281.         public void WypiszInfo()
  282.         {
  283.             Console.WriteLine("Nie wiem co tutaj wpisac :(");
  284.         }
  285.  
  286.     }
  287.     #endregion
  288.  
  289.     #region Main
  290.     class Program
  291.     {
  292.         static void Main(string[] args)
  293.         {
  294.             #region Zadanie 1
  295.             Console.WriteLine("\n### Zadanie 1 ###\n");
  296.  
  297.             var o = new Osoba("Adam", "Miś", "20.03.1980");
  298.             var o2 = new Student("Michał", "Kot", "13.04.1990", 2, 1, 12345);
  299.             var o3 = new Pilkarz("Mateusz", "Żbik", "20.03.1980", "obrońca", "FC Czestochowa");
  300.  
  301.             o.WypiszInfo();
  302.             o2.WypiszInfo();
  303.             o3.WypiszInfo();
  304.  
  305.             var s = new Student("Krzysztof", "Jeż", "22.12.1990", 2, 5, 54321);
  306.             var p = new Pilkarz("Piotr", "Kos", "14.09.1984", "napastnik", "FC Politechnika");
  307.  
  308.             s.WypiszInfo();
  309.             p.WypiszInfo();
  310.  
  311.             ((Pilkarz)o3).StrzelGola();
  312.             p.StrzelGola();
  313.             p.StrzelGola();
  314.  
  315.             o3.WypiszInfo();
  316.             p.WypiszInfo();
  317.             #endregion
  318.  
  319.             #region Zadanie 2
  320.             Console.WriteLine("\n### Zadanie 2 ###\n");
  321.  
  322.             ((Student)o2).DodajOcene("PO", "20.02.2011", 5.0);
  323.             ((Student)o2).DodajOcene("Bazy Danych", "13.02.2011", 4.0);
  324.  
  325.             // W skrypcie testowym nie było wywołań metod WypiszOceny, lecz użyłem je do przetestownia aplikacji
  326.              
  327.             o2.WypiszInfo();
  328.             o2.WypiszOceny();
  329.  
  330.             s.DodajOcene("Bazy danych", "01.05.2011", 5.0);
  331.             s.DodajOcene("AMWW", "11.05.2011", 4.0);
  332.             s.DodajOcene("AMWW", "02.04.2011", 4.5);
  333.             s.WypiszOceny();
  334.             s.WypiszOceny("AMWW");
  335.             s.WypiszOceny("Bazy danych");
  336.  
  337.             s.WypiszInfo();
  338.  
  339.             s.UsunOcene("AMWW", "02.04.2011", 4.5);
  340.             s.WypiszOceny();
  341.  
  342.             s.WypiszInfo();
  343.  
  344.             s.DodajOcene("AMWW", "02.04.2011", 4.5);
  345.             s.UsunOceny("AWW");
  346.  
  347.             s.WypiszInfo();
  348.  
  349.             s.DodajOcene("AMWW", "02.04.2011", 4.5);
  350.             s.UsunOceny();
  351.  
  352.             s.WypiszInfo();
  353.             #endregion
  354.  
  355.             Console.ReadKey();
  356.  
  357.         }
  358.     }
  359.     #endregion
  360. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement