Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- namespace Laborki_nr_2
- {
- class Program
- {
- public static void Main(string[] args)
- {
- Kot k = new Kot();
- Kot.waga = 40; // nie moge ustawic wagi dla danego kota bo pole jest wspolne ( statyczne )
- k.WstawImie("Bonifacy");
- Console.WriteLine(k.GetImie());
- // Get i Set za kompocu kompleksu
- k.Il_wasow = 17; // odwoluje sie do kompleksu a nie bezposrednio do pola il
- Console.WriteLine(k.Il_wasow); // tak samo
- // Nowy Setter i Getter
- k.Dlg_ogona = 5;
- Console.WriteLine(k.Dlg_ogona);
- // Tablica Kociarnia
- Kociarnia koty = new Kociarnia();
- Console.WriteLine(koty.ile());
- Console.ReadKey(true);
- }
- }
- //------------------
- class Kot
- {
- public const int il_nog = 4;
- public static int waga; // W C# static jest wspolny
- private string imie;
- public string GetImie()
- {
- return imie;
- }
- public void WstawImie(string imiee)
- {
- imie = imiee;
- }
- private int il_wasow;
- // Tutaj musi byc inna nazwa niz pola prywatnego, wyglada na deklaracje nowej
- // zmiennej czyli bez nawiasow kwadratowych. To kompleks getterow i setterow.
- public int Il_wasow
- {
- get
- {
- return il_wasow;
- }
- set
- {
- if (il_wasow < 0)
- il_wasow = 0;
- else
- il_wasow = value; // musi byc value
- }
- }
- public double Dlg_ogona{ set; get; }
- /* To wyzej wygenteruje to:
- * private int dlg_ogona
- * public int Dlg_ogona
- {
- get
- {
- return dlg_ogona;
- }
- set
- {
- if (dlg_ogona < 0)
- dlg_ogona = 0;
- else
- dlg_ogona = value; // musi byc value
- }
- }*/
- }
- class Kociarnia
- {
- private Kot[] ko = new Kot[100]; // Tworze tablice obiektow classy kot
- public Kot this[int nr] // nr to numer indeksu | przyklad indeksera z get i set
- {
- get
- {
- if(nr > 0 && nr < 100)
- return ko[nr];
- else
- return new Kot();
- }
- set
- {
- ko[nr].Dlg_ogona = value;
- ko[nr].Il_wasow = value;
- ko[nr].WstawImie(value);
- }
- public int ile()
- {
- return ko.Length;
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment