1. Member
Join Date
Nov 2009
Posts
9
Rep Power
0

Okay, i'm making this bingo game but i need some help. It has to be 9 random numbers 3x3 for every player. Here is what i have gained so far: Ask how many players, if wrong input, it gives error and asks you to give player amount again. Also I've got it to make some random numbers but not 3x3.

left to do : The actual game, and that it makes the 3x3 game for the amount of players given from keyboard. I've got NO CLUE, how to continue. I'd appreciate if someone could help me. Thanks in advance

heres the code:
Java Code:
```import java.util.Scanner;
import java.util.Random;
public class Niiranenmarkolopputehtävä2 {

static Random r=new Random();

public static void main(String[] args) {

// TODO Auto-generated method stub

Scanner in = new Scanner(System.in);
int players= 0;

IndexOutOfBoundsException outOfRange = new IndexOutOfBoundsException ("");
NumberFormatException nonNumbericValue = new NumberFormatException ("");

boolean repeat = true;

while(repeat == true)
{
try
{
System.out.println("How many players (1-4)");

if(in.hasNextInt() == true)
{
players = in.nextInt();
repeat = false;
}
else
throw nonNumbericValue;

if(players> 6 || players < 2)
throw outOfRange;

}

catch (IndexOutOfBoundsException e)
{
repeat = true;
System.out.println(outOfRange.toString());
}

catch (NumberFormatException e)
{
repeat = true;
System.out.println(e.toString());
}

for (int i=0;i<10;i++){

int x=r.nextInt(10)+1;

System.out.println(x);

}

}
}
}```
Last edited by XMarkoX; 11-18-2009 at 09:11 AM.

2. Member
Join Date
Nov 2009
Posts
9
Rep Power
0
I've got like week left to do this thing. been fighting intense fight with it for few days. xD

3. Member
Join Date
Nov 2009
Posts
9
Rep Power
0
The output should be something like this.. :S

Welcome to play bingo game
How many players: 1
5 7 9
3 1 6
4 8 2

Continue game (y/n) Y
5 7 9
3 1 6
0 8 2

Continue game (y/n) Y
5 7 9
0 1 6
0 8 2
Continue game (y/n) Y
5 7 9
0 0 6
0 8 2
Continue game (y/n) Y
5 7 0
0 0 6
0 8 2
BINGO

And end of game.

4. Member
Join Date
Nov 2009
Posts
9
Rep Power
0
C'mon.. this should be so easy for advanced coder. But im still stuck at this point, got 4 days left.. lawl. :P

5. I'll give you a jump start; it's spoonfeeding so no further comments;

Java Code:
```import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.Iterator;
import java.util.List;

public class Board {

private static int[][] board(int n) {

List<Integer> list= new ArrayList<Integer>();

for (int i= 0; i < n; list.add(i++));
Collections.shuffle(list);

int[][] board= new int[3][3];
Iterator<Integer> i= list.iterator();

for (int r= 0; r < board.length; r++)
for (int c= 0; c < board[r].length; c++)
board[r][c]= i.next();

return board;
}

public static void main(String[] args) {

int[][] b= board(50);

System.out.println(Arrays.deepToString(b));
}
}```
kind regards,

Jos

6. Member
Join Date
Nov 2009
Posts
9
Rep Power
0
Thank you, helped a lot.

7. Originally Posted by XMarkoX
Thank you, helped a lot.
Good; you're welcome of course; a bit of advice: don't just copy and paste the stuff but read the API documentation for every class used and try to understand what is happening.

kind regards,

Jos

8. Member
Join Date
Nov 2009
Posts
9
Rep Power
0
Well, thats the weird part.. i know what it does.. i can read the code.. but its harder to code.. i know its weird but yeah.. I edited it a lil bit and made better for my "needs" :p

9. Member
Join Date
Nov 2009
Posts
22
Rep Power
0
year!!

thank very must

#### Posting Permissions

• You may not post new threads
• You may not post replies
• You may not post attachments
• You may not edit your posts
•