Question: This is part of a bigger code, I need to find the order of playing, by rolling the dice. if a tie happens, those players
This is part of a bigger code, I need to find the order of playing, by rolling the dice. if a tie happens, those players have to roll again (not all players)
Can you help me debug the playerOrder method? it works fine in cases, but it mostly gives error (specially for the number of players = 4)
import java.util.ArrayList; import java.util.Collections; import java.util.HashMap; import java.util.List; import java.util.Map; import java.util.Random; import java.util.Scanner; import java.util.TreeMap;
public class Order { public static void main(String[] args) { Scanner keyboard = new Scanner(System.in);
List
for(int index = 0 ; index < numPlayers ; index++) { Player player = new Player("P.No" + (index+1)); players.add(player); } System.out.println(" Let's decide in what order players will roll: "); Map
return roll; } public static int flipDice() { Random random = new Random(); int dice = random.nextInt(6)+1; return dice; } }
------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
import java.util.Random; import java.util.Scanner;
public class Player { public String name; public Player(String name) { this.name = name; } public String getName(){ return name; } public int takeTurn() { int roll = flipDice(); System.out.println(name + " got dice value of " + roll + "."); return roll; } public int flipDice() { Random random = new Random(); int dice = random.nextInt(6)+1; return dice; } public String toString() { return name; }
}
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
