From 6a710c3943f2350f4575f8cb1898129ef3c7dfdd Mon Sep 17 00:00:00 2001 From: Sam Anthony Date: Thu, 28 Nov 2024 10:42:31 -0500 Subject: rename assignment code replica package --- src/main/java/derms/replica/replica2/City.java | 38 ++++++++++++++++++++++++++ 1 file changed, 38 insertions(+) create mode 100644 src/main/java/derms/replica/replica2/City.java (limited to 'src/main/java/derms/replica/replica2/City.java') diff --git a/src/main/java/derms/replica/replica2/City.java b/src/main/java/derms/replica/replica2/City.java new file mode 100644 index 0000000..b027d44 --- /dev/null +++ b/src/main/java/derms/replica/replica2/City.java @@ -0,0 +1,38 @@ +package derms.replica.replica2; + +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(); + } +} -- cgit v1.2.3