+ 5
You are creating a bowling game! The given code declares a Bowling class with its constructor and addPlayer() method. Each p
Bowls ng
18 Antworten
+ 26
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();
    }
}
+ 6
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() {
        int max = Collections.max(players.values());
        for (Map.Entry<String, Integer> entry : players.entrySet()) {
            if (entry.getValue().equals(max)) {
                System.out.println(entry.getKey());
            }
        }
    }
    
}
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();
    }
}
+ 4
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();
    }
}
+ 2
import java.util.*; 
//Please Subscribe to My Youtube Channel
//Channel Name: Fazal Tuts4U
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() {
        int max = Collections.max(players.values());
        for (Map.Entry<String, Integer> entry : players.entrySet()) {
            if (entry.getValue().equals(max)) {
                System.out.println(entry.getKey());
            }
        }
    }   
}
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();
    }
}
+ 2
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();
    }
}
+ 1
#trythis
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();
    }
}
+ 1
public class Bowling {
    HashMap<String, Integer> players;
    Bowling() {
        players = new HashMap<String, Integer>();
    }
    public void addPlayer(String name, int p) {
        players.put(name, p);
    }
    void getWinner(){ 
    int maxValue = Collections.max(players.values());
   
    String[] name = new String[players.size()];
    name = players.keySet().toArray(name);
    for (String v : name){
    if (players.get(v)<maxValue){
        players.remove(v);
        
    }
  
    } 
    String output = players.keySet().toString().replaceAll("(^\\[|\\]$)", "");
    System.out.println(output);    
    }     
    
    
    
}
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();
    }
}
0
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(){
        HashMap<String, Integer> hm = new HashMap<String, Integer>();
        Map.Entry<String, Integer> entryWithMaxValue = null;
        for (Map.Entry<String, Integer> currentEntry : hm.entrySet()) {
            if (entryWithMaxValue == null || currentEntry.getValue().compareTo(entryWithMaxValue.getValue()) > 0) {
                entryWithMaxValue = currentEntry;
            }
            
     }
     System.out.println(entryWithMaxValue.getKey());
    }
    
}
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();
            S
0
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(" ");
0
He
0
import java.util.*; 
import java.util.HashMap;
import java.util.Map.Entry;
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()
    {
        int max=Collections.max(players.values());
        for(Entry<String, Integer> entry: players.entrySet()) 
        {
            if(entry.getValue() == max) 
            {
                System.out.println(entry.getKey());
                break;
            }
        }
    }
}
0
//public void getWinner method
public void getWinner(){
        String[] nameArr = new String[players.size()];
        nameArr = players.keySet().toArray(nameArr);
        
        int score=0;
        String s="";
        for (String emp : nameArr){
          if(players.get(emp)>score){
            score=players.get(emp);
            s=emp;
          }
        }
        System.out.println(s);
    }
- 1
This is my solution so far but it's not correct it displays null pointer error
- 1
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 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();
    }
}
- 1
//your code goes here
    public void getWinner(){
        HashMap<String, Integer> hm = new HashMap<String, Integer>();
        Map.Entry<String, Integer> entryWithMaxValue = null;
        for (Map.Entry<String, Integer> currentEntry : hm.entrySet()) {
            if (entryWithMaxValue == null || currentEntry.getValue().compareTo(entryWithMaxValue.getValue()) > 0) {
                entryWithMaxValue = currentEntry;
            }
            
     }
     System.out.println(entryWithMaxValue.getKey());
    }
    
}
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();
- 2
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
- 3
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 String getWinner() {
        String winner = "";
        int highestPoints = 0;
        for (Map.Entry<String, Integer> entry : players.entrySet()) {
            if (entry.getValue() > highestPoints) {
                highestPoints = entry.getValue();
                winner = entry.getKey();
            }
        }
        return 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);
        }
        System.out.println(game.getWinner());
    }
}
- 3
Esteban L's solution is correct.



