-
Notifications
You must be signed in to change notification settings - Fork 21
/
House.java
60 lines (59 loc) · 2.24 KB
/
House.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
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
public class House extends Building implements MLSListable {
private Room[] rooms;
private int numberOfBathrooms;
public House(Room[] rooms, int numberOfBathrooms, int numberOfWindows, int numberOfFloors) {
super.setNumberOfFloors(numberOfFloors);
super.setNumberOfWindows(numberOfWindows);
this.numberOfBathrooms = numberOfBathrooms;
this.rooms = rooms;
//for-loop returns lenght of rooms
}
public String genRoomSpecs() {
String result = "";
for (int i = 0; i < rooms.length; i++) {
result += rooms[i].toString();
}
return result;
}
//Getters and Setters of Specs. of houses.
//Auto generate via Rt. Click + Source + Choose
//returns array number of rooms/bathrooms/size of each.
public Room[] getRooms() {
return rooms;
}
public void setRooms(Room[] rooms) {
this.rooms = rooms;
}
public int getNumberOfBathrooms() {
return numberOfBathrooms;
}
public void setNumberOfBathrooms(int numberOfBathrooms) {
this.numberOfBathrooms = numberOfBathrooms;
}
public int getAvgRoomSize() {
int result;
int sum = 0;
//for-loop returns calculated room sizes.
for (int i = 0; i < this.rooms.length; i++) {
sum += rooms[i].getLength() * rooms[i].getWidth();
}
result = sum / this.rooms.length;
return result;
}
//calculated getters/setters for size of houses
public String toString() {
String result = "Specifications of the House" + "\n\tRoom Size: " + this.getAvgRoomSize() + "\n\tBathrooms: "
+ this.getNumberOfBathrooms() + "\n\tFloors: " + this.getNumberOfFloors() + "\n\tWindows: "
+ this.getNumberOfWindows() + "\n\tRooms: " + this.rooms.length + this.genRoomSpecs() + "\n";
return result;
}
public String getMLSListing() {
return "MLSListing - " + this.toString();
}
}
//**MLSListable.java: I don't understand the error of the MLSListing**
//**"The public type MLSListable must be defined in its own file"**
//**I tried to difine it in own file but it wont let me run the program-so i left as-is***
public interface MLSListable {
public String getMLSListing();
}