-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathSite.java
More file actions
106 lines (85 loc) · 2.09 KB
/
Copy pathSite.java
File metadata and controls
106 lines (85 loc) · 2.09 KB
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
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
public class Site extends Property {
private static int MAX_NUM_UNITS=5;
private int[] rentTable;
private ColourGroup colourGroup;
private int numBuildings;
private int buildPrice;
Site (String name, String shortName, int price, int mortgageValue, int[] rentTable, ColourGroup colourGroup, int buildPrice) {
super(name, price, shortName, mortgageValue);
this.rentTable = rentTable;
this.colourGroup = colourGroup;
this.buildPrice = buildPrice;
numBuildings = 0;
colourGroup.addMember(this);
return;
}
// METHODS DEALING WITH BUILDING UNITS (HOUSES AND HOTELS)
public boolean canBuild (int numToBuild) {
return (numBuildings+numToBuild)<=MAX_NUM_UNITS;
}
public void build (int numToBuild) {
if (canBuild(numToBuild)) {
numBuildings = numBuildings + numToBuild;
}
return;
}
public boolean canDemolish (int numToDemolish) {
return (numBuildings-numToDemolish)>=0;
}
public void demolish (int numToDemolish) {
if (canDemolish(numToDemolish)) {
numBuildings = numBuildings - numToDemolish;
}
}
public void demolishAll () {
numBuildings = 0;
return;
}
public int getNumBuildings () {
return numBuildings;
}
public int getBuildingPrice () {
return buildPrice;
}
public boolean hasBuildings () {
return numBuildings > 0;
}
public int getNumHouses () {
int numHouses;
if (numBuildings < 5) {
numHouses = numBuildings;
} else {
numHouses = 0;
}
return numHouses;
}
public int getNumHotels () {
int numHotels;
if (numBuildings == 5) {
numHotels = 1;
} else {
numHotels = 0;
}
return numHotels;
}
// METHODS DEALING WITH COLOUR GROUPS
public ColourGroup getColourGroup () {
return colourGroup;
}
// METHODS DEALING WITH RENT
public int getRent () {
int rent;
if (numBuildings==0 && super.getOwner().isGroupOwner(this)) {
rent = rentTable[0];
} else if (numBuildings==0 && super.getOwner().isGroupOwner(this)) {
rent = 2*rentTable[0];
} else {
rent = rentTable[numBuildings];
}
return rent;
}
// COMMON JAVA METHODS
public String toString () {
return super.toString();
}
}