Jump to content

Java delegates problem

- - - - -

  • Please log in to reply
1 reply to this topic

#1
mr_x

mr_x

    Newbie

  • Members
  • Pip
  • 1 posts
Hello I am new to this forum although I have used this site for some time.
I'm studying OOP and I need some help because I got stuck with the following task.
The code consists of several classes so I send it as attached file.
The problem is described in detail in document "READ" in MP2 file.
I do not expect to someone solve my task just some advice or clue
where I made ​​a mistake.
Thank you in advance.

Attached Files

  • Attached File  MP2.zip   14.2K   6 downloads


#2
Unkish

Unkish

    Newbie

  • Members
  • Pip
  • 5 posts
Hello,

The problem is indeed in Book class, but not only.

In Your Test class You are calling Book.equals method and passing in another Book instance as a parameter.

But in Your "mp2.part4.Book" class you're trying to compare ISBN to the passed in parameter, which should return false as in Your case.
If You'd compared Book.metod (ISBN) with arguments (Book's) ISBN, then it could produce right result (assuming two Book classes would be considered equal if their "metod" fields are equal).
There is a problem in "mp2.isbn.ISBN.equals" method which:
a. does not test for null
b. uses == for String comparison
((ISBN) o).isbn == isbn)
You should use equals for String comparison instead

The "mp2.part4.Book.equals" method should have additional checks like those in "mp2.isbn.ISBN.equals"

If You fix those then You should be fine.




1 user(s) are reading this topic

0 members, 1 guests, 0 anonymous users