Paul Clapham wrote:I'm not sure I understand your requirement. It sounds like you want the key of the map to be the player's name, and the value to be the player's score. Is that correct?
Dennis Deems wrote:You put a Player instance in the map at the start of the game. When you are printing the scores, I don't understand why you instantiate a new Player object and put that in the map instead. This looks highly suspicious to me. I would expect a single Player instance for each player to last for the duration of the game. I would expect that, whenever there is new information about a player -- for example, a change in the score -- that the code would go to the map, get the existing Player object and update it.
As Paul said, it would help if you explain to us more specifically what you are doing.
Raphael Onofre wrote:I advise you to see the keySet method to list the elements on the HashMap. I think, your code will be much more clear.
E.g.:
Sebanti Sanyal wrote:If player name is unique, the same can be used as the key,and solution becomes much simpler.
nick dimi wrote:Well,these days i wrote some more code for my program and the last for look like this :
but now in do-while i cant go to the next player...Can you help me one more time please?
Sebanti Sanyal wrote:
nick dimi wrote:Well,these days i wrote some more code for my program and the last for look like this :
but now in do-while i cant go to the next player...Can you help me one more time please?
I don't really understand the purpose of the do-while loop. 'for(String name:players.keySet())' will itself take you to the next player.
nick dimi wrote:Do you know how can i get the player with the highest score?
"Leadership is nature's way of removing morons from the productive flow" - Dogbert
Articles by Winston can be found here
I was born with webbed fish toes. This tiny ad is my only friend:
Gift giving made easy with the permaculture playing cards
https://coderanch.com/t/777758/Gift-giving-easy-permaculture-playing
|