This discussion is archived
4 Replies Latest reply: Mar 9, 2009 1:03 PM by 843785 RSS

Java Collection help

843785 Newbie
Currently Being Moderated
You must use a Java Collection object (not an array) to hold the Passengers and this must limit the number of passengers
either when the maximum seat number is reached (250 for this demo) or if the maximum weight is reached (21300).
An elegant way to do this would be to subclass the Collection class you choose and add extra functionality to it

I am new to java. Yes this is 1 minor part of a bigger scaled assignment. But the wording was a bit confusing. I just need a pointer in the right direction.

Im not sure if the paragraph is saying you can use an Arraylist in a collection class but then subclass and add extra functionality.

Any help(explanation) will be appreciated. can i use an arraylist?
  • 1. Re: Java Collection help
    3004 Newbie
    Currently Being Moderated
    xxbladexx wrote:
    Im not sure if the paragraph is saying you can use an Arraylist in a collection class but then subclass and add extra functionality.
    I don't know what you mean by "in" a collection class, since an ArrayList already IS a collection.

    But yes, you can subclass ArrayList, and use that as your collection.

    (However, I disagree with your teacher that this is elegant. I would prefer composition over inheritance. That is, define a new Collection implementation that delegates to, e.g., ArrayList. But that's outside the scope of what you're doing here. Just my $0.02.)
  • 2. Re: Java Collection help
    843785 Newbie
    Currently Being Moderated
    An elegant way to do this would be to subclass the Collection class you choose and add extra functionality to it
    I disagree with this wholeheartedly. A better way in my opinion would be to create a PassengerManifest class that is backed by an appropriate data structure (whatever best fits the requirements, but classes that interact with the PassengerManifest won't care which and wouldn't be able to tell anyway).

    ~
  • 3. Re: Java Collection help
    843785 Newbie
    Currently Being Moderated
    This same assignment was posted last week. The consensus was subclassing was a stupid idea, but hold yer nose and do it for the X-tra credz.
  • 4. Re: Java Collection help
    843785 Newbie
    Currently Being Moderated
    thanks for the pointers...

    really i already know who that is but hes gt more experience.lets hope the lecturer doesnt mind. Its good to get other ideas other than just his.