1

I'm currently creating a simple taxi dispatch system for a java assignment.

the Taxi class contains the attribute platenumber.

I must have to create a hashmap that takes an area as a key and an ArrayList of taxi as the value. There are 6 different areas, and 50 unique Taxis(platenumber is what make them unique). each different area(key) is supposed to have a unique set of plates(or Taxis). and all areas are not to have more than 50 plates combined.

Now for my question,

Is there a way that I can access the object attribute (taxi plate number) within the the arraylist of taxi objects that is in the areas hashmap.

so,

areas.values()

will return my arraylist of Taxis

however I would like to get the plate number of the taxi objects that is in the taxi array list which is in the areas hashmap.

is this possible?

1 Answer 1

1

Is there a way that I can access the object attribute (taxi plate number) within the the arraylist of taxi objects that is in the areas hashmap.

Sure. To print the plate numbers for all taxis in a certain area, you would do:

List<Taxi> taxiesInArea = yourHashMap.get(area);

for (Taxi taxi : taxiesInArea)
    System.out.println(taxi.plateNumber());
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.