-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add Home interface, Cottage and Flat classes, add App class
Complete interfaces homework main task.
- Loading branch information
Showing
4 changed files
with
69 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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
26
java-oop-ru/interfaces/src/main/java/exercise/Cottage.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |