-
Notifications
You must be signed in to change notification settings - Fork 8
/
ApartmentClass.java
35 lines (26 loc) · 910 Bytes
/
ApartmentClass.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
32
33
34
35
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){
if(this.squareMeters > otherApartment.squareMeters){
return true;
}else{
return false;
}
}
private int totalPrice(){
return pricePerSquareMeter * squareMeters;
}
public int priceDifference(Apartment otherApartment){
return Math.abs(this.totalPrice()-otherApartment.totalPrice());
}
public boolean moreExpensiveThan(Apartment otherApartment){
return this.totalPrice()>otherApartment.totalPrice();
}
}