- 2
Do you guys know the solution for this question.. As Iam stuck in iterating the hashmap..
You are creating a bowling game! The given code declares a Bowling class with its constructor and addPlayer() method. Each player of the game has a name and points, and are stored in the players HashMap. The code in main takes 3 players data as input and adds them to the game. You need to add a getWinner() method to the class, which calculates and outputs the name of the player with the maximum points. Sample Input: Dave 42 Amy 103 Rob 64 Sample Output: Amy
17 ответов
+ 11
zaid When referring to the "word of key", "key name", "value of key", and "name of key"... it can get a bit confusing. 😉
Let's consider the following pseudo example of key value pairs for a HashMap:
[
{ key: "May", value: 31 },
{ key: "Jun", value: 30 },
{ key: "Jul", value: 31 },
{ key: "Aug", value: 31 }
]
Here, the months are used for the HashMap keys and # of days per month are the HashMap values.
I think you're asking how to get the HashMap key.
If so, the code already references the HashMap key.
So, it's really unclear (to me) what you're actually asking.
+ 7
Why you have shared someone else code rather than yours in description? 🤔
+ 6
native buckeye You should lay off the shrooms when trying to post answers. Your responses read like a machine learning exercise gone bad for building a new kind of Ipsum Lorem generator.
Please stop and remove these posts. I really don't want to break my streak for the longest period since deactivating an account.
So... please just self moderate yourself. 🙏😉👌
+ 3
zaid , on line 16 what is "po" in if statement?
+ 2
//i did so
public void getWinner(){
String nome="";
int max=-1;
for(String key:players.keySet()){
if(players.get(key)>max){
max=players.get(key);
nome=key;
}
}
System.out.println(nome);
}
+ 1
https://code.sololearn.com/cbYtrar82YzR/?ref=app
What I have done so far
0
Sorry that has came by mistake.. So have you seen my code.. Any idea?
0
♾ D ♾ please check my code..
0
zaid Where have you used HashMaps? Change Maps to HashMaps
0
Atul changed to hashmap but getting error
0
Ciro Pellegrino will try
0
♾ D ♾ points
0
Ciro Pellegrino bro your code works..
0
Ciro Pellegrino bro if we want the word of key in hashmap then how can we get the key name.. The above code will get the value of key.. What if we want the name of key.. Please let me know.
0
Hello zaid,
What error do you have when you execute the code?
I’m not sure if I get the same error as you with your code.
In any case, the logic that you have used is the same one I applied too. (Although I didn’t modify the main(), but it should work anyways)
So maybe it is just a little detail in the way you have written it (compilation error )
0
Write a java program that reads integers continuously, until the user enters -1. Then, the
program should display the largest positive and the minimum negative input numbers. if the user doesn't
enter any positive or negative, the program should display an informative message. (Note: zero is counted
as neither a positive or nor negative number.)
Can someone help me make a code for this?
0
For loop through HashMap and check current player have greater points than older player. After ending loop you will get max points player