-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathHouse.pde
78 lines (74 loc) · 1.46 KB
/
House.pde
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
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
House[] apartments = new House[80];
House[] houses = new House[30];
public class House{
private int index;private int type;private int resident1;private int resident2 = -1;private int resident3 = -1;private int resident4 = -1;
public House(int aptNum,Islander r){
type = 1;
index = aptNum;
resident1 = r.getID();
}
public House(){
type = 1;
index = -1;
}
public House(int houseNum,Islander r1,Islander r2){
type = 2;
index = houseNum;
resident1 = r1.getID();
resident2 = r2.getID();
}
void addResident(Islander r){
if(resident3 == -1){
resident3 = r.getID();
}else{
resident4 = r.getID();
}
}
Islander aptResident(){
return getByID(resident1);
}
void delete(){
index = -1;
type = 0;
resident1 = -1;
resident2 = -1;
resident3 = -1;
}
boolean isOccupied(){
if(type == 0 || index == -1 || resident1 == -1){
return false;
}
return true;
}
int getType(){
return type;
}
int getIndex(){
return index;
}
}
House getAptByID(int id){
return apartments[id];
}
int nextAvailableApt(){
for(int i = 0; i < apartments.length; i++){
if(apartments[i] == null){
return i;
}
if(!apartments[i].isOccupied()){
return i;
}
}
return -1;
}
int nextAvailableHouse(){
for(int i = 0; i < houses.length; i++){
if(houses[i] == null){
return i;
}
if(!houses[i].isOccupied()){
return i;
}
}
return -1;
}