Advertisement
Guest User

Untitled

a guest
Nov 21st, 2015
127
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 5.88 KB | None | 0 0
  1. using System;
  2.  
  3.  
  4. namespace _03.PC_Catalog
  5. {
  6. class Computer
  7. {
  8. private string name;
  9. private Components processor;
  10. private Components motherboard;
  11. private Components ram;
  12. private Components hdd;
  13. private Components graphicsCard;
  14. private decimal price;
  15. private int totalSum = 0;
  16.  
  17. public Computer(string name, Components processor, Components motherboard, Components ram, Components hdd, Components graphicsCard)
  18. {
  19. this.Name = name;
  20. this.Processor = processor;
  21. this.MotherBoard = motherboard;
  22. this.Ram = ram;
  23. this.Hdd = hdd;
  24. this.GraphicsCard = graphicsCard;
  25.  
  26.  
  27. }
  28. public Computer(string name, Components processor, Components ram, Components graphicsCard)
  29. :this(name, processor, null, ram, null, graphicsCard)
  30. {
  31.  
  32. }
  33. public string Name {
  34. get
  35. {
  36. return this.name;
  37. }
  38. set
  39. {
  40. if (string.IsNullOrEmpty(value))
  41. {
  42. throw new ArgumentException("You should type a name!");
  43. }
  44. else
  45. {
  46. this.name = value;
  47. }
  48. }
  49. }
  50. public Components Processor
  51. {
  52. get
  53. {
  54. return this.processor;
  55. }
  56. set
  57. {
  58.  
  59. this.processor = value;
  60.  
  61. }
  62. }
  63. public Components MotherBoard
  64. {
  65. get
  66. {
  67. return this.motherboard;
  68. }
  69. set
  70. {
  71.  
  72. this.motherboard = value;
  73.  
  74. }
  75. }
  76. public Components Ram
  77. {
  78. get
  79. {
  80. return this.ram;
  81. }
  82. set
  83. {
  84.  
  85. this.ram = value;
  86.  
  87. }
  88. }
  89. public Components Hdd
  90. {
  91. get
  92. {
  93. return this.hdd;
  94. }
  95. set
  96. {
  97.  
  98. this.hdd = value;
  99.  
  100. }
  101. }
  102. public Components GraphicsCard
  103. {
  104. get
  105. {
  106. return graphicsCard;
  107. }
  108. set
  109. {
  110.  
  111. this.graphicsCard = value;
  112.  
  113. }
  114. }
  115. public decimal Price
  116. {
  117. get
  118. {
  119. return totalSum;
  120. }
  121.  
  122. }
  123. public int TotalPrice()
  124. {
  125.  
  126.  
  127. if (processor != null)
  128. {
  129. totalSum += int.Parse(processor.ArraySight()[1]);
  130. }
  131. if (motherboard != null)
  132. {
  133. totalSum += int.Parse(motherboard.ArraySight()[1]);
  134. }
  135. if (ram != null)
  136. {
  137. totalSum += int.Parse(ram.ArraySight()[1]);
  138. }
  139. if (hdd != null)
  140. {
  141. totalSum += int.Parse(hdd.ArraySight()[1]);
  142. }
  143. if (graphicsCard != null)
  144. {
  145. totalSum += int.Parse(graphicsCard.ArraySight()[1]);
  146. }
  147. return totalSum;
  148. }
  149.  
  150. public void PrintComputer()
  151. {
  152. Console.WriteLine(name);
  153. if (processor != null)
  154. {
  155. if (processor.ArraySight().Length == 2)
  156. {
  157. Console.WriteLine("{0} - {1} lv", processor.ArraySight()[0], processor.ArraySight()[1]);
  158. }
  159. else
  160. {
  161. Console.WriteLine("{0} - {1} - {2} lv", processor.ArraySight()[0], processor.ArraySight()[1], processor.ArraySight()[2]);
  162. }
  163.  
  164. }
  165. if (motherboard != null)
  166. {
  167.  
  168. if (motherboard.ArraySight().Length == 2)
  169. {
  170. Console.WriteLine("{0} - {1} lv", motherboard.ArraySight()[0], motherboard.ArraySight()[1]);
  171. }
  172. else
  173. {
  174. Console.WriteLine("{0} - {1} - {2} lv", motherboard.ArraySight()[0], motherboard.ArraySight()[1], motherboard.ArraySight()[2]);
  175. }
  176. }
  177. if (ram != null)
  178. {
  179. if (ram.ArraySight().Length == 2)
  180. {
  181. Console.WriteLine("{0} - {1} lv", ram.ArraySight()[0], ram.ArraySight()[1]);
  182. }
  183. else
  184. {
  185. Console.WriteLine("{0} - {1} - {2} lv", ram.ArraySight()[0], ram.ArraySight()[1], ram.ArraySight()[2]);
  186. }
  187.  
  188. }
  189. if (hdd != null)
  190. {
  191. if (hdd.ArraySight().Length == 2)
  192. {
  193. Console.WriteLine("{0} - {1} lv", hdd.ArraySight()[0], hdd.ArraySight()[1]);
  194. }
  195. else
  196. {
  197. Console.WriteLine("{0} - {1} - {2} lv", hdd.ArraySight()[0], hdd.ArraySight()[1], hdd.ArraySight()[2]);
  198. }
  199.  
  200. }
  201. if (graphicsCard != null)
  202. {
  203. if (graphicsCard.ArraySight().Length == 2)
  204. {
  205. Console.WriteLine("{0} - {1} lv", graphicsCard.ArraySight()[0], graphicsCard.ArraySight()[1]);
  206. }
  207. else
  208. {
  209. Console.WriteLine("{0} - {1} - {2} lv", graphicsCard.ArraySight()[0], graphicsCard.ArraySight()[1], graphicsCard.ArraySight()[2]);
  210. }
  211. }
  212. Console.WriteLine(totalSum + "lv");
  213. }
  214. }
  215. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement