讲解:Java、Java、Java、Java Exception Handling

CSC115 Assignment 1:BingoObjectivesUpon completion of this assignment, you need to be able to:Write Java code following the Coding Conventions defined for the course.Define and create a simple class in Java.Create and use Java arrays that contain complex data types (objects).Have been introduced to Java Exception Handling.Use a developed testing system.IntroductionIn the game of Bingo, the caller randomly selects a set of Bingo balls, one at a time, froma Bingo cage and calls out the letter and number printed on the little ball. Each playerchecks for that particular number on their Bingo card, a 5 5 grid. If the number is there,then the player will cover the specific grid that contains the number. The player’s goal isto be the first to cover the the grids in a previously-agreed-upon pattern, often a straightvertical or horizontal line.Immediately after the caller’s announcement of the current ball, a player who has thenecessary pattern will call out “Bingo!”. Before claiming the prize, the player proves thevalidity by calling out the numbers of each of the covered squares that make up the pattern.The caller verifies that each of the balls were actually called, by searching through thecalled balls.In this assignment, you will create a class BingoBall and create the data structure thatcontains the called balls.Quick Start(1) Create a fresh directory to contain this assignment: CSC115/assn1 is a good name.Download this pdf file and the file BingoBall.java into that directory.(2) Create a subdirectory, called docs, for documentation and download the html files.When you open the local version of this pdf, and click on the following links, thespecifications for the required Java classes will open. Try it:BingoBall specificationsBingoCalls specificationsIf you are not using a local version of this document and/or have not created asubdirectory called docs to store the html files, you can open one of the html filesby double-clicking on it.(3) Carefully examine both of the specification documents. Note the similarity to thestandard documentation pages for all Java classes. For example, search for javaand Random and note the layout of information.(4) Compile BingoBall.java. It compiles and runs without errors, but it is not veryuseful in its initial condition.(5) Open BingoBall.java in a text editor. A basic template has been started, to guideyou through the process of creating a class by taking the following recommendedsteps:(a) Create the shell of the program (done for you): This is done by creating theclass definition and all the public methods as directed in the specificationdocument. The methods are empty, except when they must return a value,in which case a dummy value is returned. Once the shell is created, the sourcecode can be compiled.(b) Decide what the private data fields will be: Note that for BingoBall a publicstatic final array has been initiated for you. This is NOT a data field, buta constant value that you may find helpful. (See the comments in the sourcecode).(c) Implement the methods one at a time, starting with the easiest ones.Note that the main method contains a set of statements that tests the code. Youmay add more tests if you like.(6) After completing and thoroughly testing BingoBall, create the BingoCalls class,again following the specifications. Create your own main method in this class tothoroughly test all the methods in BingoCalls.Detailed InstructionsComplete both the BingoBall and BingoCalls classes adhering to the following guide-lines:The associated html file contains a summary and detailed explanation of what eachmethod must do, along with details about any input or returned value. Note that theinformation provided is generated from header comments; you are welcome to usethese as required header commenting within your code.The main1method is to be used as a tester. The BingoBall class main method iswritten for you.Use this as the standard for testing all of your assignments.Compile and test your work frequently. Experienced programmers all do this,knowing that a single syntax error or logical error is easier to fix when you’veonly made a few changes to the document.Some basic information (for details, see the textbook)By convention, Java uses very specific names for many of the basic methods, making iteasier for users to remember what methods are available. For instance, every class in Javahas both an equals and a toString method. A basic class definition in Java will generallycontain the following:private data fields: These specifically define the attributes that make a particularobject of this class unique.One or more constructors: The constructors are created to allow the user to ini-tialize an object. In most cases, the co调试Java编程作业、Java作业调试、帮做Java编程作业、Java Exception Handling实验代做nstructor sets the values of the data fields, asspecified by the argument list.1Note to C programmers: unlike C, which requires only one main method for all of the files involved inthe running of a program, Java allows for each file to contain a main method. The actual main method thatruns the program is determined by the java command which names the file.Accessor–modifier methods: These methods are also referred to as the setters andgetters. Where the user is permitted, each of the private data fields can be updatedor retrieved using these methods.A method to determine equivalence between objects of the class: It is alwaysuseful to be able to determine what conditions are necessary for two objects ofthe same class to be deemed equivalent. With some objects, like strings or numberobjects, this is intuitive. When it is not, the class designer must make the determi-nation. Generally, the combined equality of the data fields is a safe determination,but that may not always be the case.A method to format an informative String that describes the object: This is anextremely useful method, both during development as a debugging tool, and alsofor users to visualize the details of the objects.BingoBallThe BingoBall consists ofAn uppercase letter, one offB, I, N, G, Og.A number between 1 and 75. There is a matching of each of the letters to thenumbers that can be associated with it.B: f1–15gI: f16–30gN: f31–45gG: f46–60gO: f61–75gSome sample testing has been provided for you in the main method of the BingoBallclass. Note that the System.out.println statements with the BingoBall argument willproduce the output that is defined in the toString method. If the toString method hasnot been created, then the address location of the reference is printed instead, which is notvery helpful.BingoCallsThe BingoCalls class is basically a means to store the BingoBalls that were called duringa particular game. There will only be one instance of this class, as opposed to the 1–75BingoBalls that can be instantiated. The main data field of this class will be an array ofBingoBalls. You may use a single array or a 2D array, or an array of arrays for this datafield. You MAY NOT use any of the collections data structures that extend the List classfrom the java.util package.In the design, the public methods allow the caller (the user) tocreate an empty container at the start of a game,add balls as they are called in the game,determine how many balls have been played,find and remove a ball that was accidentally added (mistakes can happen).confirm that a particular ball was played during the game, andempty the container of all balls, making it ready for a new game.Java array data types must have a fixed size that is determined when the array is initialized.(Note that the array must be initialized separately from the individual items inside thearray.) To allow for re-usability, we add a provision that doubles the size of the array whenthe number of items exceeds the capacity of the array. To test for this, create the initialarray to hold a maximum of 5 items. Before each insert, make sure that the array is notalready full; if it is, then call a private method, created by you, that enlarges the arraybefore inserting the item.As with the BingoBall, thoroughly test everything within the main method of the class.SubmissionSubmit the following completed files to the Assignment folder on conneX. You will beshown how to do this in the first week of labs:BingoBall.javaBingoCalls.javaPlease make sure you have submitted the required file(s) and conneX has sent you a con-firmation email. Do not send [.class] (the byte code) files. Also, make sure you submityour assignment, not just save a draft. Draft copies are not available to the instructors, sothey are not collected with the other submissions. We can find your draft submission, butonly if we know that it’s there.A note about academic integrityIt is OK to talk about your assignment with your classmates, and you are encouraged todesign solutions together, but each student must implement their own solution.GradingMarks are allocated for the following:Proper programming style. is demonstrated, as per the coding conventions on CSC115conneX Resources.All methods are implemented exactly to the specifications.The main data field of BingoCalls must be an array, and not an object of any ofthe List classes in the Java API, java.utils package.The private method that resizes the array in BingoCalls must copy the contentsof the original array one by one into the new larger array.The main method of BingoCalls must demonstrate that each method in BingoCallswas tested.You will receive no marks for any Java files that do not compile.& 转自:http://ass.3daixie.com/2018052758777292.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

推荐阅读更多精彩内容