Thank you for reading this post, i was wondering if you would be so kind as to help me with this code.

I have to give this project this friday night, and im kind of desperate because i cant figure out how to continue.

This bingo is supposed to be composed of an 3x5 array of numbers which the user should be able to introduce using the keyboard or ask the program to generate them randomly,they cannot be repeated or out of a 1-99 range (both inclusive).

Then, after you have those 15 numbers, random numbers representing the bingo balls have to be generated. They cannot be repeated (a number cannot appear twice), and finally the numbers have to be checked each ball appears to know whether you have line/bingo or not.

Ive been trying with no luck so far. At the moment the only thing which works is the array of random balls and a menu in which you could choose between those functions (entering the numbers, random numbers and play).

Here you have some of my tries:

Method for random balls :

Method for random numbers (the 15 you are playing with), this one has some problems, if there is a single repeated number it is ok, but if a second one was about to repeat, it repeats.Code:public static void main(String[] args) { bolasAle(); } public static int [] bolasAle() { int []bola=new int [99]; for (int i=0; i<99; i++) { bola[i]=(int)(Math.random() * (99)+1); for (int j=0; j<=i; j++) {if (bola[i]==bola[j] && i!=j) { while (bola[i]==bola[j]) { bola[i]=(int)(Math.random() * (99)+1); } j=0; } } } for (int k=0;k<99;k++) { System.out.print(bola[k] +" "); } return bola; }

This method would check if there is line or bingo. I thought giving a negative value to a winner number (*-1) would be a good idea, so if every 5 numbers of a line are < 0 there is LINE, if every line has LINE then, BINGO.Code:public static int [][] CartonAle() { int [][]carton=new int [3][5]; for (int i=0; i<carton.length; i++) { for (int j=0; j<carton[i].length; j++){ if (i==0 && j == 0){ carton[i][j]=(int)(Math.random() * (99)+1); }else{ generacion(i,j,carton); } } } for (int k=0;k<3;k++) { for(int i=0;i<5;i++) { System.out.print(carton[k][i] +" "); if (i==4) { System.out.println();} } } return carton;} public static void generacion(int i, int j, int [][]carton){ carton[i][j]=(int)(Math.random() * (99)+1); for (int k=0; k<=i; k++){ for (int l=0; l<=j; l++){ if ((carton[i][j]==carton[k][l]) && (i!=k || j!=l)){ generacion(i,j,carton); } } } }

I guess it would be finished with the play method, some people adviced me to do it using a boolean array so i dont know wether it would be a good idea or not.Code:public static void estadoActual(int [][] carton){ // se comprueba cuantos numeros negativos (aciertos) hay en el carton // si hay cinco en una linea, ¡linea!. si todas tienen linea, ¡bingo!. int aciertosL1=0,aciertosL2=0,aciertosL3=0; for (int i=0;i<5;i++){ if (carton[1][i]<0) { aciertosL1++; } if (carton[2][i]<0){ aciertosL2++; } if (carton[1][i]<0){ aciertosL3++; } } if (aciertosL1==5 || aciertosL2==5 || aciertosL3==5){ System.out.println("LINEA!"); } if (aciertosL1==5 && aciertosL2==5 && aciertosL3==5) { System.out.println("BINGO!"); } //Vuelve a poner a 0 el numero de aciertos para por si // hay una nueva comprobacion aciertosL1=0; aciertosL2=0; aciertosL3=0; }

Tweet This+ 1 thisPost To Linkedin