-
Notifications
You must be signed in to change notification settings - Fork 271
Expand file tree
/
Copy pathCampusMap.java
More file actions
50 lines (41 loc) · 1.51 KB
/
CampusMap.java
File metadata and controls
50 lines (41 loc) · 1.51 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
import java.util.ArrayList;
public class CampusMap {
ArrayList<Building> buildings;
/* Default constructor, initializes empty ArrayList */
public CampusMap() {
buildings = new ArrayList<Building>();
}
/**
* Adds a Building to the map
* @param b the Building to add
*/
public void addBuilding(Building b) {
System.out.println("Adding building...");
buildings.add(b);
System.out.println("-->Successfully added " + b.getName() + " to the map.");
}
/**
* Removes a Building from the map
* @param b the Building to remove
* @return the removed Building
*/
public Building removeBuilding(Building b) {
System.out.println("Removing building...");
buildings.remove(b);
System.out.println("-->Successfully removed " + b.getName() + " to the map.");
return b;
}
public String toString() {
String mapString = "DIRECTORY of BUILDINGS";
for (int i = 0; i < this.buildings.size(); i ++) {
mapString += "\n " + (i+1) + ". "+ this.buildings.get(i).getName() + " (" + this.buildings.get(i).getAddress() + ")";
}
return mapString;
}
public static void main(String[] args) {
CampusMap myMap = new CampusMap();
myMap.addBuilding(new Building("Ford Hall", "100 Green Street Northampton, MA 01063", 4));
myMap.addBuilding(new Building("Bass Hall", "4 Tyler Court Northampton, MA 01063", 4));
System.out.println(myMap);
}
}