vendredi 17 mai 2019

Why the CustomDate cannot be compared using .equals()? It always turn false

I have set a custom date class to manipulate the date entry from records. Then I need to compare the records with same name and the brithday, however, it keeps return false on the birthday arguments. Anyone could let me know what's the problem?

the program will need to match the record with exact name and birthday, then update the other fields in the record.

I have already tried .equals, compareTo, ==, i think it should be done with .equals but still fail, the name can return true but not the birthday.

        boolean found = false;

        for (donator a: donatorRecord) {
            if (a.getdonatorName().equals(temp.getdonatorName())) {
                if (a.getdonatorDOB().equals(temp.getdonatorDOB())) {
                if (temp.getdonatorAddress() != null) {
                    a.setdonatorAddress(temp.getdonatorAddress());
                }
                else if (temp.getdonatorPostcode() != null) {
                    a.setdonatorPostcode(temp.getdonatorPostcode());
                }
                else if (temp.getdonatorPhone() != null) {
                    a.setdonatorPhone(temp.getdonatorPhone());
                }
                found = true;
            }

            }
        }
        if(!found)
        {
            addDonator(temp);
            temp = new donator();
        }

now my result is the record has been created instead of update the existing one, if the name and birthday has been matched, the address, phone and postcode should be updated.

Aucun commentaire:

Enregistrer un commentaire