forked from jcrouser/CSC120-A6
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Building.java
37 lines (29 loc) · 1016 Bytes
/
Building.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
public class Building {
private String name = "<Name Unknown>";
private String address = "<Address Unknown>";
private int nFloors = 1;
public Building(String name, String address, int nFloors) {
if (name != null) { this.name = name; }
if (address != null) { this.address = address; }
if (nFloors < 1) {
throw new RuntimeException("Cannot construct a building with fewer than 1 floor.");
}
this.nFloors = nFloors;
}
public String getName() {
return this.name;
}
public String getAddress() {
return this.address;
}
public int getFloors() {
return this.nFloors;
}
public String toString() {
return this.name + " is a " + this.nFloors + "-story building located at " + this.address;
}
public static void main(String[] args) {
Building fordHall = new Building("Ford Hall", "100 Green Street Northampton, MA 01063", 4);
System.out.println(fordHall);
}
}