class BankAccount {
private String firstname;
private String lastname;
private int ssn;
private int accountnumber = 0;
private double accountbala
Every answer so far is correct and points out problems. Here is one that is not yet mentioned.
Your equals
method does not properly over-ride the parent:
public boolean equals(BankAccount ba) {
return this.accountbalance == ba.accountbalance;
}
The signature of equals
on Object
is public boolean equals(Object other)
so that any objects can be compared to each other. You have changed it to only allow comparing against other BankAccounts, which violates the contract.
Try this instead:
public boolean equals(BankAccount ba) {
if (ba instanceof BankAccount) {
return this.accountbalance == ((BankAccount) ba).accountbalance;
}
else {
return false;
}
}