private Flat[] RemoveDuplicates(Flat[] flats) { int nonNullFlatCount = 0; foreach (var flat in flats) { if (flat != null) { nonNullFlatCount++; } } var filteredFlats = new Flat[nonNullFlatCount]; var currentIndex = 0; foreach (var flat in flats) { if (flat != null) { filteredFlats[currentIndex++] = flat; } } return(filteredFlats); }
public void AddFlat(Flat flat) { int stairway = GetStairway(flat.Id); int floor = GetFloor(stairway, flat.Id); flat.Stairway = stairway; flat.Floor = floor; Flats[FlatCount++] = flat; }
public House(int flatCount) { if (flatCount <= MAX_FLAT_COUNT) { Flats = new Flat[flatCount]; FlatCount = 0; } else { throw new Exception($"Cannot create a house with more than {MAX_FLAT_COUNT} flats"); } }
public Flat[] FilterByRoomCount(int roomCount) { var filteredFlats = new Flat[FlatCount]; for (int i = 0; i < FlatCount; i++) { if (Flats[i].RoomCount == roomCount) { filteredFlats[i] = Flats[i]; } } return(RemoveDuplicates(filteredFlats)); }
public Flat[] FilterByPrice(double price) { var filteredFlats = new Flat[FlatCount]; for (int i = 0; i < FlatCount; i++) { if (Flats[i].Price <= price) { filteredFlats[i] = Flats[i]; } } return(RemoveDuplicates(filteredFlats)); }
public Flat[] FilterByFloorInterval(int minFloor, int maxFloor) { var filteredFlats = new Flat[FlatCount]; for (int i = 0; i < FlatCount; i++) { if (Flats[i].Floor >= minFloor && Flats[i].Floor <= maxFloor) { filteredFlats[i] = Flats[i]; } } return(RemoveDuplicates(filteredFlats)); }
public House(Flat[] flats) { if (flats.Length <= MAX_FLAT_COUNT) { Flats = new Flat[flats.Length]; FlatCount = 0; foreach (var flat in flats) { AddFlat(flat); } } else { throw new Exception($"Cannot create a house with more than {MAX_FLAT_COUNT} flats"); } }