Skip to content

Commit

Permalink
submit java-oop-ru/interfaces
Browse files Browse the repository at this point in the history
  • Loading branch information
hexlet-cli committed Sep 25, 2024
1 parent 9d5cb1f commit 0b70f65
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 21 deletions.
23 changes: 9 additions & 14 deletions java-oop-ru/interfaces/src/main/java/exercise/App.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,23 +2,18 @@

import java.util.List;
import java.util.ArrayList;
import java.util.Collections;
import java.util.stream.Collectors;


public class App {
public static List<String> buildApartmentsList(List<Home> homes, int n) {
List<String> homesList = new ArrayList<>();

// Сортируем список объектов по площади по возрастанию
Collections.sort(homes);

// Берем первые n элементов
List<Home> firstHomes = homes.subList(0, Math.min(n, homes.size()));

// Создаем список строковых представлений объектов
for (Home home : firstHomes) {
homesList.add(home.toString());
}

return homesList;
return homes.stream()
.sorted((h1, h2) -> Double.compare(h1.getArea(), h2.getArea()))
.limit(n)
.map(Home::toString)
.collect(Collectors.toList());
}
}


2 changes: 1 addition & 1 deletion java-oop-ru/interfaces/src/main/java/exercise/Cottage.java
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,6 @@ public int compareTo(Home another) {

@Override
public String toString() {
return floorCount + "этажный коттедж площадью" + area + "метров";
return floorCount + " этажный коттедж площадью " + area + " метров";
}
}
3 changes: 1 addition & 2 deletions java-oop-ru/interfaces/src/main/java/exercise/Flat.java
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@ public int compareTo(Home another) {

@Override
public String toString() {
return "Квартира площадью" + this.getArea() + "метров на" + floor + "этаже";
return "Квартира площадью " + this.getArea() + " метров на " + floor + " этаже";
}

}
4 changes: 0 additions & 4 deletions java-oop-ru/interfaces/src/test/java/exercise/AppTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -55,8 +55,4 @@ void testBuildApartmentsList3() {
List<String> result = App.buildApartmentsList(apartments, 10);
assertThat(result).isEqualTo(expected);
}

// BEGIN

// END
}

0 comments on commit 0b70f65

Please sign in to comment.