• 11-18-2009, 05:14 AM
XMarkoX
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:
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); } } } }```
• 11-18-2009, 10:44 AM
XMarkoX
I've got like week left to do this thing. been fighting intense fight with it for few days. xD
• 11-19-2009, 08:58 AM
XMarkoX
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.
• 11-20-2009, 10:26 AM
XMarkoX
C'mon.. this should be so easy for advanced coder. But im still stuck at this point, got 4 days left.. lawl. :P
• 11-20-2009, 11:01 AM
JosAH
I'll give you a jump start; it's spoonfeeding so no further comments;

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
• 11-20-2009, 12:36 PM
XMarkoX
Thank you, helped a lot.
• 11-20-2009, 02:53 PM
JosAH
Quote:

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
• 11-20-2009, 11:49 PM
XMarkoX
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
• 11-23-2009, 09:45 AM
manhtungtnk28@gmail.com
year!!

thank very must