Skip to content

Commit

Permalink
Add Home interface, Cottage and Flat classes, add App class
Browse files Browse the repository at this point in the history
Complete interfaces homework main task.
  • Loading branch information
JackKaif committed Feb 5, 2024
1 parent 0cbd317 commit 061d1d0
Show file tree
Hide file tree
Showing 4 changed files with 69 additions and 4 deletions.
13 changes: 10 additions & 3 deletions java-oop-ru/interfaces/src/main/java/exercise/App.java
Original file line number Diff line number Diff line change
@@ -1,8 +1,15 @@
package exercise;

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

// BEGIN
import java.util.List;

public class App {
public static List<String> buildApartmentsList(List<Home> apartments, int numOfElements) {
return apartments.stream()
.sorted(Home::compareTo)
.limit(numOfElements)
.map(Home::toString)
.toList();
}
}
// END
26 changes: 26 additions & 0 deletions java-oop-ru/interfaces/src/main/java/exercise/Cottage.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,31 @@
package exercise;

// BEGIN
import static java.lang.Math.signum;

public class Cottage implements Home{
private double area;
private int floor;

public Cottage(double area, int floor) {
this.area = area;
this.floor = floor;
}

public double getArea() {
return this.area;
}

public int compareTo(Home another) {
return (int) signum(this.getArea() - another.getArea());
}

@Override
public String toString() {
return this.floor +
" этажный коттедж площадью " +
this.getArea() +
" метров";
}
}
// END
29 changes: 29 additions & 0 deletions java-oop-ru/interfaces/src/main/java/exercise/Flat.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,34 @@
package exercise;

// BEGIN
import static java.lang.Math.signum;

public class Flat implements Home {
private double area;
private double balconyArea;
private int floor;

public Flat(double area, double balconyArea, int floor) {
this.area = area;
this.balconyArea = balconyArea;
this.floor = floor;
}

public double getArea() {
return this.area + this.balconyArea;
}

public int compareTo(Home another) {
return (int) signum(this.getArea() - another.getArea());
}

@Override
public String toString() {
return "Квартира площадью " +
this.getArea() +
" метров на " +
this.floor +
" этаже";
}
}
// END
5 changes: 4 additions & 1 deletion java-oop-ru/interfaces/src/main/java/exercise/Home.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
package exercise;

// BEGIN

public interface Home {
double getArea();
int compareTo(Home another);
}
// END

0 comments on commit 061d1d0

Please sign in to comment.