From 231c0b6fbd54d73e29dd36f331ac45a19a115090 Mon Sep 17 00:00:00 2001 From: Thomas Smits Date: Thu, 15 Jun 2023 11:54:30 +0200 Subject: [PATCH] Update of exercises --- .../pr2/object/equals_hashcode/Wesen.java | 37 +++++++++++++++++++ 1 file changed, 37 insertions(+) diff --git a/sources/src/main/java/pr2/object/equals_hashcode/Wesen.java b/sources/src/main/java/pr2/object/equals_hashcode/Wesen.java index a40709d..424641c 100644 --- a/sources/src/main/java/pr2/object/equals_hashcode/Wesen.java +++ b/sources/src/main/java/pr2/object/equals_hashcode/Wesen.java @@ -26,4 +26,41 @@ public class Wesen { this.staerke = staerke; } + /** + * @see java.lang.Object#hashCode() + */ + @Override + public int hashCode() { + final int prime = 31; + int result = 1; + result = prime * result + ((name == null) ? 0 : name.hashCode()); + result = prime * result + staerke; + return result; + } + + /** + * @see java.lang.Object#equals(java.lang.Object) + */ + @Override + public boolean equals(Object obj) { + if (this == obj) { + return true; + } + if (obj == null) { + return false; + } + if (getClass() != obj.getClass()) { + return false; + } + Wesen other = (Wesen) obj; + if (name == null) { + if (other.name != null) { + return false; + } + } + else if (!name.equals(other.name)) { + return false; + } + return staerke == other.staerke; + } }