Need some help where to start...what to do????


The objective of this program is to simulate playing the game of Bingo.

A Bingo card basically consists of a 2-d array of 5 rows and 5 columns containing integers. The first column contains integers in the range 1-15, the second column (16-30), the third column (31-45), the fourth column (46-60) and the fifth column (61-75). The numbers are not repeated. The central square is a free square (say 0). An example is shown below:

11 17 33 49 65
1 29 41 59 66
13 25 0 47 63
7 22 44 55 74
10 18 34 51 70

Your program should read a set of numbers representing such a Bingo card as input. It should then generate random numbers between 1 and 75 (non-repeated). When each number is generated, if it is present in the card, it should be “marked”. If a column, diagonal or row of marked numbers is obtained, then “BINGO!”, the game is won. If no such column, diagonal or row is obtained after 25 attempts, then the program should print “GAME OVER!” and quit.

You can show the winning card as a separate one, with the called numbers shown and the others filled with 0.

A sample run of the program is given below:

Welcome to the Bingo game simulation
Enter the Bingo card numbers: 11 17 33 49 65 1 29 41 59 66 13 25 0 47 63 7 22 44 55 74 10 18 34 51 70

Here’s your card
11 17 33 49 65
1 29 41 59 66
13 25 0 47 63
7 22 44 55 74
10 18 34 51 70


Number called: 44
Present
Number called: 56
Not present
Number called: 74
Present
Number called: 22
Present
Number called: 1
Present
Number called: 55
Present
Number called: 62
Not present
Number called: 7
Present
BINGO!

0 0 0 0 0
1 0 0 0 0
0 0 0 0 0
7 22 44 55 74
0 0 0 0 0


Note: Use the principles of modular programming by designing methods to do the v
arious tasks in the program such as generating the random number, checking if the number is present, checking for Bingo!, and printing the card.

The description is pretty detailed. Give it a try, and if you have problems with the code, then post what you've written and we'll help you correct it. But, this post looks like a "do it for me post", and that is not something we're going to do.

hello poggie
Try decompose program to set of classes.
One can be a BingoCard.java class:
-define inside integer 2D structure 5x5,
-define constructor,
-define needed methods
In this case concentrate on problem what a BingoCard is.
It has a columns,rows , diagonals (always 2).
You should check if given number is present in structure 5x5,
for this you can use another "shadow" boolean 2D structure 5x5
....
show Your work, and ask.
Good described assumption data are half of succes.
quuba

alright this is what I have so far, I need some help with checking to see if the random number has been chosen already, and also to check of a full row has been had.

/**
 * @(#)bingoGame.java
 *
 * bingoGame application
 *
 * @author 
 * @version 1.00 2008/11/24
 */
import java.util.*;
import java.math.*;
public class bingoGame {
    	
    public static void main(String[] args) {
    	int i ,j;
    	int[][] card1 = new int[5][5];
    	int[][] check = new int[5][5];
    	cardRead(card1);
    	cardPrint(card1);
    }
    public static void cardRead(int[][]a){
        int i,j;
        Scanner keyboard = new Scanner(System.in);
        System.out.print("Whats the card: ");
    	for(i=0; i<5; i++)
    		for(j=0; j<5; j++)
    			a[i][j] = keyboard.nextInt();
    			
    }
	public static void cardPrint(int[][]a){
		int i, j;
		System.out.println();
		for(i=0;i<5;i++){
			for(j=0;j<5;j++)
				System.out.print(a[i][j] + "\t");
				System.out.println();
		}
	}
	public static void random(int a){
		 int i, j;
		 int answer =1;
		 Random r = new Random();
		 int random1 = r.nextInt(74)+1;
		 if(answer == 1){
		 for(i=0;i<5;i++){
			for(j=0;j<5;j++)
				a[i][j] = random1();
		 int count = 1;
		 if (count>1)
		 	for(i=0;i<5;i++)
			for(j=0;j<5;j++)
				if(a[i][j]==random1)
					answer =1;
				else
					answer =0;
		 }
		 }
		 } 	
}

The description is pretty detailed. Give it a try, and if you have problems with the code, then post what you've written and we'll help you correct it. But, this post looks like a "do it for me post", and that is not something we're going to do.

i dont want you to do it I just needed some help where to get started, now can you help me that i posted my code so far?

Place the numbers generated into a Set. When you attempt to add something to a set that already exists in the set, the add method will return false, so keep generating numbers and adding them to the set, until the add action succeeds.

i dont want you to do it I just needed some help where to get started, now can you help me that i posted my code so far?

Like I said

... this post looks like a "do it for me post", ...

with emphasis on the looks like.

What else are we to assume when all you do is block copy your assignment text?

Sorry if that's how it came accross. Now, i have no idea what a set is so I'm going to assume I can't use it. I would like to use a for loop like

//up here i would declare a new array to store generated numbers

public static void randomCheck(int[][] a){
Random r = new Random();
int answer=1;
if (answer==1){
int randomnum = r.nextInt(74)+1;
for(int i=0; i<5; i++)
      for(int j=0; j<5; j++){
if(randomnum != array[i][j]){
      answer = 1;}
else {
       a[i][j] = randomnum;}
       System.out.println("Number called: "+a[i][j]);
       answer = 1;
      }
   }
}

and hopefully that would make sure my number was not repeated (let me know if it would!)but how do I ask this:
Number called: 44
and return:
Present

so this is what i have, thae last method is the one i have trouble with because the for loop will only check at the curent address in the array, i need the for loop to check every single address is the array to see if the random number has previously been generated.

/**
 * @(#)bingoGame.java
 *
 * bingoGame application
 *
 * @author 
 * @version 1.00 2008/11/24
 */
import java.util.*;
import java.math.*;
public class bingoGame {
    	
    public static void main(String[] args) {
    	int i ,j;
    	int[][] card1 = new int[5][5];
    	int[][] check = new int[5][5];
    	cardRead(card1);
    	cardPrint(card1);
    	random(check);
    }
    public static void cardRead(int[][]a){
        int i,j;
        Scanner keyboard = new Scanner(System.in);
        System.out.print("Whats the card: ");
    	for(i=0; i<5; i++)
    		for(j=0; j<5; j++)
    			a[i][j] = keyboard.nextInt();
    			
    }
	public static void cardPrint(int[][]a){
		int i, j;
		System.out.println();
		for(i=0;i<5;i++){
			for(j=0;j<5;j++)
				System.out.print(a[i][j] + "\t");
				System.out.println();
		}
	}
	public static void random(int[][] c){
		
		Random r = new Random();	
		int randomnum = r.nextInt(74)+1;
		int first=1;
		do{
			c[0][0]=randomnum;
			first=2;
		}while(first==1);
		int answer=1;
		if (answer==1){
		for(int i=0; i<5; i++){
    		  for(int j=1; j<5; j++){
    		  	Random r1 = new Random();	
				int randomnum1 = r1.nextInt(74)+1;
				if(c[i][j] == randomnum1){//this if statement only allows checking of current address,
 //i need  to check every address of the array for repeat
      					answer = 1;
      					i--;
      					j--;}
				 else if(c[i][j] != randomnum1)  {
						c[i][j] = randomnum1;}
   					    System.out.println("Number called: "+c[i][j]);
    				    answer = 1;}
    				    	}
    			}	    
    	
			first=2;
   }
}

Like it has been already suggested, keep pushing the items in a Set until the size of the set is 25 [since you are attempting to fill a 5 x 5 array]. Since a Set rejects duplicate elements, the only time the size of a Set will be 25 is when it contains 25 unique elements. Loop over the Set using an Iterator and push the elements in the given array.

Or maintain a frequency table [using array] of the size as the range of your random number generation [in your case 74]. As soon as you generate a random number, increment the frequency and keep generating as long as the frequency for a given generated number is greater than 0.

int[] freq = new int[75]; // 0 to 74
int[][] arr = new int[5][5];
for(int i = 0; i < 5; ++i) {
  for(int j = 0; i < 5; ++j) {
    for(; ;) {
      int r = /* generated random number between 1 and 74 */
      if(freq[r] != 0)
        continue; // generate the next random
      ++freq[r];
      arr[i][j] = r;
      break;
    }    
  }
}

You can even use a HashMap to maintain the frequencies. Just modify the above idea/code to fit your needs.

In your case, it would be easier to tackle one row/column at a time rather than looping over the entire two dimensional array. Also consider creating a Bingo class which encapsulates the arrangement of numbers rather than exposing the entire functionality as a two dimensional integer array.

what does these mean?

for(; ;)

and

break;

when i run this application with you code inserted

/**
 * @(#)bingoGame.java
 *
 * bingoGame application
 *
 * @author 
 * @version 1.00 2008/11/24
 */
import java.util.*;
import java.math.*;
public class bingoGame1 {
    	
    public static void main(String[] args) {
    	int i ,j;
    	int[][] card1 = new int[5][5];
    	int[][] check = new int[5][5];
    	cardRead(card1);
    	cardPrint(card1);
    	random(check);//line 19
    }
    public static void cardRead(int[][]a){
        int i,j;
        Scanner keyboard = new Scanner(System.in);
        System.out.print("Whats the card: ");
    	for(i=0; i<5; i++)
    		for(j=0; j<5; j++)
    			a[i][j] = keyboard.nextInt();
    			
    }
	public static void cardPrint(int[][]a){
		int i, j;
		System.out.println();
		for(i=0;i<5;i++){
			for(j=0;j<5;j++)
				System.out.print(a[i][j] + "\t");
				System.out.println();
		}
	}
	public static void random(int[][] d){
		Random r1 = new Random();
		int[] freq = new int[75];
		int[][] arr = new int[5][5];
		for(int i = 0; i < 5; i++) {
  			for(int j = 0; i < 5; j++) {
   			 for(; ;) {
      		int r = r1.nextInt(74)+1;
      	if(freq[r] != 0)
        	continue;
      	freq[r]++;
      	d[i][j] = r;//line 50
      	break;
   				 }
 			 }
		}
	}
   }

i get the following error

Exception in thread "main" java.lang.ArrayIndexOutOfBoundsException: 5
at bingoGame1.random(bingoGame1.java:50)
at bingoGame1.main(bingoGame1.java:19)

what does these mean?

for(; ;)

and

break;

The first one is an infinite loop. Use your favorite search engine to know more about break in Java; it's pretty basic stuff you should know before trying to program in Java or as a matter of fact any language.

BTW, the code snippet I presented in my previous post was untested and was meant to be used as a reference and not directly copy pasted. And the reason you are getting an ArrayIndexOutOfBounds exception is because of a typo in my previous post; replace the i < 5 in the second loop with j < 5 .

I really appreciate the help, but i do get the feeling that i am being a bother, if you don't wanna help me, fine. You don't need to act like a crank.
P.S. I'm in first year computer science and this is the first language i've learned, so excuse me for not knowing some stuff, and asking for help, in a help forum.

commented: He is trying to help. You are the one acting like a "crank" with this post. -3

> but i do get the feeling that i am being a bother, if you don't
> wanna help me, fine

If you would have bothered to read the all replies given to your post, you would have noticed that it contains all that you need to complete this assignment of yours. If you don't understand things, you need to search them up and then post if you still have doubts; acting like a spoiled brat is no excuse.

> I'm in first year computer science and this is the first language
> i've learned

So? All I did was to ask you search up something; was it that difficult/troublesome?

> excuse me for not knowing some stuff, and asking for help,
> in a help forum.

People are definitely excused here for not knowing stuff but behavior like yours is certainly not. Replies like yours make us feel that our valuable time was wasted on something which has no returns to the Software Development community in general.

P.S.: Though this is a help forum, people here are not under any obligation to reply to threads; all the replies you received were from people who spend their valuable time trying to help others out. You should be thankful.

commented: Well, you've certainly tried to help him here. +15

right, you missed the first line that said, I appreciate your help....yeah first 4 words of my post. Second of all you made it sound like my question was stupid and trivial, and maybe for you it was but for me it wasn't. I don't care about searching things up, If thats what you suggest I'll do it. Don't try and make me seem unthankfull, thats the first line I posted. I'm just trying to think of where i acted like a "spoiled brat", yeah i can't seem to find it, so before you try and belittle me get some facts, I asked for help.

It's not about being thankful; as long as someone benefits/learns something from the answers posted, it's always an effort worth spent. I have very little time and lot of boards to manage so most of my replies are curt and short; maybe that made you think I am dismissing your problem as trivial.

My level of expectation was high because at universities they don't given these kinds of problems to complete beginners hence the knowledge of `break' was at least expected from you.

> I'm just trying to think of where i acted like a "spoiled brat"

By calling someone who tries to help you out a `crank'?

commented: I guess trying is the first step to success, but some will never learn +3

Well, whatever...I'm just going to forget about this and move along.

Okay, so moving along, my next question is how do i check these two arrays as in the array random to array card.

so if a random number is actually present in the card it will fill that spot with a value(99) to show it has been called. And print the card after each random number card check.

Okay, so moving along, my next question is how do i check these two arrays as in the array random to array card.

so if a random number is actually present in the card it will fill that spot with a value(99) to show it has been called. And print the card after each random number card check.

aaaaallrighty then...
moving along:
step 1. new question equals new thread
why? so we don't bother to read all that has allready been posted here (for starters) and so we wouldn't notice that you've been acting rude to those who have been trying to help you.

if looking things up, or doing some research is too much to ask, do not, I repeat, DO NOT, continue your studies, since you're going to fail like hell.

do remember, we're trying to help you, but when we get the idea we're trying a blind man how to read... well, we can get cranky indeed, but this is the first cranky post you've received in this thread.

secondly: what do you mean, how do I check these two arrays? do you want to check your arrays to see if a certain value is already present in it? let's see...

if ( !isPresentInArray(#yourEnteredValue#, #yourArray#){
  add(#yourEnteredValue#) to(#yourArray#);
}

public boolean isPresentInArray(int value, int[] values){
  for (int i = 0; i < values.length; i++){
      if ( values[i] == value){
         return true;
     }
  }
  return false;
}

do not copy paste this, since you'll get a lot of errors that are expected. the method to check if the value is present, you may copy paste if you want, that'll do the trick, but for future reference, treating those who try to help you badly does not help you to convince them to sacrifice their time to do your work

pretty sure we moved along now....frigg

well...
excuse me for answering your question then

well...
excuse me for answering your question then

There is no excuse for you. ;-)

(Replace you with him, and the statement is true, though.)

There is no excuse for you. ;-)

(Replace you with him, and the statement is true, though.)

mjah ... sarcasm doesn't take well in digital form, does it? :P

mjah ... sarcasm doesn't take well in digital form, does it? :P

It's a bit hard to get the vocal stress points right. ;-)

It's a bit hard to get the vocal stress points right. ;-)

ow key ... how do we solve thát using Java? :)

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.