From cbca68aa88cbc480ea56f4363b6013998b9f345f Mon Sep 17 00:00:00 2001 From: JesseChum Date: Tue, 25 Nov 2025 11:48:14 -0800 Subject: [PATCH] followed through livecode today. everything works --- .../github/auberonedu/equalsLivecode/App.java | 14 ++-- .../auberonedu/equalsLivecode/Centroid.class | Bin 0 -> 879 bytes .../auberonedu/equalsLivecode/Centroid.java | 67 ++++++++++++++++++ .../equalsLivecode/NamedCentroid.java | 5 ++ 4 files changed, 80 insertions(+), 6 deletions(-) create mode 100644 src/main/java/io/github/auberonedu/equalsLivecode/Centroid.class create mode 100644 src/main/java/io/github/auberonedu/equalsLivecode/NamedCentroid.java diff --git a/src/main/java/io/github/auberonedu/equalsLivecode/App.java b/src/main/java/io/github/auberonedu/equalsLivecode/App.java index 44717b0..82f6e03 100644 --- a/src/main/java/io/github/auberonedu/equalsLivecode/App.java +++ b/src/main/java/io/github/auberonedu/equalsLivecode/App.java @@ -11,13 +11,13 @@ public static void main(String[] args) { // To start, look at Centroid.java // BEFORE running the code, make a prediction of what the following will print: - Centroid locA = new Centroid(4, 9, "Salamander"); - Centroid locB = new Centroid(4, 9, "Salamander"); + // Centroid locA = new Centroid(4, 9, "Salamander"); + // Centroid locB = new Centroid(4, 9, "Salamander"); - System.out.println("Result of locA == locB " + (locA == locB)); - System.out.println("Result of locA.equals(locB) " + locA.equals(locB)); + // System.out.println("Result of locA == locB " + (locA == locB)); + // System.out.println("Result of locA.equals(locB) " + locA.equals(locB)); - //videoDemo(); + videoDemo(); } // We will look at this a bit later in the livecode, please ignore for first part @@ -87,11 +87,13 @@ public static void videoDemo() { Finder finder = new Finder(legend); Set salamanderLocations = finder.allLocations(video, "Salamander"); Set foodLocations = finder.allLocations(video, "Food"); - + //5 System.out.println("Number of locations the salamander visited " + salamanderLocations.size()); + //1 System.out.println("Number of locations the food was at " + foodLocations.size()); boolean hasOverlap = !Collections.disjoint(salamanderLocations, foodLocations); + //true System.out.println("Do the salamander locations overlap with the food locations: " + hasOverlap); } diff --git a/src/main/java/io/github/auberonedu/equalsLivecode/Centroid.class b/src/main/java/io/github/auberonedu/equalsLivecode/Centroid.class new file mode 100644 index 0000000000000000000000000000000000000000..a3ed8bbdfa047b38806a8a77435b01cd69ace121 GIT binary patch literal 879 zcmZuv-*3`T7(EvXE!d7S*l@DxoWDw$Yc%?_#h4IHNZ6K$nQ=Z9xWP_V6x#hUzWC_N z9$Ydo@xl1E#J|ZHPYYAFnC5<8zwe%VdcJe}^Y^#!0G`3lB7vj|MMny00rS8;a-E** zcb(nVfoul?=`GLqf+qq=tFo7YhK!1=jw{dw*1f*d^@6uy%W=b&9Q1wJ2_5+%bbG^w zcO={Wj&y3$4+ed&BOnG`^@w9mM=l}|?WoG@m`6cC@!dlyFyHv6q8SW4zq=X9T+p$I zl7QBgL9OQwhXMtwGJ}nqF?31CHI%7+B1K@qn!!yb+pO$ov4SNP*DuUH`JzC{s@G=@ zO@&nUD6__~1ab|}mpkDh=YHw7dh94v_98Z_J}GJfDtkNeSj7usr+flNGjQAQw%zwr zl5Ddd4%+g$7cm;==50il;3myV@Zyq;ya2u>A|K;S2boh4TsIh3S#5D&VJ_NVA?)%9 zs=YjdVc#FYJYipu5p*@hs1cdrlf@jl3uF~o!>uXP3bP<8WuHPl{(CeXH*<`){|hxP zLkoo7!Cl5xlFYK2UoNqh2;wbHp(h+ANyMA#8B)n(dyHb0YmBQOqq_P7+IFOEo$FJK zIEBH&I4{gIn5>ypG`MpJt*9Y87qGPKu4Nx literal 0 HcmV?d00001 diff --git a/src/main/java/io/github/auberonedu/equalsLivecode/Centroid.java b/src/main/java/io/github/auberonedu/equalsLivecode/Centroid.java index b0e343a..2f1dfaf 100644 --- a/src/main/java/io/github/auberonedu/equalsLivecode/Centroid.java +++ b/src/main/java/io/github/auberonedu/equalsLivecode/Centroid.java @@ -22,4 +22,71 @@ public int getC() { public String getName() { return name; } + + @Override + public int hashCode() { + final int prime = 31; + int result = 1; + result = prime * result + r; + result = prime * result + c; + // result = prime * result + ((name == null) ? 0 : name.hashCode()); + return result; + } + + @Override + public boolean equals(Object obj) { + if (this == obj) + return true; + if (obj == null) + return false; + if (getClass() != obj.getClass()) + return false; + Centroid other = (Centroid) obj; + if (r != other.r) + return false; + if (c != other.c) + return false; + // if (name == null) { + // if (other.name != null) + // return false; + // } else if (!name.equals(other.name)) + // return false; + return true; + } + + + + // @Override + // public boolean equals(Object o) { + // // is this equals to o? + // //ensure r, c, and name are all equal between this and o + // //ensure we meet java equals contract + // if(o == null) return false; + + // if(!this.getClass().equals(o.getClass())){ + // return false; + // } + + // Centroid other = (Centroid) o; + + // if(this.r != other.r) return false; + // if(this.c != other.c) return false; + + // if(this.name == null){ + // return other.name == null; + // // if(other.name == null){ + // //return true + // //} + // // else { //other.name is not null + // // return false; + // //} + // } + + // return this.name.equals(other.name); + // // if(!this.name.equals(other.name)){ + // // return false; + // // } else { + // // return true; + // // } + // } } diff --git a/src/main/java/io/github/auberonedu/equalsLivecode/NamedCentroid.java b/src/main/java/io/github/auberonedu/equalsLivecode/NamedCentroid.java new file mode 100644 index 0000000..46c5aef --- /dev/null +++ b/src/main/java/io/github/auberonedu/equalsLivecode/NamedCentroid.java @@ -0,0 +1,5 @@ +package io.github.auberonedu.equalsLivecode; + +public record NamedCentroid(String name, int r, int c) { + +}