-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathAddress.java
More file actions
76 lines (62 loc) · 1.94 KB
/
Address.java
File metadata and controls
76 lines (62 loc) · 1.94 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
package onlinestore;
public class Address {
private String street;
private int houseNumber;
private String city;
private String country;
//Constructor
public Address(String street, int houseNumber, String city, String country) throws StringEmptyNullException,
IllegalArgumentException{
setStreet(street);
setHouseNumber(houseNumber);
setCity(city);
setCountry(country);
}
//Copy Constructor
public Address(Address other) {
this.street = other.street;
this.houseNumber = other.houseNumber;
this.city = other.city;
this.country = other.country;
}
public String getStreet() {
return street;
}
public void setStreet(String street) throws StringEmptyNullException {
if (street == null || street.isEmpty()) {
throw new StringEmptyNullException("street");
}
this.street = street;
}
public int getHouseNumber() {
return houseNumber;
}
public void setHouseNumber(int houseNumber) throws IllegalArgumentException {
if (houseNumber < 1) {
throw new IllegalArgumentException("House Number cannot be less than 1");
}
this.houseNumber = houseNumber;
}
public String getCity() {
return city;
}
public void setCity(String city) throws StringEmptyNullException {
if (city == null || city.isEmpty()) {
throw new StringEmptyNullException("city");
}
this.city = city;
}
public String getCountry() {
return country;
}
public void setCountry(String country) throws StringEmptyNullException {
if (country == null || country.isEmpty()) {
throw new StringEmptyNullException("Country");
}
this.country = country;
}
@Override
public String toString() {
return street + ", " + houseNumber + ", " + city + ", " + country;
}
}