-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathBuilding.java
More file actions
100 lines (89 loc) · 2.8 KB
/
Copy pathBuilding.java
File metadata and controls
100 lines (89 loc) · 2.8 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
/*
* Click nbfs://nbhost/SystemFileSystem/Templates/Licenses/license-default.txt to change this license
* Click nbfs://nbhost/SystemFileSystem/Templates/Classes/Class.java to edit this template
*/
package com.cs2212;
import java.util.*;
/**
* A Building represents a structure containing a number of Floors.
* Floors can be added to the building via the addFloor() method.
* The building maintains a List of Floors as well as a Map of Floors keyed by name.
*
* @author JOYZH
*/
public class Building {
private Map<String,List<Floor>> floors;
private List<Floor> array;
private String name;
private String address;
private Integer numFloors;
/**
* Constructs a new Building with the specified name, address, and number of floors.
* Initializes the floors map and array list.
* @param name the name of the building
* @param address the address of the building
* @param numFloors the number of floors in the building
*/
public Building(String name, String address, Integer numFloors) {
floors = new HashMap<>();
array = new ArrayList<>();
this.name = name;
this.address = address;
this.numFloors = numFloors;
}
/**
* Adds a Floor to the Building.
* The Floor is added to the List of Floors and the Map of Floors keyed by the Building's name.
* @param floor the Floor to add to the Building
*/
public void addFloor(Floor floor) {
array.add(floor);
floors.put(name,array);
}
/**
* Returns the Map of Floors keyed by the Building's name.
* @return the Map of Floors keyed by the Building's name
*/
public Map getFloors() {
return floors;
}
/**
* Returns the List of Floors.
* @return the List of Floors
*/
public List<Floor> getArray() {
return array;
}
/**
* Returns the number of floors in the Building.
* @return the number of floors in the Building
*/
public Integer getNumFloors() {
return this.numFloors;
}
/**
* Returns an Object array containing the numbers of the Floors in the Building.
* @return an Object array containing the numbers of the Floors in the Building
*/
public Object[] getFloorsArray() {
Object[] floorNum = new Object[array.size()];
for (int i=0; i<array.size(); i++) {
floorNum[i] = floors.get(name).get(i).getNumber();
}
return floorNum;
}
/**
* Returns the name of the Building.
* @return the name of the Building
*/
public String getName() {
return name;
}
/**
* Returns the address of the Building.
* @return the address of the Building
*/
public String getAddress() {
return address;
}
}