-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathHouse.java
More file actions
165 lines (132 loc) · 3.87 KB
/
House.java
File metadata and controls
165 lines (132 loc) · 3.87 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
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
import java.util.ArrayList;
/**
*
* @author lucas
*/
public class House {
private Address address;
private Valeur valeur;
private int surface;
private byte sdb;
private byte otherRoom;
private byte totalRooms;
private boolean terrace;
private boolean balcon;
private ArrayList<HousePart> houseParts=new ArrayList<HousePart>();
private byte sdbCounter;
private byte oRCounter;
private byte balconCounter;
// Constructeurs
public House(byte otherRoom, byte sdb, int prix) {
//this.setOtherRoom(otherRoom);
//this.setSdb(sdb);
for (int i=0; i<otherRoom; i++) {
houseParts.add(new OtherRoom());
}
for (int i=0; i<sdb; i++) {
houseParts.add(new Sdb());
}
valeur= new Valeur(prix);
address = new Address();
countHouseParts();
}
public House(byte otherRoom, byte sdb, int prix, boolean terrace, boolean balcon) {
this(otherRoom,sdb,prix);
this.terrace=terrace;
this.balcon=balcon;
}
public House(byte otherRoom, byte sdb, int prix, String rue, String numero, String postCode, String commune) {
this(otherRoom, sdb, prix);
address.setRue(rue);
address.setNumero(numero);
address.setPostCode(postCode);
address.setCommune(commune);
}
public House(byte otherRoom, byte sdb, int prix, String rue,String numero, String postCode, String commune, String pays) {
this(otherRoom,sdb,prix,rue,numero,postCode,commune);
address.setPays(pays);
}
public String toString() {
return "Address: "+address.toString()+" // Total Rooms: "+(sdbCounter+oRCounter)+
" // Price To Pay: "+valeur.toString();
}
private void updateRooms() {
totalRooms = (byte) (sdb+otherRoom);
}
//setters ang getters
public void setSdb(byte sdb) {
if (sdb > 0) {
this.sdb = sdb;
updateRooms();
}else{
System.out.println("House should have at least 1 sdb");
}
}
public void setOtherRoom(byte otherRoom) {
if (otherRoom > 1) {
this.otherRoom = otherRoom;
updateRooms();
}else{
System.out.println("House should have at least 1 other room");
}
}
public void setSurface(int x, int y) {
if (x > 0 && y > 0) { surface =x*y; }else{ System.out.println("Error numbers invalid"); }
}
public void setTerrace(boolean terrace) {
this.terrace = terrace;
}
public void setBalcon(boolean balcon) {
this.balcon = balcon;
}
// operations on Address
public long actualValue(byte years) {
return valeur.actualiz(years, this.surface, this.balcon, this.terrace);
}
private void changeRue(String rue) {
address.setRue(rue);
}
private void changeNumero(String numero) {
address.setNumero(numero);
}
private void changeCommune(String commune) {
address.setCommune(commune);
}
private void changepostCode(String postCode) {
address.setPostCode(postCode);
}
private void changePays(String pays) {
address.setPays(pays);
}
public void changeAddress(String rue, String numero, String postCode, String commune) {
changeRue(rue);
changeNumero(numero);
changepostCode(postCode);
changeCommune(commune);
}
public void changeAddress(String rue, String numero, String postCode, String commune, String pays) {
changeAddress(rue,numero,postCode,commune);
changePays(pays);
}
// interface surface
public void askSurface() {
System.out.print("Choose x: ");
String xS = System.console().readLine();
System.out.print("Choose y: ");
String yS = System.console().readLine();
int x = Integer.parseInt(xS);
int y = Integer.parseInt(yS);
setSurface(x, y);
}
public int getPrice() {
return valeur.getToPay();
}
private void countHouseParts () {
for (int i=0; i<this.houseParts.size();i++) {
if (this.houseParts.get(i) instanceof Sdb) { sdbCounter += 1; }
else if (this.houseParts.get(i) instanceof OtherRoom){ oRCounter += 1; }
else if (this.houseParts.get(i) instanceof Balcon){ balconCounter += 1; }
//else if (this.houseParts.get(i) instanceof Jardin){ jardinCounter += 1; }
}
}
}