Advertisement
Guest User

Untitled

a guest
Jul 24th, 2019
156
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.31 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Text;
  4.  
  5. namespace SpaceStationRecruitment
  6. {
  7. class SpaceStation
  8. {
  9. public string Name { get; set; }
  10. public int Capacity { get; set; }
  11.  
  12. private List<Astronaut> data;
  13.  
  14. public SpaceStation(string Name, int Capacity)
  15. {
  16. this.Name = Name;
  17. this.Capacity = Capacity;
  18. data = new List<Astronaut>();
  19. }
  20.  
  21. public void Add(Astronaut astronaut)
  22. {
  23. if (Capacity > 0)
  24. {
  25. data.Add(astronaut);
  26. Capacity--;
  27. }
  28. }
  29.  
  30. public bool Remove(string name)
  31. {
  32. bool result = false;
  33. foreach (var item in data)
  34. {
  35. if (item.Name == name)
  36. {
  37. data.Remove(item);
  38. result = true;
  39. }
  40. }
  41. return result;
  42. }
  43.  
  44. public Astronaut GetOldestAstronaut()
  45. {
  46. int age = int.MinValue;
  47. foreach (var item in data)
  48. {
  49. if (item.Age >= age)
  50. {
  51. age = item.Age;
  52. }
  53. }
  54. var newAstronaut = new Astronaut("asaa", 1, "asasa");
  55. foreach (var item in data)
  56. {
  57. if (item.Age == age)
  58. {
  59. newAstronaut = item;
  60. }
  61. }
  62. return newAstronaut;
  63. }
  64.  
  65. public Astronaut GetAstronaut(string name)
  66. {
  67. var NewAstronaut = new Astronaut("Ivan", 0, "Plovdiv");
  68. foreach (var item in data)
  69. {
  70. if (item.Name == name)
  71. {
  72. NewAstronaut = item;
  73. }
  74. }
  75. return NewAstronaut;
  76. }
  77.  
  78. public int Count()
  79. {
  80. return data.Count;
  81. }
  82.  
  83. public string Report()
  84. {
  85. string result = $"Astronauts working at Space Station {Name}:\n";
  86. foreach (var item in data)
  87. {
  88. result += $"Astronaut: {item.Name}, {item.Age} ({item.Country})\n";
  89. }
  90. return result;
  91. }
  92. }
  93. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement