inherit
136707
0
Nov 24, 2009 20:56:51 GMT -8
Strawberrypie
I love Strawberries
116
January 2009
strawberrypie
|
Post by Strawberrypie on Nov 24, 2009 20:34:52 GMT -8
I'm using Jgrasp to make a Bingo Game, but I don't know how to generate a card for each player or call out a random number like "B7". Can you guys help me out?
Here's my Code:
import java.util.Scanner;
public class BingoGame { public static void main(String[] args) { Scanner input = new Scanner(System.in); String [][] letters = new String[1][5]; letters[0][0] = "B"; letters[0][1] = "I"; letters[0][2] = "N"; letters[0][3] = "G"; letters[0][4] = "0"; System.out.print("Enter the number of players: "); int players = input.nextInt(); int [][][] cards = new int [players][5][5]; for (int b = 0; b < cards[0].length; b++) { cards[player][b][0] = (int)(Math.random() * 15) + 1; for (int i = 0; i < cards[0].length; i++) { cards[players][i][1] = (int)(Math.random() * 30) + 1; for (int n = 0; n < cards[0].length; n++) { cards[players][n][2] = (int)(Math.random() * 45) + 1; for (int g = 0; g < cards[0].length; g++) { cards[players][g][3] = (int)(Math.random() * 60) + 1; for (int o = 0; o < cards[0].length; o++) { cards[players][o][4] = (int)(Math.random() * 75) + 1; } } } } } System.out.println("Player " + players); System.out.println(letters[0][0] + " " + letters[0][1] + " " + letters[0][2] + " " + letters[0][3] + " " + letters[0][4]); System.out.println(cards[players][5][5]); } }
|
|
inherit
136707
0
Nov 24, 2009 20:56:51 GMT -8
Strawberrypie
I love Strawberries
116
January 2009
strawberrypie
|
Post by Strawberrypie on Nov 24, 2009 20:42:22 GMT -8
No no no! It's not for the forums, it's my homework! Come on, people help me out quick!
|
|
inherit
100824
0
May 13, 2012 5:37:49 GMT -8
Michael
14,585
March 2007
wrighty
|
Post by Michael on Nov 24, 2009 21:18:12 GMT -8
You have a few problems in there. But I guess that you know what you want it to do, so some exact help with that would be good. so the user is asked for the number of players... they enter the number. then what happens? ---- I've coded the following. It assigns each player 5 numbers. Using Math.random(). What you need to look at is your Array Structure. It's seriously out of whack. Why are you doing you 'BINGO' declaration like that? Firstly, they're Chars. So use a Char Array. Secondly, declare the array when initialising it. Let me know if you need any help with it. And you're using Java not Jgrasp! import java.util.Scanner;
public class BingoGame { public static void main(String[] args) { Scanner input = new Scanner(System.in); char letters[] = {'B', 'I', 'N', 'G', 'O'}; System.out.print("Enter the number of players: "); int players = input.nextInt(); int [][] cards = new int [players][5]; for(int i = 0; i < cards.length; i++) for(int x = 0; x < cards.length; x++) cards[x] = (int)(Math.random() * 30); for(int i = 0; i < players; i++){ System.out.println("Player " + (i + 1) + " Numbers"); printNums(cards); } } public static void printNums(int [] x){ for(int y = 0; y < x.length; y++) System.out.print(x[y] + " "); System.out.println(); } }
|
|