Hello please I need some help with the bowling game project in java | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
+ 2

Hello please I need some help with the bowling game project in java

They tell me to search the Shashi for the winner with iteration but I keep getting this error <identifier> not found help me guys please

29th Nov 2020, 6:45 PM
Mehdi29
Mehdi29 - avatar
6 Answers
29th Nov 2020, 9:41 PM
JaScript
JaScript - avatar
+ 11
import java.util.*; public class Bowling { HashMap<String, Integer> players; Bowling() { players = new HashMap<String, Integer>(); } public void addPlayer(String name, int p) { players.put(name, p); } public void getWinner(){ String best=""; Iterator<Map.Entry<String,Integer>> it =players.entrySet().iterator(); int max=0; while(it.hasNext()){ String playerName=it.next().getKey(); Integer checkVal=players.get(playerName); if (checkVal>=max){ max=checkVal; best=playerName; } } System.out.println(best); } } public class Program { public static void main(String[ ] args) { Bowling game = new Bowling(); Scanner sc = new Scanner(System.in); for(int i=0;i<3;i++) { String input = sc.nextLine(); String[] values = input.split(" "); String name = values[0]; int points = Integer.parseInt(values[1]); game.addPlayer(name, points); } game.getWinner(); } }
13th Feb 2021, 7:39 PM
Esteban L
Esteban L - avatar
+ 3
Uhhh... I've finished the java course. No info. Hint: Try asking in StackOverflow or Quora
29th Nov 2020, 9:27 PM
OverdrivedProgrammer
0
JaScript Thanks so much, helped me figure out where i went wrong. followed.
11th Dec 2020, 11:12 PM
Chris Presnell
Chris Presnell - avatar
0
Your welcome. I am glad to hear that.
12th Dec 2020, 11:33 AM
JaScript
JaScript - avatar
0
Hello! This code runs but in Sololearn the test case 1, 2, and 4 show correct: test case 3 is x and locked test case 4 is checked correct however it is also locked. The program will not allow me to move forward: what am I missing in this code or is there a error in the program? Somebody anybody: Help!!!!! import java.util.*; public class Bowling { HashMap<String, Integer> players; Bowling() { players = new HashMap<String, Integer>(); } public void addPlayer(String name, int p) { players.put(name, p); } //your code goes here public void getWinner(){ String Winner = ""; int max = 0; players.put("John", 100); players.put("James", 55); players.put("Julie", 98); for(String name: players.keySet()){ if(players.get(name)>max){ Winner = name; max = players.get(name); } } System.out.println(Winner); } } public class Program{ public static void main(String[] args){ Bowling game = new Bowling(); Scanner sc = new Scanner(System.in); for(int i=0;i<3;i++) { String input = sc.nextLine(); String[] values = input.split(" "); String name = values[0]; int points = Integer.parseInt(values[1]); game.addPlayer(name, points); } game.getWinner(); } }
4th Jun 2022, 1:34 AM
Natalie Sequita Wilder
Natalie Sequita Wilder - avatar