From 33e44ae807be01e73265c3445027b7921b285605 Mon Sep 17 00:00:00 2001 From: Kimberly Mageary Date: Fri, 9 May 2025 08:40:33 -0700 Subject: [PATCH] Finished the livecode! --- .../auberonedu/equalsLivecode/Centroid.java | 48 +++++++++++++++++++ 1 file changed, 48 insertions(+) diff --git a/src/main/java/io/github/auberonedu/equalsLivecode/Centroid.java b/src/main/java/io/github/auberonedu/equalsLivecode/Centroid.java index b0e343a..6d9ed97 100644 --- a/src/main/java/io/github/auberonedu/equalsLivecode/Centroid.java +++ b/src/main/java/io/github/auberonedu/equalsLivecode/Centroid.java @@ -1,5 +1,7 @@ package io.github.auberonedu.equalsLivecode; +import java.util.Objects; + public class Centroid { private int r; private int c; @@ -22,4 +24,50 @@ public int getC() { public String getName() { return name; } + + @Override + public int hashCode() { + int hash = 5; + hash = 73 * hash + this.r; + hash = 73 * hash + this.c; + hash = 73 * hash + Objects.hashCode(this.name); + return hash; + } + + @Override + public boolean equals(Object obj) { + if (this == obj) { + return true; + } + if (obj == null) { + return false; + } + if (getClass() != obj.getClass()) { + return false; + } + final Centroid other = (Centroid) obj; + if (this.r != other.r) { + return false; + } + if (this.c != other.c) { + return false; + } + return Objects.equals(this.name, other.name); + } + + // @Override + // public boolean equals(Object o){ + // if(o == null) return false; + + // if(getClass() != o.getClass()) return false; + // Centroid other = (Centroid) o; + // if(r!= other.r) return false; + // if(c != other.c) return false; + // if(name == null){ + // if(other.name == null) return true; + // if(other.name != null) return false; + // } + // if(!name.equals(other.name)) return false; + // return true; + // } }