-
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.
- Loading branch information
1 parent
35f01a2
commit ae1a330
Showing
7 changed files
with
137 additions
and
137 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 +1 @@ | ||
{"assignment":"java-oop-ru/classes-and-objects"} | ||
{"assignment":"java-oop-ru/interfaces"} |
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,15 +1,15 @@ | ||
package exercise; | ||
|
||
// 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 | ||
package exercise; | ||
|
||
// 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 |
62 changes: 31 additions & 31 deletions
62
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,31 +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 | ||
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,34 +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 | ||
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,8 +1,8 @@ | ||
package exercise; | ||
|
||
// BEGIN | ||
public interface Home { | ||
double getArea(); | ||
int compareTo(Home another); | ||
} | ||
// END | ||
package exercise; | ||
|
||
// BEGIN | ||
public interface Home { | ||
double getArea(); | ||
int compareTo(Home another); | ||
} | ||
// END |
62 changes: 31 additions & 31 deletions
62
java-oop-ru/interfaces/src/main/java/exercise/ReversedSequence.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,31 +1,31 @@ | ||
package exercise; | ||
|
||
// BEGIN | ||
public class ReversedSequence implements CharSequence{ | ||
private String sequence; | ||
public ReversedSequence(String sequence) { | ||
var reversedSequence = new StringBuilder(sequence); | ||
this.sequence = reversedSequence.reverse().toString(); | ||
} | ||
|
||
@Override | ||
public int length() { | ||
return this.sequence.length(); | ||
} | ||
|
||
@Override | ||
public char charAt(int index) { | ||
return this.sequence.toCharArray()[index]; | ||
} | ||
|
||
@Override | ||
public CharSequence subSequence(int start, int end) { | ||
return this.sequence.substring(start, end); | ||
} | ||
|
||
@Override | ||
public String toString() { | ||
return this.sequence; | ||
} | ||
} | ||
// END | ||
package exercise; | ||
|
||
// BEGIN | ||
public class ReversedSequence implements CharSequence{ | ||
private String sequence; | ||
public ReversedSequence(String sequence) { | ||
var reversedSequence = new StringBuilder(sequence); | ||
this.sequence = reversedSequence.reverse().toString(); | ||
} | ||
|
||
@Override | ||
public int length() { | ||
return this.sequence.length(); | ||
} | ||
|
||
@Override | ||
public char charAt(int index) { | ||
return this.sequence.toCharArray()[index]; | ||
} | ||
|
||
@Override | ||
public CharSequence subSequence(int start, int end) { | ||
return this.sequence.substring(start, end); | ||
} | ||
|
||
@Override | ||
public String toString() { | ||
return this.sequence; | ||
} | ||
} | ||
// END |
34 changes: 17 additions & 17 deletions
34
java-oop-ru/interfaces/src/test/java/exercise/ReversedSequenceTest.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,17 +1,17 @@ | ||
package exercise; | ||
|
||
import org.junit.jupiter.api.Test; | ||
|
||
import static org.junit.jupiter.api.Assertions.assertEquals; | ||
|
||
public class ReversedSequenceTest { | ||
CharSequence sequence = new ReversedSequence("abcdef"); | ||
|
||
@Test | ||
public void testReversedSequence() { | ||
assertEquals("fedcba", sequence.toString()); | ||
assertEquals('e', sequence.charAt(1)); | ||
assertEquals(6, sequence.length()); | ||
assertEquals("edc", sequence.subSequence(1, 4).toString()); | ||
} | ||
} | ||
package exercise; | ||
|
||
import org.junit.jupiter.api.Test; | ||
|
||
import static org.junit.jupiter.api.Assertions.assertEquals; | ||
|
||
public class ReversedSequenceTest { | ||
CharSequence sequence = new ReversedSequence("abcdef"); | ||
|
||
@Test | ||
public void testReversedSequence() { | ||
assertEquals("fedcba", sequence.toString()); | ||
assertEquals('e', sequence.charAt(1)); | ||
assertEquals(6, sequence.length()); | ||
assertEquals("edc", sequence.subSequence(1, 4).toString()); | ||
} | ||
} |