I have to create an equals method that return true if the Politicians' titles are the same. How do I compare the strings?
This is how I've tried to write it so far:
public class Politician implements Priority{
private String name, title;
private int a;
public Politician(String n, String t, int p){
name=n;
title=t;
a=p;
}
public boolean equals(Politician a){
if(title.equals(a.title))
return true;
return false;
}
However, it just always return false. Even when I test:
Priority t4= new Politician("Arnie", "Governor", 4);
Politician t5= new Politician("Bill", "Governor", 10);
System.out.println(t5.equals(t4));
System.out.println(t4.equals(t5));
I've written equals() before and I don't know why it's not working anymore