{"id":531,"date":"2013-08-15T22:33:07","date_gmt":"2013-08-16T05:33:07","guid":{"rendered":"http:\/\/blogs.unsw.edu.au\/comp1400\/?p=531"},"modified":"2013-08-22T23:07:34","modified_gmt":"2013-08-23T06:07:34","slug":"assignment-1-loops-and-arrays-draft","status":"publish","type":"post","link":"https:\/\/blogs.unsw.edu.au\/comp1400\/blog\/2013\/08\/assignment-1-loops-and-arrays-draft\/","title":{"rendered":"Assignment 1 &#8211; Loops and Arrays"},"content":{"rendered":"<h3><strong>Due: 11:59pm Sunday 1 September (i.e. the end of week 5)<\/strong><\/h3>\n<p>This assignment is about loops arrays. You will write three methods to manipulate arrays. The first two are easy. The third one will require more thought about the design. You will submit the assignment using the CSE\u00a0<strong>give<\/strong> system (see below).<\/p>\n<p>Download the BlueJ project,\u00a0<a href=\"http:\/\/www.cse.unsw.edu.au\/~cs1400\/13s2\/examples\/Assignment1.zip\">Assignment1.zip<\/a>. It contains three methods. You have to write the code that goes inside them.<\/p>\n<h3>Question 1<\/h3>\n<p>The first method finds the average of the elements of an integer array:<\/p>\n<p><code>public double average(int[] data)<\/code><\/p>\n<p>That is, given an integer array,\u00a0<strong>data<\/strong>, calculate what the average of its elements are and return the average value. For example, the average of\u00a0{1, 3, 2, 5, 8} is 3.8.<\/p>\n<h3>Question 2<\/h3>\n<p>The second method is:<\/p>\n<p><code>public int countInRange(int[] data, int lo, int hi)<\/code><\/p>\n<p>For this, you have to count the number of elements of the array,\u00a0<strong>data<\/strong>, that lie in the range\u00a0<strong>lo<\/strong> to\u00a0<strong>hi<\/strong> <em>inclusive<\/em>, and return the count. For example, if\u00a0<strong>data<\/strong> is the array\u00a0{1, 3, 2, 5, 8} then the call<\/p>\n<p><code>countInRange(data, 2, 5)<\/code><\/p>\n<p>should return 3 because there are three elements, 3, 2 and 5 that lie in the range 2 .. 5.<\/p>\n<h3>Question 3<\/h3>\n<p>The third method,\u00a0<strong>arrayAdd<\/strong>, takes two arrays as parameters and returns a new array that is the sum of the first two.<\/p>\n<p><code>public int[] arrayAdd(int[] R1, int[] R2)<br \/>\n<\/code><br \/>\nThe addition of two arrays yields an array whose elements are the sum of the corresponding elements in the parameter arrays, i.e.<\/p>\n<p><code>R1[0] + R2[0], R1[1] + R2[1], R1[2] + R2[2], ....<\/code><\/p>\n<h3>Submission instructions<\/h3>\n<p>You will submit your assignment to the Give automated marked system.<\/p>\n<ol>\n<li>From within your assignment 1 BlueJ project, select Project -&gt; Create Jar File\u2026<\/li>\n<li>In the Dialog Box that appears:\n<ol type=\"a\">\n<li>Set \u201cMain Class\u201d to none<\/li>\n<li>Ensure \u201cInclude Source\u201d is checked<\/li>\n<li>Leave \u201cInclude Bluej project files\u201d unchecked<\/li>\n<\/ol>\n<\/li>\n<li>Press \u201cContinue\u201d<\/li>\n<li>Save the filename as \u201cAssignment1.jar\u201d<\/li>\n<li>Open a web browser and go to\u00a0<a href=\"https:\/\/cgi.cse.unsw.edu.au\/~give\/Student\/give.php\">the give web site<\/a><\/li>\n<li>Log-in with you Z-Pass<\/li>\n<li>Either enter \u201cCOMP1400\u2033 in for the course, or select COMP1400 from the drop down menu and press \u201cSearch for Assignments\u201d. Note INFSi1609\/2609 students may need to enter \u201cCOMP1400\u2033 instead of selecting the course form the dropdown<\/li>\n<li>Select \u201cassignment1\u2033 from the next drop down menu and press \u201cUpload my Assignment\u201d<\/li>\n<li>Accept the student declaration<\/li>\n<li>Press \u201cChoose File\u201d and select the \u201cAssignment1.jar\u201d file that you saved in step 4<\/li>\n<li>Press \u201cSubmit my Files\u201d<\/li>\n<li>Wait for the page to completely load. Then carefully read the output. If the assignment is successful you should see the following lines:\n<pre>================================================\r\nChecking your submission...\r\n\r\nChecking for Assignment1.java\r\nAssignment1.java Compiled Sucessfully\r\n\r\nAll files are OK\r\n================================================<\/pre>\n<\/li>\n<li>If the page doesn\u2019t load properly, that is OK just submit the assignment file again.<\/li>\n<li>If you don\u2019t get the above output check the output to see what went wrong and resubmit.<\/li>\n<\/ol>\n<p>Submission notes:<\/p>\n<ol>\n<li>You can submit as many times as you wish, even after the deadline. Only your last submission will be marked.<\/li>\n<li>Make sure you name everything the as instructed, including the classes and the submission file or the submission will not work.<\/li>\n<li>If you have any problems with submission, email\u00a0<a href=\"mailto:cs1400@cse.unsw.edu.au\">the class account<\/a><\/li>\n<\/ol>\n<p>&nbsp;<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Due: 11:59pm Sunday 1 September (i.e. the end of week 5) This assignment is about loops arrays. You will write three methods to manipulate arrays. The first two are easy. The third one will require more thought about the design. You will submit the assignment using the CSE\u00a0give system (see below). Download the BlueJ project,\u00a0Assignment1.zip. [&hellip;]<\/p>\n","protected":false},"author":328,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[468],"tags":[],"class_list":["post-531","post","type-post","status-publish","format-standard","hentry","category-assignments"],"_links":{"self":[{"href":"https:\/\/blogs.unsw.edu.au\/comp1400\/wp-json\/wp\/v2\/posts\/531","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/blogs.unsw.edu.au\/comp1400\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/blogs.unsw.edu.au\/comp1400\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/blogs.unsw.edu.au\/comp1400\/wp-json\/wp\/v2\/users\/328"}],"replies":[{"embeddable":true,"href":"https:\/\/blogs.unsw.edu.au\/comp1400\/wp-json\/wp\/v2\/comments?post=531"}],"version-history":[{"count":8,"href":"https:\/\/blogs.unsw.edu.au\/comp1400\/wp-json\/wp\/v2\/posts\/531\/revisions"}],"predecessor-version":[{"id":552,"href":"https:\/\/blogs.unsw.edu.au\/comp1400\/wp-json\/wp\/v2\/posts\/531\/revisions\/552"}],"wp:attachment":[{"href":"https:\/\/blogs.unsw.edu.au\/comp1400\/wp-json\/wp\/v2\/media?parent=531"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/blogs.unsw.edu.au\/comp1400\/wp-json\/wp\/v2\/categories?post=531"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/blogs.unsw.edu.au\/comp1400\/wp-json\/wp\/v2\/tags?post=531"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}