Advertisement
Guest User

Untitled

a guest
Oct 17th, 2019
94
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.81 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5.  
  6. namespace SpaceStationRecruitment
  7. {
  8. class SpaceStation
  9. {
  10. private Dictionary<string, Astronaut> data;
  11. public string Name { get; set; }
  12. public int Capacity { get; set; }
  13. public int Count
  14. {
  15. get
  16. {
  17. return this.data.Count;
  18. }
  19. }
  20.  
  21. public SpaceStation(string name, int capacity)
  22. {
  23. this.Name = name;
  24. this.Capacity = capacity;
  25. this.data = new Dictionary<string, Astronaut>(capacity);
  26. }
  27.  
  28. public void Add(Astronaut astronaut)
  29. {
  30. if (!data.ContainsKey(astronaut.Name) && data.Count < Capacity)
  31. {
  32. data.Add(astronaut.Name, astronaut);
  33. }
  34. }
  35.  
  36. public bool Remove(string name)
  37. {
  38. if (data.ContainsKey(name))
  39. {
  40. data.Remove(name);
  41. return true;
  42. }
  43. return false;
  44. }
  45.  
  46. public Astronaut GetOldestAstronaut()
  47. {
  48. return data.OrderByDescending(x => x.Value.Age).First().Value;
  49. }
  50.  
  51. public Astronaut GetAstronaut(string name)
  52. {
  53. if (data.ContainsKey(name))
  54. {
  55. return data[name];
  56. }
  57. return null;
  58. }
  59.  
  60. public string Report()
  61. {
  62. StringBuilder sb = new StringBuilder();
  63. sb.AppendLine($"Astronauts working at Space Station {this.Name}:");
  64. foreach (var astronaut in data)
  65. {
  66. sb.AppendLine(astronaut.Value.ToString());
  67. }
  68. return sb.ToString().TrimEnd();
  69. }
  70. }
  71. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement