Advertisement
Guest User

Untitled

a guest
Oct 20th, 2019
79
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 12.44 KB | None | 0 0
  1. namespace CryptoMiningSystem.Core
  2. {
  3. using Contracts;
  4. using CryptoMiningSystem.Entities;
  5. using CryptoMiningSystem.Entities.Components.Processors;
  6. using CryptoMiningSystem.Entities.Components.VideoCards;
  7. using CryptoMiningSystem.Factories;
  8. using System.Collections.Generic;
  9. using System.Linq;
  10. using System.Text;
  11. using System;
  12.  
  13. public class PCController
  14. {
  15. private static List<User> users = new List<User>();
  16. public decimal totalProfit = 0;
  17. public string RegisterUser(List<string> args)
  18. {
  19. if (users.Count() != 0)
  20. if (users.Count(x => x.Name == args[0]) != 0) return $"Username: { args[0]} already exists!";
  21. users.Add(new User(args[0], decimal.Parse(args[1])));
  22. return $"Successfully registered user - {args[0]}!";
  23. }
  24.  
  25.  
  26.  
  27. public string CreateComputer(List<string> args)
  28. {
  29. Processor processor;
  30. VideoCard videoCard;
  31. if (users.Count(x => x.Name == args[0]) == 0) return $"Username: {args[0]} does not exist!";
  32. User user = users.FirstOrDefault(x => x.Name == args[0]);
  33. if (args[1] == "Low") processor = new LowPerformanceProcessor(args[2], int.Parse(args[3]), decimal.Parse(args[4]));
  34. else if (args[2] == "High") processor = new HighPerformanceProcessor(args[2], int.Parse(args[3]), decimal.Parse(args[4]));
  35. else return "Invalid type processor!";
  36. if (args[5] == "Game") videoCard = new GameVideoCard(args[6], int.Parse(args[7]), int.Parse(args[8]), decimal.Parse(args[9]));
  37. else if (args[5] == "Mine") videoCard = new MineVideoCard(args[6], int.Parse(args[7]), int.Parse(args[8]), decimal.Parse(args[9]));
  38. else return "Invalid type video card!";
  39. if (user.Money < processor.Price + videoCard.Price) return $"User: {args[0]} - insufficient funds!";
  40. user.Computer = new Computer(processor, videoCard, int.Parse(args[10]));
  41. return $"Successfully created computer for user: {args[0]}!";
  42.  
  43. /*
  44. name – символен низ
  45. processorType – символен низ
  46. processorModel – символен низ
  47. processorGeneration – цяло число
  48. processorPrice – реално число
  49. videoCardType – символен низ
  50. videoCardModel – символен низ
  51. videoCardGeneration – цяло число
  52. videoCardRam – цяло число
  53. videoCardPrice – реално число
  54. */
  55.  
  56. }
  57.  
  58.  
  59.  
  60. public string Mine()
  61. {
  62. decimal dailyProfit = 0;
  63. decimal userProfit = 0;
  64. foreach (var x in users)
  65. {
  66. {
  67. if (x.Computer != null)
  68. {
  69. userProfit += x.Computer.MinedAmountPerHour * 8;
  70. x.Computer.Processor.LifeWorkingHours -= 8;
  71. x.Computer.VideoCard.LifeWorkingHours -= 8;
  72. x.Money += userProfit; dailyProfit += userProfit;
  73. }
  74. }
  75. }
  76. //users.ForEach(x => { userProfit += x.Computer.MinedAmountPerHour * 8; x.Computer.Processor.LifeWorkingHours -= 8; x.Computer.VideoCard.LifeWorkingHours -= 8; x.Money += userProfit; dailyProfit += userProfit; });
  77. totalProfit += dailyProfit;
  78. return $"Daily profits: {dailyProfit}!";
  79. }
  80.  
  81.  
  82.  
  83. public string UserInfo(List<string> args)
  84. {
  85. if (users.Count(x => x.Name == args[1]) == 0) return $"Username: {args[0]} does not exist!";
  86. User user = users.FirstOrDefault(x => x.Name == args[1]);
  87. StringBuilder sb = new StringBuilder();
  88. sb.AppendLine($"Name: { user.Name} - Stars: { user.Stars}\nBalance: { user.Money}");
  89. Computer computer = user.Computer;
  90. if (computer != null) sb.AppendLine($"PC Ram: {computer.Ram}\n - { computer.Processor.GetType().Name} – { computer.Processor.Model} – { computer.Processor.Generation}\n - { computer.VideoCard.GetType().Name} – { computer.VideoCard.Model} – { computer.VideoCard.Generation}\n *Video card Ram: { computer.VideoCard.Ram}\n");
  91. return sb.ToString();
  92. }
  93.  
  94. public string Shutdown()
  95. {
  96. string result = "";
  97. users.OrderByDescending(x => x.Stars).ThenBy(x => x.Name).ToList().ForEach(x => result += UserInfo(new List<string>() { "UserInfo", $"{x.Name}" }) + "\n");
  98. result += $"System total profits: {(int)totalProfit}!!!";
  99. return result;
  100. }
  101. }
  102.  
  103. /*
  104. * namespace CryptoMiningSystem.Core
  105. {
  106. using Contracts;
  107. using CryptoMiningSystem.Entities;
  108. using CryptoMiningSystem.Entities.Components.Processors;
  109. using CryptoMiningSystem.Entities.Components.VideoCards;
  110. using CryptoMiningSystem.Factories;
  111. using System.Collections.Generic;
  112. using System.Linq;
  113. using System.Text;
  114. using System;
  115.  
  116.  
  117. //To do...
  118. public class PCController
  119. {
  120. List<User> users = new List<User>();
  121. public decimal totalProfit=0;
  122. public string RegisterUser(List<string> args)
  123. {
  124. if (users.Count(x => x.Name == args[0]) != 0) return $"Username: { args[0]} already exists!";
  125. users.Add(new User(args[0], decimal.Parse(args[1])));
  126. return $"Successfully registered user - {args[0]}";
  127. }
  128.  
  129.  
  130.  
  131. public string CreateComputer(List<string> args)
  132. {
  133. Processor processor;
  134. VideoCard videoCard;
  135. if (users.Count(x => x.Name == args[1]) == 0) return $"Username: {args[0]} does not exist!";
  136. User user = users.FirstOrDefault(x => x.Name == args[1]);
  137. if (args[2] == "Low") processor = new LowPerformanceProcessor(args[3], int.Parse(args[4]), decimal.Parse(args[5]));
  138. else if (args[2] == "High") processor = new HighPerformanceProcessor(args[3], int.Parse(args[4]), decimal.Parse(args[5]));
  139. else return "Invalid type processor!";
  140. if (args[6] == "Game") videoCard = new GameVideoCard(args[7], int.Parse(args[8]), int.Parse(args[9]), decimal.Parse(args[10]));
  141. else if (args[6] == "Mine") videoCard = new MineVideoCard(args[7], int.Parse(args[8]), int.Parse(args[9]), decimal.Parse(args[10]));
  142. else return "Invalid type video card!";
  143. if (user.Money < processor.Price + videoCard.Price) return $"User: {args[0]} - insufficient funds!";
  144. user.Computer=new Computer(processor, videoCard, int.Parse(args[11]));
  145. return $"Successfully created computer for user: {args[1]}!";
  146.  
  147. /*
  148. name – символен низ
  149. processorType – символен низ
  150. processorModel – символен низ
  151. processorGeneration – цяло число
  152. processorPrice – реално число
  153. videoCardType – символен низ
  154. videoCardModel – символен низ
  155. videoCardGeneration – цяло число
  156. videoCardRam – цяло число
  157. videoCardPrice – реално число
  158.  
  159.  
  160. }
  161.  
  162.  
  163.  
  164. public string Mine()
  165. {
  166. decimal dailyProfit = 0;
  167. decimal userProfit = 0;
  168. users.ForEach(x => { userProfit += x.Computer.MinedAmountPerHour * 8; x.Computer.Processor.LifeWorkingHours -= 8; x.Computer.VideoCard.LifeWorkingHours -= 8; x.Money += userProfit; dailyProfit += userProfit; });
  169. totalProfit += dailyProfit;
  170. return $"Daily profits: {dailyProfit}!";
  171. }
  172.  
  173.  
  174.  
  175. public string UserInfo(List<string> args)
  176. {
  177. if (users.Count(x => x.Name == args[1]) == 0) return $"Username: {args[0]} does not exist!";
  178. User user = users.FirstOrDefault(x => x.Name == args[1]);
  179. StringBuilder sb = new StringBuilder();
  180. sb.AppendLine($"Name: { user.Name} - Stars: { user.Stars}\nBalance: { user.Money}");
  181. Computer computer = user.Computer;
  182. if (computer != null) sb.AppendLine($"PC Ram: {computer.Ram}\n - { computer.Processor.GetType().Name} – { computer.Processor.Model} – { computer.Processor.Generation}\n - { computer.VideoCard.GetType().Name} – { computer.VideoCard.Model} – { computer.VideoCard.Generation}\n *Video card Ram: { computer.VideoCard.Ram}\n");
  183. return sb.ToString();
  184. }
  185.  
  186. public string Shutdown()
  187. {
  188. string result = "";
  189. users.OrderByDescending(x => x.Stars).ThenBy(x => x.Name).ToList().ForEach(x => result += UserInfo(new List<string>() { "UserInfo", $"{x.Name}" }) + "\n");
  190. result += $"System total profits: {(int)totalProfit}!!!";
  191. return result;
  192. }
  193. }
  194. }
  195. */
  196.  
  197. //To do...
  198. /* public class PCController
  199. {
  200. List<User> users = new List<User>();
  201. public decimal totalProfit=0;
  202. public string RegisterUser(List<string> args)
  203. {
  204. if(args.Count()!=3)throw new ArgumentOutOfRangeException("asd");
  205. if (users.Count(x => x.Name == args[0]) != 0) return $"Username: { args[0]} already exists!";
  206. users.Add(new User(args[0], decimal.Parse(args[1])));
  207. return $"Successfully registered user - {args[0]}";
  208. }
  209.  
  210.  
  211.  
  212. public string CreateComputer(List<string> args)
  213. {
  214. Processor processor;
  215. VideoCard videoCard;
  216. if (users.Count(x => x.Name == args[1]) == 0) return $"Username: {args[0]} does not exist!";
  217. User user = users.FirstOrDefault(x => x.Name == args[1]);
  218. if (args[2] == "Low") processor = new LowPerformanceProcessor(args[3], int.Parse(args[4]), decimal.Parse(args[5]));
  219. else if (args[2] == "High") processor = new HighPerformanceProcessor(args[3], int.Parse(args[4]), decimal.Parse(args[5]));
  220. else return "Invalid type processor!";
  221. if (args[6] == "Game") videoCard = new GameVideoCard(args[7], int.Parse(args[8]), int.Parse(args[9]), decimal.Parse(args[10]));
  222. else if (args[6] == "Mine") videoCard = new MineVideoCard(args[7], int.Parse(args[8]), int.Parse(args[9]), decimal.Parse(args[10]));
  223. else return "Invalid type video card!";
  224. if (user.Money < processor.Price + videoCard.Price) return $"User: {args[0]} - insufficient funds!";
  225. user.Computer=new Computer(processor, videoCard, int.Parse(args[11]));
  226. return $"Successfully created computer for user: {args[1]}!";
  227.  
  228. /*
  229. name – символен низ
  230. processorType – символен низ
  231. processorModel – символен низ
  232. processorGeneration – цяло число
  233. processorPrice – реално число
  234. videoCardType – символен низ
  235. videoCardModel – символен низ
  236. videoCardGeneration – цяло число
  237. videoCardRam – цяло число
  238. videoCardPrice – реално число
  239.  
  240.  
  241. }
  242.  
  243.  
  244.  
  245. public string Mine()
  246. {
  247. decimal dailyProfit =0;
  248. decimal userProfit = 0;
  249. users.ForEach(x => { userProfit += x.Computer.MinedAmountPerHour * 8; x.Computer.Processor.LifeWorkingHours -= 8; x.Computer.VideoCard.LifeWorkingHours -= 8;x.Money += userProfit;dailyProfit += userProfit; }) ;
  250. totalProfit += dailyProfit;
  251. return $"Daily profits: {dailyProfit}!";
  252. }
  253.  
  254.  
  255.  
  256. public string UserInfo(List<string> args)
  257. {
  258. if (users.Count(x => x.Name == args[1]) == 0) return $"Username: {args[0]} does not exist!";
  259. User user = users.FirstOrDefault(x => x.Name == args[1]);
  260. StringBuilder sb = new StringBuilder();
  261. sb.AppendLine($"Name: { user.Name} - Stars: { user.Stars}\nBalance: { user.Money}");
  262. Computer computer = user.Computer;
  263. if (computer != null) sb.AppendLine($"PC Ram: {computer.Ram}\n - { computer.Processor.GetType().Name} – { computer.Processor.Model} – { computer.Processor.Generation}\n - { computer.VideoCard.GetType().Name} – { computer.VideoCard.Model} – { computer.VideoCard.Generation}\n *Video card Ram: { computer.VideoCard.Ram}\n");
  264. return sb.ToString();
  265. }
  266.  
  267. public string Shutdown()
  268. {
  269. string result = "";
  270. users.OrderByDescending(x=>x.Stars).ThenBy(x=>x.Name).ToList().ForEach(x=>result+=UserInfo(new List<string>() { "UserInfo", $"{x.Name}" })+"\n");
  271. result += $"System total profits: {(int)totalProfit}!!!";
  272. return result;
  273. }
  274. }*/
  275. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement