- 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

11th Jun 2021, 4:58 PM
zaid
zaid - avatar
17 odpowiedzi
+ 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.
12th Jun 2021, 3:01 AM
David Carroll
David Carroll - avatar
+ 7
Why you have shared someone else code rather than yours in description? 🤔
11th Jun 2021, 5:10 PM
D Shah 🎯⏳️
D Shah 🎯⏳️ - avatar
+ 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. 🙏😉👌
12th Jun 2021, 4:39 PM
David Carroll
David Carroll - avatar
+ 3
zaid , on line 16 what is "po" in if statement?
11th Jun 2021, 5:27 PM
D Shah 🎯⏳️
D Shah 🎯⏳️ - avatar
+ 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); }
11th Jun 2021, 5:27 PM
Ciro Pellegrino
Ciro Pellegrino - avatar
11th Jun 2021, 5:02 PM
zaid
zaid - avatar
0
Sorry that has came by mistake.. So have you seen my code.. Any idea?
11th Jun 2021, 5:13 PM
zaid
zaid - avatar
0
♾ D ♾ please check my code..
11th Jun 2021, 5:14 PM
zaid
zaid - avatar
0
zaid Where have you used HashMaps? Change Maps to HashMaps
11th Jun 2021, 5:16 PM
Atul [Inactive]
0
Atul changed to hashmap but getting error
11th Jun 2021, 5:22 PM
zaid
zaid - avatar
0
11th Jun 2021, 5:27 PM
zaid
zaid - avatar
0
♾ D ♾ points
11th Jun 2021, 5:28 PM
zaid
zaid - avatar
0
Ciro Pellegrino bro your code works..
11th Jun 2021, 5:36 PM
zaid
zaid - avatar
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.
11th Jun 2021, 5:38 PM
zaid
zaid - avatar
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 )
12th Jun 2021, 4:16 PM
NR Alberto
NR Alberto - avatar
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?
12th Jun 2021, 8:02 PM
Maricel Natural
Maricel Natural - avatar
0
For loop through HashMap and check current player have greater points than older player. After ending loop you will get max points player
13th Jun 2021, 5:08 AM
Java Developer
Java Developer - avatar