You are creating a bowling game! | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
0

You are creating a bowling game!

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

6th Jan 2021, 10:24 AM
Shaik Masthan
Shaik Masthan - avatar
13 Answers
0
Shaik Masthan Post your attempt first .
6th Jan 2021, 10:29 AM
Alphin K Sajan
Alphin K Sajan - avatar
0
Okay i will try
6th Jan 2021, 10:46 AM
Shaik Masthan
Shaik Masthan - avatar
6th Jan 2021, 11:05 AM
JaScript
JaScript - avatar
0
Thank you 🤗🤗
6th Jan 2021, 11:05 AM
Shaik Masthan
Shaik Masthan - avatar
0
The binary numeric system uses only two digits: 0 and 1. Computers operate in binary, meaning they store data and perform calculations using only zeros and ones. You need to make a program to convert integer numbers to their binary representation. Create a Converter class with a static toBinary() method, which returns the binary version of its argument. The code in main takes a number as input and calls the corresponding static method. Make sure the code works as expected. Sample Input: 42 Sample Output: 101010
6th Jan 2021, 11:07 AM
Shaik Masthan
Shaik Masthan - avatar
0
Can u help me to do this code
6th Jan 2021, 11:16 AM
Shaik Masthan
Shaik Masthan - avatar
0
public void getWinner() { String[] nameArr = new String[players.size()]; nameArr = players.keySet().toArray(nameArr); String topPlayer = nameArr[6]; int maxVal = players.get(nameArr[4]); for (String player : nameArr){ if(players.get(player) > maxVal) { topPlayer = player; maxVal = players.get(player); } } System.out.println(topPlayer); }
4th Feb 2021, 3:06 PM
Supi MazBis
0
package sololearnPracticeProject; /** * This class is used to implement BinaryConverter class * @author Shuvo * */ public class Converter { //creating a static string type method with parameter from main method static String toBinary(int x) { String binary=""; //initializing with user input variable from BinaryConverter int num = x ; //using loop to convert to binary while( num > 0) { //remember not to use "=>" due to infinit loop binary = (num%2)+binary; num /= 2; } return binary; //returning binary } }
20th Feb 2021, 4:01 AM
Md Rahman
Md Rahman - avatar
0
my solution 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[] nameArr = new String[players.size()]; nameArr = players.keySet().toArray(nameArr); String topPlayer = nameArr[1]; int maxVal = players.get(nameArr[0]); for (String player : nameArr){ if(players.get(player) > maxVal) { topPlayer = player; maxVal = players.get(player); } } System.out.println(topPlayer); } } 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 2021, 3:56 PM
BAIRRO DA MOITA
BAIRRO DA MOITA - avatar
0
public void getWinner() { String[] nameArr = new String[players.size()]; nameArr = players.keySet().toArray(nameArr); String topPlayer = nameArr[1]; int maxVal = players.get(nameArr[0]); for (String player : nameArr){ if(players.get(player) > maxVal) { topPlayer = player; maxVal = players.get(player); } } System.out.println(topPlayer); } can anyone explain me this code?
9th Jun 2021, 7:42 AM
Ankita Khandekar
Ankita Khandekar - avatar
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() { String[] nameArr = new String[players.size()]; nameArr = players.keySet().toArray(nameArr); String bestPlayer = nameArr[0]; int maxVal = players.get(nameArr[0]); for (String player : nameArr){ if(players.get(player) > maxVal) { bestPlayer = player; maxVal = players.get(player); } } System.out.println(bestPlayer); } } 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(); } }
3rd Aug 2021, 12:23 PM
Kasetty Husenaiah
- 1
import java.util.Scanner; abstract class Shape { int width; abstract void area(int c, int d); } //your code goes here class Square extends Shape { public void area(int a,int b) { System.out.println(a*a); System.out.print(Math.PI*b*b); } } public class Program { public static void main(String[ ] args) { Scanner sc = new Scanner(System.in); int x = sc.nextInt(); int y = sc.nextInt(); Square sq=new Square(); sq.area(x,y); } } this code is showing errors can u help Mee to do this code Alphin k sajan
6th Jan 2021, 10:30 AM
Shaik Masthan
Shaik Masthan - avatar
- 2
Can you help me to do this code
6th Jan 2021, 10:42 AM
Shaik Masthan
Shaik Masthan - avatar