示例#1
0
        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);
        }
示例#2
0
        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;
        }
示例#3
0
 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");
     }
 }
示例#4
0
        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));
        }
示例#5
0
        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));
        }
示例#6
0
        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));
        }
示例#7
0
        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");
            }
        }