Laitofai

Untitled

May 16th, 2019
177
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 5.10 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Collections;
  4. using System.Linq;
  5. using System.Text;
  6. using System.Threading.Tasks;
  7.  
  8. namespace ConsoleApplication6
  9. {
  10. abstract class Equipment
  11. {
  12. public string Name { get; set; }
  13. public string ID { get; set; }
  14. public int CommissioningYear { get; set; }
  15. public int LifeTime { get; set; } // в годах
  16.  
  17. public Equipment(string Name, string ID, int CommissioningYear, int LifeTime)
  18. {
  19. this.Name = Name;
  20. this.ID = ID;
  21. this.CommissioningYear = CommissioningYear;
  22. this.LifeTime = LifeTime;
  23. }
  24.  
  25. public abstract bool IsOutdated();
  26. }
  27.  
  28. class Furniture : Equipment
  29. {
  30. public string Material { get; set; }
  31. public double Price;
  32.  
  33. public Furniture(string Name, string ID, int CommissioningYear, int LifeTime, string Material, double Price) : base(Name, ID, CommissioningYear, LifeTime)
  34. {
  35. this.Material = Material;
  36. this.Price = Price;
  37. }
  38.  
  39. public override bool IsOutdated()
  40. {
  41. if (CommissioningYear + LifeTime < DateTime.Today.Year)
  42. {
  43. return true;
  44. }
  45. else
  46. {
  47. return false;
  48. }
  49. }
  50. public double GetPrice()
  51. {
  52. if(IsOutdated())return Price / 2;
  53. else return Price;
  54. }
  55. }
  56.  
  57. class OfficeEquipment : Equipment
  58. {
  59. public string Specifications { get; set; }
  60. public string Type { get; set; }
  61.  
  62. public OfficeEquipment(string Name, string ID, int CommissioningYear, int LifeTime, string Specifications, string Type)
  63. : base(Name, ID, CommissioningYear, LifeTime)
  64. {
  65. this.Specifications = Specifications;
  66. this.Type = Type;
  67. }
  68.  
  69. public override bool IsOutdated()
  70. {
  71. int temp = 0;
  72. for (int i = CommissioningYear + 1; i < DateTime.Today.Year; i++)
  73. {
  74. if (i - CommissioningYear <= 3)
  75. {
  76. temp++;
  77. }
  78. else
  79. {
  80. temp += 2;
  81. }
  82. }
  83. if (temp > LifeTime)
  84. {
  85. return false;
  86. }
  87. else
  88. {
  89. return true;
  90. }
  91. }
  92. }
  93.  
  94. class SportEquipment : Equipment
  95. {
  96. public string KindOfSport { get; set; }
  97. private bool isValid = true;
  98.  
  99. public SportEquipment(string Name, string ID, int CommissioningYear, int LifeTime, string KindOfSport)
  100. : base(Name, ID, CommissioningYear, LifeTime)
  101. {
  102. this.KindOfSport = KindOfSport;
  103. }
  104.  
  105. public override bool IsOutdated()
  106. {
  107. if (isValid == false)
  108. {
  109. return false;
  110. }
  111. if (CommissioningYear + LifeTime < DateTime.Today.Year)
  112. {
  113. return true;
  114. }
  115. else
  116. {
  117. return false;
  118. }
  119. }
  120.  
  121. public void ToDead()
  122. {
  123. isValid = false;
  124. }
  125. }
  126.  
  127. class Tabel
  128. {
  129. ArrayList list = new ArrayList();
  130.  
  131. public void AddRecord(Equipment eq)
  132. {
  133. list.Add(eq);
  134. }
  135.  
  136. public void PrintAllRecords()
  137. {
  138. Console.WriteLine("{0, -15}{1, -40}{2, -15}", "ID", "Имя", "Статус");
  139. foreach (Equipment eq in list)
  140. {
  141. if (eq.IsOutdated() == true)
  142. {
  143. Console.WriteLine("{0, -15}{1, -40}{2, -15}", eq.ID, eq.Name, "Устарел");
  144. }
  145. else
  146. {
  147. Console.WriteLine("{0, -15}{1, -40}{2, -15}", eq.ID, eq.Name, "Годен");
  148. }
  149. }
  150. }
  151. }
  152.  
  153. class Program
  154. {
  155. static void Main(string[] args)
  156. {
  157. Tabel tabel = new Tabel();
  158. tabel.AddRecord(new OfficeEquipment("Стол", "ASD3154AF", 2010, 8, "Столик", "Это стол"));
  159. tabel.AddRecord(new OfficeEquipment("Стул", "ASD31523F", 2014, 8, "Стулик", "Это стул"));
  160. tabel.AddRecord(new OfficeEquipment("Кулер", "ASNS154AF", 2015, 6, "Кулик", "Это кулер"));
  161. tabel.AddRecord(new OfficeEquipment("Стол", "AS63554AF", 2017, 3, "Столик", "Это стол"));
  162.  
  163. tabel.AddRecord(new SportEquipment("Бита", "BASF2YGBH", 2010, 9, "Бейсбол"));
  164. tabel.AddRecord(new SportEquipment("Мяч", "435765235", 2018, 2, "Футбол"));
  165.  
  166. tabel.AddRecord(new Furniture("Диван", "158263529", 2013, 8, "Кожа"));
  167. tabel.AddRecord(new Furniture("Диван 2", "182536529", 2013, 3, "неКожа"));
  168. tabel.PrintAllRecords();
  169. Console.ReadKey();
  170. }
  171. }
  172. }
Advertisement
Add Comment
Please, Sign In to add comment