Advertisement
Guest User

Untitled

a guest
Nov 24th, 2014
134
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.82 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 zad_1
  8. {
  9. abstract class Maszyna
  10. {
  11. double moc;
  12. double cena;
  13. string opis;
  14. string typ;
  15. public abstract bool Jazda();
  16. public abstract void Stop();
  17. public abstract void Start();
  18.  
  19. public Maszyna(double moc, double cena, string opis, string typ)
  20. {
  21. this.moc = moc;
  22. this.cena = cena;
  23. this.opis = opis;
  24. this.typ = typ;
  25. }
  26. public Maszyna()
  27. {
  28. //NICZ
  29. }
  30. public string Podaj()
  31. {
  32. return typ + ", " + opis + ", " + moc + "KM, " + cena + "PLN";
  33. }
  34.  
  35. public int Porównaj(Maszyna m)
  36. {
  37. if (this.moc == m.moc) return 0;
  38. if (this.moc > m.moc)
  39. return -1;
  40. else
  41. return 1;
  42. }
  43. }
  44.  
  45. class Kombajn : Maszyna
  46. {
  47. bool CzyJedzie;
  48. public Kombajn(double moc, double cena, string opis, string typ)
  49. : base(moc, cena, opis, typ)
  50. {
  51. }
  52. public override void Start()
  53. {
  54. CzyJedzie = true;
  55. }
  56. public override void Stop()
  57. {
  58. CzyJedzie = false;
  59. }
  60. public override bool Jazda()
  61. {
  62. return CzyJedzie;
  63. }
  64. }
  65.  
  66. class Traktor : Maszyna
  67. {
  68. bool CzyJedzie;
  69. public Traktor(double moc, double cena, string opis, string typ)
  70. : base(moc, cena, opis, typ)
  71. {
  72. }
  73. public override void Start()
  74. {
  75. CzyJedzie = true;
  76. }
  77. public override void Stop()
  78. {
  79. CzyJedzie = false;
  80. }
  81. public override bool Jazda()
  82. {
  83. return CzyJedzie;
  84. }
  85. }
  86. class Program
  87. {
  88. static void Main(string[] args)
  89. {
  90. Traktor ursus = new Traktor(120, 150000, "Szybki jak dzik", "Traktor");
  91. Traktor johndeer = new Traktor(180, 2150000, "Drogi mocno", "Traktor");
  92.  
  93. Kombajn K1 = new Kombajn(330, 1500000, "Łoooho", "Kombajn");
  94. Kombajn K2 = new Kombajn(280, 500000, "Łoooho oho", "Kombajn");
  95.  
  96. ursus.Start();
  97. johndeer.Start();
  98.  
  99. K1.Start();
  100. K2.Stop();
  101.  
  102. List<Maszyna> Parking = new List<Maszyna>();
  103.  
  104. Parking.Add(ursus);
  105. Parking.Add(johndeer);
  106. Parking.Add(K1);
  107. Parking.Add(K2);
  108.  
  109. for (int i = 0; i < Parking.Count; i++)
  110. {
  111. Console.WriteLine(Parking[i].Podaj());
  112. }
  113.  
  114. Console.ReadKey();
  115. }
  116. }
  117. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement