Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Text;
- namespace SpaceStationRecruitment
- {
- class SpaceStation
- {
- private Dictionary<string, Astronaut> data;
- public string Name { get; set; }
- public int Capacity { get; set; }
- public int Count
- {
- get
- {
- return this.data.Count;
- }
- }
- public SpaceStation(string name, int capacity)
- {
- this.Name = name;
- this.Capacity = capacity;
- this.data = new Dictionary<string, Astronaut>(capacity);
- }
- public void Add(Astronaut astronaut)
- {
- if (!data.ContainsKey(astronaut.Name) && data.Count < Capacity)
- {
- data.Add(astronaut.Name, astronaut);
- }
- }
- public bool Remove(string name)
- {
- if (data.ContainsKey(name))
- {
- data.Remove(name);
- return true;
- }
- return false;
- }
- public Astronaut GetOldestAstronaut()
- {
- return data.OrderByDescending(x => x.Value.Age).First().Value;
- }
- public Astronaut GetAstronaut(string name)
- {
- if (data.ContainsKey(name))
- {
- return data[name];
- }
- return null;
- }
- public string Report()
- {
- StringBuilder sb = new StringBuilder();
- sb.AppendLine($"Astronauts working at Space Station {this.Name}:");
- foreach (var astronaut in data)
- {
- sb.AppendLine(astronaut.Value.ToString());
- }
- return sb.ToString().TrimEnd();
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement