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 zad_1
- {
- abstract class Maszyna
- {
- double moc;
- double cena;
- string opis;
- string typ;
- public abstract bool Jazda();
- public abstract void Stop();
- public abstract void Start();
- public Maszyna(double moc, double cena, string opis, string typ)
- {
- this.moc = moc;
- this.cena = cena;
- this.opis = opis;
- this.typ = typ;
- }
- public Maszyna()
- {
- //NICZ
- }
- public string Podaj()
- {
- return typ + ", " + opis + ", " + moc + "KM, " + cena + "PLN";
- }
- public int Porównaj(Maszyna m)
- {
- if (this.moc == m.moc) return 0;
- if (this.moc > m.moc)
- return -1;
- else
- return 1;
- }
- }
- class Kombajn : Maszyna
- {
- bool CzyJedzie;
- public Kombajn(double moc, double cena, string opis, string typ)
- : base(moc, cena, opis, typ)
- {
- }
- public override void Start()
- {
- CzyJedzie = true;
- }
- public override void Stop()
- {
- CzyJedzie = false;
- }
- public override bool Jazda()
- {
- return CzyJedzie;
- }
- }
- class Traktor : Maszyna
- {
- bool CzyJedzie;
- public Traktor(double moc, double cena, string opis, string typ)
- : base(moc, cena, opis, typ)
- {
- }
- public override void Start()
- {
- CzyJedzie = true;
- }
- public override void Stop()
- {
- CzyJedzie = false;
- }
- public override bool Jazda()
- {
- return CzyJedzie;
- }
- }
- class Program
- {
- static void Main(string[] args)
- {
- Traktor ursus = new Traktor(120, 150000, "Szybki jak dzik", "Traktor");
- Traktor johndeer = new Traktor(180, 2150000, "Drogi mocno", "Traktor");
- Kombajn K1 = new Kombajn(330, 1500000, "Łoooho", "Kombajn");
- Kombajn K2 = new Kombajn(280, 500000, "Łoooho oho", "Kombajn");
- ursus.Start();
- johndeer.Start();
- K1.Start();
- K2.Stop();
- List<Maszyna> Parking = new List<Maszyna>();
- Parking.Add(ursus);
- Parking.Add(johndeer);
- Parking.Add(K1);
- Parking.Add(K2);
- for (int i = 0; i < Parking.Count; i++)
- {
- Console.WriteLine(Parking[i].Podaj());
- }
- Console.ReadKey();
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement