Bookmark Topic Watch Topic
  • New Topic

Assigning an object to a field in another object  RSS feed

 
Jack Fletcher
Greenhorn
Posts: 13
  • Mark post as helpful
  • send pies
  • Report post to moderator
Hi guys,

I am making a mock system for a library where each User of the library is allowed to take out up to 3 books on loan.
The system should somehow assign the name of the User loaning the book out, in the object of the Book which is loaned.
So far I have a LinkedList which stores the Book objects and another to store the Users.
How do I go about assigning a Book to a User? I need to enable the user of the system to choose a User and then add their name to the String userBorrowing field in the Book object which is to be loaned.

Thanks.
 
K. Tsang
Bartender
Posts: 3648
16
Firefox Browser Java Mac OS X
  • Mark post as helpful
  • send pies
  • Report post to moderator
Have you considered using the "has-a" concept? Whether you have a Book inside the User class or have a User in the Book class, it's up to you. But each has different meaning.

To me, Book has User means this book is current rent to that user. User has Book can then mean this user currently borrowed that book.

Since your requirement mentions each user can have up to 3 books or vice versa, then a List or array is needed to store such info.

Hope this helps.
 
fred rosenberger
lowercase baba
Bartender
Posts: 12565
49
Chrome Java Linux
  • Likes 1
  • Mark post as helpful
  • send pies
  • Report post to moderator
Closed. Please follow up on this thread.
 
Don't get me started about those stupid light bulbs.
    Bookmark Topic Watch Topic
  • New Topic
Boost this thread!