讲解:Java、Java、Java、Java

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

©著作权归作者所有,转载或内容合作请联系作者
  • 序言:七十年代末,一起剥皮案震惊了整个滨河市,随后出现的几起案子,更是在滨河造成了极大的恐慌,老刑警刘岩,带你破解...
    沈念sama阅读 219,589评论 6 508
  • 序言:滨河连续发生了三起死亡事件,死亡现场离奇诡异,居然都是意外死亡,警方通过查阅死者的电脑和手机,发现死者居然都...
    沈念sama阅读 93,615评论 3 396
  • 文/潘晓璐 我一进店门,熙熙楼的掌柜王于贵愁眉苦脸地迎上来,“玉大人,你说我怎么就摊上这事。” “怎么了?”我有些...
    开封第一讲书人阅读 165,933评论 0 356
  • 文/不坏的土叔 我叫张陵,是天一观的道长。 经常有香客问我,道长,这世上最难降的妖魔是什么? 我笑而不...
    开封第一讲书人阅读 58,976评论 1 295
  • 正文 为了忘掉前任,我火速办了婚礼,结果婚礼上,老公的妹妹穿的比我还像新娘。我一直安慰自己,他们只是感情好,可当我...
    茶点故事阅读 67,999评论 6 393
  • 文/花漫 我一把揭开白布。 她就那样静静地躺着,像睡着了一般。 火红的嫁衣衬着肌肤如雪。 梳的纹丝不乱的头发上,一...
    开封第一讲书人阅读 51,775评论 1 307
  • 那天,我揣着相机与录音,去河边找鬼。 笑死,一个胖子当着我的面吹牛,可吹牛的内容都是我干的。 我是一名探鬼主播,决...
    沈念sama阅读 40,474评论 3 420
  • 文/苍兰香墨 我猛地睁开眼,长吁一口气:“原来是场噩梦啊……” “哼!你这毒妇竟也来了?” 一声冷哼从身侧响起,我...
    开封第一讲书人阅读 39,359评论 0 276
  • 序言:老挝万荣一对情侣失踪,失踪者是张志新(化名)和其女友刘颖,没想到半个月后,有当地人在树林里发现了一具尸体,经...
    沈念sama阅读 45,854评论 1 317
  • 正文 独居荒郊野岭守林人离奇死亡,尸身上长有42处带血的脓包…… 初始之章·张勋 以下内容为张勋视角 年9月15日...
    茶点故事阅读 38,007评论 3 338
  • 正文 我和宋清朗相恋三年,在试婚纱的时候发现自己被绿了。 大学时的朋友给我发了我未婚夫和他白月光在一起吃饭的照片。...
    茶点故事阅读 40,146评论 1 351
  • 序言:一个原本活蹦乱跳的男人离奇死亡,死状恐怖,灵堂内的尸体忽然破棺而出,到底是诈尸还是另有隐情,我是刑警宁泽,带...
    沈念sama阅读 35,826评论 5 346
  • 正文 年R本政府宣布,位于F岛的核电站,受9级特大地震影响,放射性物质发生泄漏。R本人自食恶果不足惜,却给世界环境...
    茶点故事阅读 41,484评论 3 331
  • 文/蒙蒙 一、第九天 我趴在偏房一处隐蔽的房顶上张望。 院中可真热闹,春花似锦、人声如沸。这庄子的主人今日做“春日...
    开封第一讲书人阅读 32,029评论 0 22
  • 文/苍兰香墨 我抬头看了看天上的太阳。三九已至,却和暖如春,着一层夹袄步出监牢的瞬间,已是汗流浃背。 一阵脚步声响...
    开封第一讲书人阅读 33,153评论 1 272
  • 我被黑心中介骗来泰国打工, 没想到刚下飞机就差点儿被人妖公主榨干…… 1. 我叫王不留,地道东北人。 一个月前我还...
    沈念sama阅读 48,420评论 3 373
  • 正文 我出身青楼,却偏偏与公主长得像,于是被迫代替她去往敌国和亲。 传闻我的和亲对象是个残疾皇子,可洞房花烛夜当晚...
    茶点故事阅读 45,107评论 2 356

推荐阅读更多精彩内容