+ 1

Pls someone help me with the answer

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 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(); } }

1st Apr 2022, 6:55 AM
MR KINGSHOW
MR KINGSHOW - avatar
3 odpowiedzi
+ 2
Try searching the forum by 'bowling game' search term. I just did, and saw a lot of similar questions.
1st Apr 2022, 7:21 AM
Ipang
+ 2
SoloProg thank you broo I'm so proud of guys
1st Apr 2022, 8:28 AM
MR KINGSHOW
MR KINGSHOW - avatar
+ 1
public void getWinner() { Iterator<String> p = players.keySet().iterator(); String key, keyWinner=""; Integer ValueWinner=0; while (p.hasNext()) { key = p.next(); if (keyWinner=="") { keyWinner=key; ValueWinner=players.get(key); } else { if (players.get(key)>ValueWinner) { keyWinner=key; ValueWinner=players.get(key); } } } System.out.println(keyWinner); } // Good Luck
1st Apr 2022, 8:20 AM
SoloProg
SoloProg - avatar