Jump to content

3 questions: Would I use an Array or HashTable for them?

- - - - -

This topic has been archived. This means that you cannot reply to this topic.
3 replies to this topic

#1
Treymac

Treymac

    Newbie

  • Members
  • Pip
  • 3 posts
Hey guys, new here.
I'm studying for my java final and we were given 3 questions about where an Array or HashTable would apply. If you guys could give me your thoughts on what would apply I would appreciate it.

1) Ship has-man Deck, where the number and arrangement of decks can not change after the ship is built.

I think it would an Array, since the number of decks can't be changed. (right?/any other comments on this one)

2) Ship has-man Passenger, where the ship's booking manager needs to be able to add new passengers, and print out the current passenger list in alphabetical order, whenever she wants to.

I think it would be a HashTable because new passengers need to be added, but as for the sorting, does that matter either way? (right?/any other comments on this one)

3) Ship has-many Stateroom, where the ship's steward needs to be able to enter a stateroom identifier at a terminal, and get back the names and ages of the people currently occupying that room.

I think it would be a HashTable because the steward needs to access a specific room. Also, it would be a HashTable because the identifier would be the key, and the names and ages could be from a person object that the key refers to? (right?/any other comments on this one)

Thanks a lot guys for any help at all.:cool:

#2
gszauer

gszauer

    Programmer

  • Members
  • PipPipPipPip
  • 113 posts
1, Array
2, Hash Table / Vector Object
3, Array (Multidimentional / Associative aka. Map)

~Aristotle said:

It is the mark of an educated mind to entertain a tought without accepting it
If my post was helpful, please help me build some rep Posted Image

#3
Treymac

Treymac

    Newbie

  • Members
  • Pip
  • 3 posts
Awesome, thanks for the help. I ended up with 100% on my final :D

#4
gszauer

gszauer

    Programmer

  • Members
  • PipPipPipPip
  • 113 posts
:D Glad to help.

~Aristotle said:

It is the mark of an educated mind to entertain a tought without accepting it
If my post was helpful, please help me build some rep Posted Image