Answered step by step
Verified Expert Solution
Question
1 Approved Answer
The purpose of this assignment is to acquaint ourselves with processing multi-dimensional ar- rays. This program will utilize loops, external file i/o, random numbers, and
The purpose of this assignment is to acquaint ourselves with processing multi-dimensional ar- rays. This program will utilize loops, external file i/o, random numbers, and methods with array parameters. The Game of BINGO! Bingo is a popular game played on a 5 row by 5 column grid, called a card. There is one letter of the word B-I-N-G-0 at the top of each column. In each space under each letter are randomly selected numbers : . under B, 1-15 under I, 16-30 . under N, 31-45 under G, 46 60 under 0, 61-75. As numbers are selected, they are marked off the card. When a line of five squares, horizontal, vertical, or diagonal, is marked out, the card is a winner. A sample bingo card is shown below: 12 3 10 7 2 28 31 49 66 26 45 5375 17 33 59 67 19 42 5574 23 37 46 70 If the numbers 3, 45, 53, 75, and 26 are picked at random, then there will be a horizontal bingo on the second row. Diagonal wins may be from top left corner down to bottom right corner or top right corner down to bottom left corner. No free space will be utilized. 1. Write a program to play a game of bingo on a single card. The input to your program will be from the file bingo.in. The input will consist of a set of exactly 25 integers in row major order on separate lines representing the numbers on the bingo card. You will use the built-in random() method from the Math class to generate your random integers between 1 and 75 corresponding to the numbers being picked from a bingo bin. (i.e., Math.round((Math.random() * 74 + 1))) This process will continue until a winning pick is "called." 2. The bingo numbers that are picked should be displayed on the screen. This should be followed by a display of the winning bingo card with x's used in place of called numbers. In addition, print a message to the screen indicating whether the win was horizontal, vertical, or diagonal, and how many picks from the bin it took to find a win. 3. Your program should be named Bingo and should be in a Progi directory on your account. Method Notes You will need to use at least four class methods in this program. Below are some good candidates. You are strongly encouraged to break one or more of these methods into other methods. As you'll see, some of them can get long. A fillcard method to input the values from the file into your 5 by 5 card. . A printCard method to print your card values out to the screen in tabular form. Any num- ber that has been picked in the current game should be represented by an X. Drawing the game board and including the name "BINGO" lined up above the board are both required. A playGame method that acts as the main driver for all of your game action. It will need to contain a loop which continues to run until a win is found. You may want to have it call a separate method which picks a random integer between 1 and 75 that has not already been picked, and then "marks" that integer if it finds on your card. The easiest way to mark a card is to simply change its value to 0. It should print to the screen each random number picked from the bingo bin. After picking a number and marking it if it is on the card, you will want to call a method called checkForwin. This method will sum up each row, each column, and then the two diagonals. If, at any point, you find a zero sum, you should leave this method and return your type of win. I recommend storing your win type as an integer. A non-win can be a 0, and your other wins can be global constants such as: One potential problem spot with this method is in your summations. For your horizontal and vertical summations for this method, you are going to need to flush your sum variable public static final int HORIZONTAL = 1; public static final int VERTICAL = 2; public static final int DIAGONAL 3; to zero before each inner loop is processed. With your diagonal suns, you've only got one loop, so just reset the value before each loop
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started