Advertisement
VickSuna

Untitled

Dec 5th, 2020
29
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.46 KB | None | 0 0
  1. using MortalEngines.Entities.Contracts;
  2. using System;
  3. using System.Collections.Generic;
  4. using System.Text;
  5.  
  6. namespace MortalEngines.Entities
  7. {
  8. public class Pilot : IPilot
  9. {
  10. private string name;
  11. private IList<IMachine> machines;
  12.  
  13. public Pilot(string name)
  14. {
  15. this.Name = name;
  16. this.machines = new List<IMachine>();
  17. }
  18.  
  19. public string Name
  20. {
  21. get
  22. {
  23. return this.name;
  24. }
  25. private set
  26. {
  27. if (string.IsNullOrWhiteSpace(value))
  28. {
  29. throw new ArgumentNullException("Pilot name cannot be null or empty string.");
  30. }
  31.  
  32. this.name = value;
  33. }
  34. }
  35.  
  36. public void AddMachine(IMachine machine)
  37. {
  38. if (machine == null)
  39. {
  40. throw new NullReferenceException("Null machine cannot be added to the pilot.");
  41. }
  42.  
  43. this.machines.Add(machine);
  44.  
  45. }
  46.  
  47. public string Report()
  48. {
  49. StringBuilder sb = new StringBuilder();
  50.  
  51. sb.AppendLine($"{this.Name} - {this.machines.Count} machines");
  52.  
  53. foreach (IMachine machine in this.machines)
  54. {
  55. sb.AppendLine(machine.ToString());
  56. }
  57.  
  58. return sb.ToString().TrimEnd();
  59. }
  60. }
  61. }
  62.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement