There equals()are some errors in your method , for example:
if(this == dollars && this == cents)
It will never be true ... it should be:
if(this.dollars == dollars && this.cents == cents)
But I will not make any efforts to code peers, it is recommended to auto-generate peers. Something like that:
@Override
public boolean equals(Object obj) {
if (this == obj)
return true;
if (obj == null)
return false;
if (getClass() != obj.getClass())
return false;
Currency other = (Currency) obj;
if (cents != other.cents)
return false;
if (dollars != other.dollars)
return false;
return true;
}
( , @AdriaanKoster), equals(), hashCode()
equals() :
, hashCode , , hashCode, , -.
-:
@Override
public int hashCode() {
final int prime = 31;
int result = 1;
result = prime * result + cents;
result = prime * result + dollars;
return result;
}