So let's say I have following classes -- Game, Player, Results. I can add new players to a game via Game class. The Player class just contains some variables like name and age. Results class can for example start and stop a timer, and then get the result. Separate timers and results for each player.

What I need is a new Results object to be created each time I add a new player to my Game. So that later I can start and stop timer for each of my players.

So for example I create a new game:

Code:

Game game1 = new Game();

Then create a player and add it to my game:

Code:

Player player1 = new Player("John",21);
game1.addPlayer(player1); //Here a new Results object for player1 should be created.

How would I create a new Results object for each new player? After I've done so, how can I check results of a certain player?

I imagine it would look something like: (res1 would be a Results object that was created automatically in addPlayer method of Game class)

Good idea, but I forgot to mention that it's a school assignment and we get finished interfaces that we have to implement in those 3 classes. And all the functions like getResults() or start() are inside the Results interface and have to stay there.

04-17-2011, 05:37 PM

Fubarable

Another way to associate a single Results object with a single Player object is to add to your Game class a HashMap<Player, Result>. Please check out the tutorial for this. If you are going to go this route though, be sure that Player has both a decent hashcode method and equals method and that no two players can have different hashcodes yet still be equal.

04-17-2011, 05:41 PM

Marvin

Thanks, I guess it should be it since I missed a couple of lessons on collections, lists etc. I will look into it!