Advertisement
Guest User

Untitled

a guest
Oct 20th, 2019
91
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 8.39 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 CryptoMiningSystem
  8. {
  9. public class PCController
  10. {
  11. private static List<User> users = new List<User>();
  12. public decimal totalProfit = 0;
  13. public string RegisterUser(List<string> args)
  14. {
  15. if (users.Count() != 0)
  16. if (users.Count(x => x.Name == args[0]) != 0) return $"Username: { args[0]} already exists!";
  17. users.Add(new User(args[0], decimal.Parse(args[1])));
  18. return $"Successfully registered user - {args[0]}";
  19. }
  20.  
  21.  
  22.  
  23. public string CreateComputer(List<string> args)
  24. {
  25. Processor processor;
  26. VideoCard videoCard;
  27. if (users.Count(x => x.Name == args[0]) == 0) return $"Username: {args[0]} does not exist!";
  28. User user = users.FirstOrDefault(x => x.Name == args[0]);
  29. if (args[1] == "Low") processor = new LowPerformanceProcessor(args[2], int.Parse(args[3]), decimal.Parse(args[4]));
  30. else if (args[2] == "High") processor = new HighPerformanceProcessor(args[2], int.Parse(args[3]), decimal.Parse(args[4]));
  31. else return "Invalid type processor!";
  32. if (args[5] == "Game") videoCard = new GameVideoCard(args[6], int.Parse(args[7]), int.Parse(args[8]), decimal.Parse(args[9]));
  33. else if (args[5] == "Mine") videoCard = new MineVideoCard(args[6], int.Parse(args[7]), int.Parse(args[8]), decimal.Parse(args[9]));
  34. else return "Invalid type video card!";
  35. if (user.Money < processor.Price + videoCard.Price) return $"User: {args[0]} - insufficient funds!";
  36. user.Computer = new Computer(processor, videoCard, int.Parse(args[10]));
  37. return $"Successfully created computer for user: {args[0]}!";
  38.  
  39. /*
  40. name – символен низ
  41. processorType – символен низ
  42. processorModel – символен низ
  43. processorGeneration – цяло число
  44. processorPrice – реално число
  45. videoCardType – символен низ
  46. videoCardModel – символен низ
  47. videoCardGeneration – цяло число
  48. videoCardRam – цяло число
  49. videoCardPrice – реално число
  50. */
  51.  
  52. }
  53.  
  54.  
  55.  
  56. public string Mine()
  57. {
  58. decimal dailyProfit = 0;
  59. decimal userProfit = 0;
  60. foreach (var x in users)
  61. {
  62. {
  63. if (x.Computer != null)
  64. {
  65. userProfit += x.Computer.MinedAmountPerHour * 8;
  66. x.Computer.Processor.LifeWorkingHours -= 8;
  67. x.Computer.VideoCard.LifeWorkingHours -= 8;
  68. x.Money += userProfit; dailyProfit += userProfit;
  69. }
  70. }
  71. }
  72. //users.ForEach(x => { userProfit += x.Computer.MinedAmountPerHour * 8; x.Computer.Processor.LifeWorkingHours -= 8; x.Computer.VideoCard.LifeWorkingHours -= 8; x.Money += userProfit; dailyProfit += userProfit; });
  73. totalProfit += dailyProfit;
  74. return $"Daily profits: {dailyProfit}!";
  75. }
  76.  
  77.  
  78.  
  79. public string UserInfo(List<string> args)
  80. {
  81. if (users.Count(x => x.Name == args[1]) == 0) return $"Username: {args[0]} does not exist!";
  82. User user = users.FirstOrDefault(x => x.Name == args[1]);
  83. StringBuilder sb = new StringBuilder();
  84. sb.AppendLine($"Name: { user.Name} - Stars: { user.Stars}\nBalance: { user.Money}");
  85. Computer computer = user.Computer;
  86. 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");
  87. return sb.ToString();
  88. }
  89.  
  90. public string Shutdown()
  91. {
  92. string result = "";
  93. users.OrderByDescending(x => x.Stars).ThenBy(x => x.Name).ToList().ForEach(x => result += UserInfo(new List<string>() { "UserInfo", $"{x.Name}" }) + "\n");
  94. result += $"System total profits: {(int)totalProfit}!!!";
  95. return result;
  96. }
  97. }
  98. }
  99. /*
  100. * namespace CryptoMiningSystem.Core
  101. {
  102. using Contracts;
  103. using CryptoMiningSystem.Entities;
  104. using CryptoMiningSystem.Entities.Components.Processors;
  105. using CryptoMiningSystem.Entities.Components.VideoCards;
  106. using CryptoMiningSystem.Factories;
  107. using System.Collections.Generic;
  108. using System.Linq;
  109. using System.Text;
  110. using System;
  111.  
  112.  
  113. //To do...
  114. public class PCController
  115. {
  116. List<User> users = new List<User>();
  117. public decimal totalProfit=0;
  118. public string RegisterUser(List<string> args)
  119. {
  120. if (users.Count(x => x.Name == args[0]) != 0) return $"Username: { args[0]} already exists!";
  121. users.Add(new User(args[0], decimal.Parse(args[1])));
  122. return $"Successfully registered user - {args[0]}";
  123. }
  124.  
  125.  
  126.  
  127. public string CreateComputer(List<string> args)
  128. {
  129. Processor processor;
  130. VideoCard videoCard;
  131. if (users.Count(x => x.Name == args[1]) == 0) return $"Username: {args[0]} does not exist!";
  132. User user = users.FirstOrDefault(x => x.Name == args[1]);
  133. if (args[2] == "Low") processor = new LowPerformanceProcessor(args[3], int.Parse(args[4]), decimal.Parse(args[5]));
  134. else if (args[2] == "High") processor = new HighPerformanceProcessor(args[3], int.Parse(args[4]), decimal.Parse(args[5]));
  135. else return "Invalid type processor!";
  136. if (args[6] == "Game") videoCard = new GameVideoCard(args[7], int.Parse(args[8]), int.Parse(args[9]), decimal.Parse(args[10]));
  137. else if (args[6] == "Mine") videoCard = new MineVideoCard(args[7], int.Parse(args[8]), int.Parse(args[9]), decimal.Parse(args[10]));
  138. else return "Invalid type video card!";
  139. if (user.Money < processor.Price + videoCard.Price) return $"User: {args[0]} - insufficient funds!";
  140. user.Computer=new Computer(processor, videoCard, int.Parse(args[11]));
  141. return $"Successfully created computer for user: {args[1]}!";
  142.  
  143. /*
  144. name – символен низ
  145. processorType – символен низ
  146. processorModel – символен низ
  147. processorGeneration – цяло число
  148. processorPrice – реално число
  149. videoCardType – символен низ
  150. videoCardModel – символен низ
  151. videoCardGeneration – цяло число
  152. videoCardRam – цяло число
  153. videoCardPrice – реално число
  154.  
  155.  
  156. }
  157.  
  158.  
  159.  
  160. public string Mine()
  161. {
  162. decimal dailyProfit = 0;
  163. decimal userProfit = 0;
  164. users.ForEach(x => { userProfit += x.Computer.MinedAmountPerHour * 8; x.Computer.Processor.LifeWorkingHours -= 8; x.Computer.VideoCard.LifeWorkingHours -= 8; x.Money += userProfit; dailyProfit += userProfit; });
  165. totalProfit += dailyProfit;
  166. return $"Daily profits: {dailyProfit}!";
  167. }
  168.  
  169.  
  170.  
  171. public string UserInfo(List<string> args)
  172. {
  173. if (users.Count(x => x.Name == args[1]) == 0) return $"Username: {args[0]} does not exist!";
  174. User user = users.FirstOrDefault(x => x.Name == args[1]);
  175. StringBuilder sb = new StringBuilder();
  176. sb.AppendLine($"Name: { user.Name} - Stars: { user.Stars}\nBalance: { user.Money}");
  177. Computer computer = user.Computer;
  178. 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");
  179. return sb.ToString();
  180. }
  181.  
  182. public string Shutdown()
  183. {
  184. string result = "";
  185. users.OrderByDescending(x => x.Stars).ThenBy(x => x.Name).ToList().ForEach(x => result += UserInfo(new List<string>() { "UserInfo", $"{x.Name}" }) + "\n");
  186. result += $"System total profits: {(int)totalProfit}!!!";
  187. return result;
  188. }
  189. }
  190. }
  191. */
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement