public class Binary {
private int _DecNum;
private String _BinNum;
public Binary(int n) {
_DecNum = n;
_BinNum = ConvToBinR(n);
}
public static String ConvToBin(int n) {
String a = "";
while(n > 1) {
a = (n % 2) + a;
n = n /2;
}
return n + a;
}
public String toString() {
return _BinNum;
}
public boolean equals(Object a) {
return this == a || (a instanceof Binary && this._BinNum == ((Binary) a)._BinNum);
}
public static void main(String[] args ) {
int a = Integer.parseInt(args[0]);
int b = Integer.parseInt(args[1]);
Binary Zero = new Binary(a);
Binary One = new Binary(b);
System.out.println("Base 10: " + a + " in Base 2: " + Zero);
System.out.println(Zero.equals(One));
}
}
Hi Guys! My equals function does not work for some reason I can't figure out. this._BinNum == ((Binary) a)._BinNum; gives me a false statement even when I set the values of a and b to be equal. Can anyone help? Thank you!