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
13 odpowiedzi
0
Shaik Masthan Post your attempt first .
0
Okay i will try
0
This will help you:
https://code.sololearn.com/cZmNH1Z7uXql/?ref=app
0
Thank you 🤗🤗
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
0
Can u help me to do this code
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);
}
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
}
}
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();
}
}
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?
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();
}
}
- 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
- 2
Can you help me to do this code