Assign object to another object?
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)
Code:
player1.res1.startTimer();
player1.res1.stopTimer();
player1.res1.getResults();
But I am not sure how it is done in Java.