-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathApartmentComparison.java
32 lines (22 loc) · 991 Bytes
/
ApartmentComparison.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
import static java.lang.Math.abs;
public class Apartment {
private int rooms;
private int squareMeters;
private int pricePerSquareMeter;
public Apartment(int rooms, int squareMeters, int pricePerSquareMeter) {
this.rooms = rooms;
this.squareMeters = squareMeters;
this.pricePerSquareMeter = pricePerSquareMeter;
}
public boolean larger(Apartment otherApartment) {
return (this.squareMeters > otherApartment.squareMeters);
}
public int priceDifference(Apartment otherApartment) {
int firstValue = this.pricePerSquareMeter * this.squareMeters;
int secondValue = otherApartment.pricePerSquareMeter * otherApartment.squareMeters;
return abs(firstValue - secondValue);
}
public boolean moreExpensiveThan(Apartment otherApartment) {
return ((this.pricePerSquareMeter * this.squareMeters) > (otherApartment.pricePerSquareMeter * otherApartment.squareMeters));
}
}