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 Feb 5, 2024
1 parent 35f01a2 commit ae1a330
Show file tree
Hide file tree
Showing 7 changed files with 137 additions and 137 deletions.
2 changes: 1 addition & 1 deletion .current.json
Original file line number Diff line number Diff line change
@@ -1 +1 @@
{"assignment":"java-oop-ru/classes-and-objects"}
{"assignment":"java-oop-ru/interfaces"}
30 changes: 15 additions & 15 deletions java-oop-ru/interfaces/src/main/java/exercise/App.java
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 java-oop-ru/interfaces/src/main/java/exercise/Cottage.java
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
68 changes: 34 additions & 34 deletions java-oop-ru/interfaces/src/main/java/exercise/Flat.java
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
16 changes: 8 additions & 8 deletions java-oop-ru/interfaces/src/main/java/exercise/Home.java
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 java-oop-ru/interfaces/src/main/java/exercise/ReversedSequence.java
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
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());
}
}

0 comments on commit ae1a330

Please sign in to comment.