diff options
| author | Sam Anthony <sam@samanthony.xyz> | 2024-11-23 13:51:12 -0500 |
|---|---|---|
| committer | Sam Anthony <sam@samanthony.xyz> | 2024-11-23 13:51:12 -0500 |
| commit | 3c62b863509131e78c18ed13c6b83e4fc508848f (patch) | |
| tree | cf246e91da283edf704af936b9cef7eb8e09a6f8 /src/main/java/derms/replica/replica1/City.java | |
| parent | e3b72053e8b04f2df013da0d7d49fe33927461a9 (diff) | |
| download | soen423-3c62b863509131e78c18ed13c6b83e4fc508848f.zip | |
import replica code from assignment
Diffstat (limited to 'src/main/java/derms/replica/replica1/City.java')
| -rw-r--r-- | src/main/java/derms/replica/replica1/City.java | 38 |
1 files changed, 38 insertions, 0 deletions
diff --git a/src/main/java/derms/replica/replica1/City.java b/src/main/java/derms/replica/replica1/City.java new file mode 100644 index 0000000..548f1fa --- /dev/null +++ b/src/main/java/derms/replica/replica1/City.java @@ -0,0 +1,38 @@ +package derms.replica.replica1; + +import java.io.Serializable; + +public class City implements Serializable { + public static final int codeLen = 3; + + private String code; + + public City(String code) throws IllegalArgumentException { + if (code.length() != codeLen) + throw new IllegalArgumentException("Invalid city: "+code+"; must be "+codeLen+" letters"); + this.code = code; + } + + public City() { + this("XXX"); + } + + @Override + public String toString() { + return code; + } + + @Override + public boolean equals(Object obj) { + if (obj == null || this.getClass() != obj.getClass()) { + return false; + } + City other = (City) obj; + return this.code.equals(other.code); + } + + @Override + public int hashCode() { + return code.hashCode(); + } +} |