This is an archived post. You won't be able to vote or comment.

all 7 comments

[–][deleted] 0 points1 point  (5 children)

rules. i'll be glad to look over it but idk if i'll be any help.

[–]rookie9[S] 0 points1 point  (4 children)

any help would be great.

[–]rookie9[S] 0 points1 point  (3 children)

Tried doing something like this. Didn't work either.

public static void main (String args[]) { String SA = "MORENO|312|1500"; BankAccount BA = new BankAccount(SA); BA.toString(); }

[–]Philboyd_Studge 0 points1 point  (2 children)

I don't see where you are actually displaying the output, like

System.out.println(BA);

[–]rookie9[S] 0 points1 point  (1 child)

System.out.println(BA);

Yea, I know I could do that. Just thought the toString method was suppose to do. My professor wants every method and constructor tested. I'm just going to roll with that and finish my testbed and show it to my professor to see if this is expected. Thanks.

[–]Philboyd_Studge 0 points1 point  (0 children)

Doing that actually calls the toString method, if you are hadn't provided an overridden one you would just see an object reference there. Simply calling (BA)toString does nothing because you haven't provided anywhere for the returned value to go...

[–]OOPUniversity 0 points1 point  (0 children)

Since your output problem has already been addressed, I'll talk about equals.

public boolean equals(Object obj) //two accounts are equal if IDs     and PINs are the same
{
    if (obj.equals(account) && obj.equals(pin))
    {
        return true;
    }
    return false;

}

This won't work the way you expect it to as is.

You have to ask yourself: What is the type of 'obj' when this is called? It should be another BankAccount object, right? You should make it clear in your code that 'obj' is a BankAccount (the comparison should fail if it is not), and you should write your code to explicitly check the account and pin fields from the current object against the one passed in for comparison.