The Student Room Group

Creating a hashset of players

Hi all,

I need to create a hashset of 5 football teams with 11 of it's players. I was going to create 55 of these hashset's with the player name, team, position and stats (goals scored) (which will entail 200+ lines of code all together). Is their a quicker way of doing this just adding all the player together in one team or is the the best way is to do the hashset is separately for each player?
(edited 7 years ago)
Reply 1
Anyone? Tips and suggestions appreciated.
Reply 2
What programming language is this for? This task seems like an object oriented task so my guess would be Java as that's what most unis teach. Assuming this is a uni or college task.
Reply 3
This is Java, OOP. I know how to do the task, just wanted to know if their is a quicker way? Instead of writing one hashset of a player, his name and statistic and yet another hashset of the same thing and anoher all the way to 55 hashset's of player's name, team and position.

Thank you
Reply 4
Well the solution is to use some kind of loop. I used a for loop. Here's an example I wrote.

Here'a a GitHub gist I created to demonstrate my way of doing it.
https://gist.github.com/anonymous/a01c4c136768478dd763924e83d62ac8

Hope it helps. Ask any questions if you've got any.

Edit:
Now just add those objects to a HashSet which I forgot to do. Haha
(edited 7 years ago)
Thank you! Can you show me how to add those objects to a HashSet please?

Thank you
Reply 6
Original post by CompSci89
Thank you! Can you show me how to add those objects to a HashSet please?

Thank you


I regret posting my solution now. I feel like you will only c&p it.
Why don't you go to your tutor or reference this question from the materials given to you?
(edited 7 years ago)

Quick Reply

Latest