CIS 35A-- Java Programming Programming Assignment #2 - Page 1 of 3 Programming Homework Assignment #2 Due Date: Mon., May 7 (uploaded by 11:59 PM under Week 5 in Catalyst) Upload to Catalyst the source files (.java files) and screen output (copied and pasted into the end of the main file, commented out), all zipped in one file (use input given on Catalyst) Problem: Write a Java application program to play Bingo. However, the 2-dim. arrays to be used in this program will be &"sideways&", so row 0 is the &"B column&", row 1 is the &"I column&", row 2 is the &"N column&", row 3 is the &"G column&", and row 4 is the &"O column&". Even though there are several ways to write a program for Bingo, below are more requirements. (If any of you find a good internet page about Bingo, please post it in the HW2 Forum!) Declare the following arrays in main— bingoNums1 (2-dim. array of int), bingoNums2 (2-dim. array of int), bingoMatches1 (2-dim. array of boolean), bingoMatches2 (2-dim. array of boolean). In main, allocate memory for all the 2-dim. arrays so theyre 5 X 5 (could do in the declarations). DO NOT RE-ALLOCATE THE 2-DIM. ARRAYS IN THIS PROGRAM (i.e., always re-use the same 2-dim. arrays). Then main must call the following methods (logic for main is below): 1. **Call a static method (also in this main class, Im calling it fillBingoNums, see details in A. below) to fill the 2-dim. array of int parameter passing bingoNums1 2. Call fillBingoNums again, this time passing bingoNums2. 3. Call displayBingoNums (see B. below) passing &"Your Bingo Card: &" and bingoNums1 4. Call displayBingoNums passing &"Computers Bingo Card: &" and bingoNums2 5. Call a static method (Im calling it initBingoMatches, details in C. below), passing bingoMatches1 to set all the elements in the 2-dim. array to false 6. Call initBingoMatches), passing bingoMatches2 7. Call a static method (Im calling it playBingo-- see details in D. below) that plays a Bingo game using bingoNums1, bingoNums2, bingoMatches1, and bingoMatches2 8. Prompt the user and read (into a String) if the user wants to play another. If the beginning char of the answer string is y or Y, then repeat from ** More on the above-mentioned methods: A. In the fillBingoNums method (has a 2-dim. array of int parameter), fill the 2-dim. array so that EACH &"row&" of the 2-dim. array represents a &"column&" on the Bingo card in the following way (more explanation in Online Meeting #1): row 0 has the range 1-15, row 1 has the range 16-30, row 2 has the range 31-45, row 3 has the range 46-60, row 4 has the range 61-75 (POINTS OFF IF YOU ASSIGN TRANPOSED INSTEAD!) pseudo-randomly (see last page for how, but DONT USE A Random object unless its private static) assign numbers in the appropriate to each element (use nested for loops), BUT DO NOT ALLOW DUPLICATES* row 2, element 2 will be a &"free&" space, so put -1 (negative 1) in that element CIS 35A-- Java Programming Programming Assignment #2 - Page 2 of 3 B. In the displayBingoNums method, display each row of the parameter (2-dim. array of ints) in columns (sideways), so it displays the String parameter first, then on the next row &"B I N G O&", then the next row all the element 0s of each row of the 2-dim. array, then below that, all the element 1s of each row, etc. (display FREE if element value is -1) (see Online Meeting video for clarifications) C. In the initBingoMatches method, use nested for loops to set each element of the 2-dim. array of boolean parameter to false set element [2][2] to true (&"free&" spot) D. In the playBingo method, you will use bingoNums1, bingoNums2, bingoMatches1, and bingoMatches2 passed from main (parameters), and in this method, bingoNums1 and bingoMatches1 are for the USER, and the other 2 are for the computer. Declare a LOCAL one-dim. array of boolean (Im calling it bingoArray ) and allocate 76 elements for it. This method will play a Bingo game (see E. below for algorithm), using the following methods: getBingoNumber (GIVEN IN THE HW2 CODE FILE) that will return a randomly-generated number not already used in the game. displayBingoNum (GIVEN IN THE HW2 CODE FILE) that will display to System.out ONE number with the appropriate letter &"column&" findMatch (see details in F. below) that checks a bingoNums 2-dim. array if the number is in it, AND 调试Java编程作业、Java作业代做留学生、代写Java实验、Java实验代做updates the corresponding bingoMatches 2-dim. array (returns true if it is, false, if not) checkWin (see details in G. below, SOME of this is in the HW2 Code File) that checks if a bingoMatches array (parameter) has a row, column or either diagonal all matched, and returns (in a RETURN STATEMENT) the winning numbers (from the parameter bingoNums) in a new array of ints (SHOULD NOT CALL THIS METHOD UNLESS A MATCH WAS FOUND!!!) E. When &"playing&" Bingo, do the following Display some instructions (see test run) ***Get and display the next Bingo number Check the &"user&" first, THEN the &"computer&": (in the following, the &"user&" is the player, then the &"computer&" is the player) Check if the number is in the bingoNums (2-dim. array) using findMatch (which will also update the corresponding bingoMatches array) Display if the player had a match If the player had a match, check if the player won (call checkWin) and display if the player won or not, and IF the player won, display the winning numbers (array that was returned from the checkWin method) (NOTE: if the USER won, dont check if the computer won) If no one won, prompt the user if he/she wants to continue, read the answer in a String CIS 35A-- Java Programming Programming Assignment #2 - Page 3 of 3 If the beginning char of the answer isnt n nor N, return to main, otherwise, repeat to *** F. In the findMatch method, Check the appropriate row of the bingoNums parameter if the number (parameter) is in that row * (DONT CHECK THE WHOLE 2-DIM. ARRAY OR POINTS WILL BE DEDUCTED FOR INEFFICIENCY, hint: see displayBingoNum) If it is, set the corresponding element in the bingoMatches parameter to true, AND (to make it easier to debug, so this is really for the programmer), display the row and column it was found Return true (boolean) if its found, false otherwise G. In the checkWin method, (SOME OF THIS METHOD IS IN THE HW2 CODE FILE) Check the bingoMatches parameter for the first row, column or diagonal (be sure to check right and left diagonals if needed) in which each element is true and save the numbers in a winning row/column/diagonal in a new one-dim. array of ints (INCLUDE CODE TO CHECK EACH ROW, COLUMN, DIAGONAL) Return (in a return statement) the one-dim. array (if win found), null otherwise *Suggestion: write a method that does a sequential/linear search for ONE row, and returns the position in that row where found, or -1 if not found (use this method where you see *) DO NOT USE ANY CLASS-SCOPE VARIABLES unless theyre static AND final! ALL METHODS ARE static. (This assignment is NOT object-oriented, but HW#3 will be). ALWAYS check the array bounds correctly (both dimensions)! Try to make efficient (including not wasting memory) or points may be deducted! DONT CHANGE ANY ALGORITHMS OR SPECIFICATIONS WITHOUT PERMISSION OR POINTS OFF! TURN IN with output that includes the user winning, the computer winning, someone winning a &"row&", someone winning a &"column&", someone winning a diagonal, and the user quitting before anyone wins. You may have play several times to get all those examples. Check your answers carefully (make sure its a win when it should be)! HOW TO USE get pseudo-randomly generated integers between MIN and MAX (inclusive): (int)(Math.random() * (MAX-MIN+1) ) + MIN (OR you may use a Random object for this but ONLY IF ITS private static at CLASS SCOPE) SUGGESTION: To test this, make sure you check if ALL the numbers on a bingoCard are in the correct range for the &"column&", that no duplicates in the bingoCard OR bingo game numbers are duplicates, if its a match, that your program indicates that its a match when it should be, and it finds a win when it should. This isnt easy, but not impossible. When testing your method that checks if its a win, display each row and column that youre testing (and make your output clear so you know youre checking the correct row and column). When testing, copy and paste your output to a Word document so you could find matches and wins easier. CHECK YOUR ANSWERS (that the winning numbers were actually &"chosen&", that they were in the bingoNums array AND they were all in a row)!!! If you dont know how to play Bingo, look it up on the internet! Extra Credit: See the CodeLab exercises for HW#2 (listed in Catalyst and CodeLab). See CodeLab for the due dates. & 转自:http://ass.3daixie.com/2018052758777089.html
讲解:Java、Java、Java、Java
©著作权归作者所有,转载或内容合作请联系作者
- 文/潘晓璐 我一进店门,熙熙楼的掌柜王于贵愁眉苦脸地迎上来,“玉大人,你说我怎么就摊上这事。” “怎么了?”我有些...
- 文/花漫 我一把揭开白布。 她就那样静静地躺着,像睡着了一般。 火红的嫁衣衬着肌肤如雪。 梳的纹丝不乱的头发上,一...
- 文/苍兰香墨 我猛地睁开眼,长吁一口气:“原来是场噩梦啊……” “哼!你这毒妇竟也来了?” 一声冷哼从身侧响起,我...
推荐阅读更多精彩内容
- 如何不同领域的人针对同一事物的联想如此不同? 你是否遇到过这种情况:“几个不同行业的人聚会,有的人是专栏作家,有的...
- 版本记录 前言 我们在做app的时候,不是做完功能就结束了,很多时候是需要进行检查和优化的,而xcode自带了一个...