Skip to content
Snippets Groups Projects
Commit 0e7da63a authored by Martin Vatshelle's avatar Martin Vatshelle
Browse files

Code for use in lecture

parent 1dd64a27
Branches master
No related tags found
No related merge requests found
package lecture8;
public class HashCode {
public static void main(String[] args) {
Pair p1 = new Pair(1, 4);
Pair p2 = new Pair(1, 4);
System.out.println(p1.equals(p2));
}
}
class Pair{
private int a;
private int b;
public Pair(int a, int b) {
this.a = a;
this.b = b;
}
public int getA() {
return a;
}
public void setA(int a) {
this.a = a;
}
public int getB() {
return b;
}
public void setB(int b) {
this.b = b;
}
@Override
public boolean equals(Object obj) {
if (this == obj)
return true;
if (obj == null)
return false;
if (obj instanceof Pair) {
Pair other = (Pair) obj;
return a == other.a && b == other.b;
}
else{
return false;
}
}
@Override
public String toString() {
return "("+a+","+b+")";
}
}
\ No newline at end of file
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment