{"id":381,"date":"2012-08-02T20:07:24","date_gmt":"2012-08-03T03:07:24","guid":{"rendered":"http:\/\/blogs.unsw.edu.au\/comp1400\/?p=381"},"modified":"2012-08-02T20:07:25","modified_gmt":"2012-08-03T03:07:25","slug":"tutorial-wk4","status":"publish","type":"post","link":"https:\/\/blogs.unsw.edu.au\/comp1400\/blog\/2012\/08\/tutorial-wk4\/","title":{"rendered":"Tutorial &#8211; Wk4"},"content":{"rendered":"<p>This week, you will download the BlueJ project <a href=\"http:\/\/www.cse.unsw.edu.au\/~is1609\/12s2\/examples\/Week4.zip\">Week4.zip<\/a> and write methods to manipulate arrays. Two methods are given to you complete. You don\u2019t have to do anything to them.<\/p>\n<p>The method <strong>readArray<\/strong><\/p>\n<p><code>public int[] readArray()<br \/>\n<\/code><br \/>\nreads a list of numbers, one per line, ending with a blank line, and returns an array containing the numbers. Don\u2019t try to understand the details of this method. It uses things that you\u2019ll learn about later.<\/p>\n<p>The method <strong>printArray<\/strong> takes an integer array parameter and prints it to the terminal<\/p>\n<p><code>public void printArray(int[] R)<br \/>\n<\/code><br \/>\nThe project provides templates for other methods that you have to write. Your job is to work out the code that goes inside them.<\/p>\n<p>The first method, <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], ....<br \/>\n<\/code><br \/>\nThe <strong>dotProduct<\/strong> of two arrays returns a single integer.<\/p>\n<p>public int dotProduct(int[] R1, int[] R2)<\/p>\n<p>It is found by multiplying corresponding elements and adding them all up, i.e.<\/p>\n<p><code>R1[0] * R2[0] + R1[1] * R2[1] + R1[2] * R2[2], ....<br \/>\n<\/code><br \/>\nFinally, you should write a method, <strong>main<\/strong>,<\/p>\n<p><code>public void main()<br \/>\n<\/code><br \/>\nthat reads two arrays, then:<\/p>\n<p>calls <strong>arrayAdd<\/strong> and calls <strong>printArray<\/strong> to print the resulting array<br \/>\ncalls <strong>dotProduct<\/strong> and prints the result<\/p>\n","protected":false},"excerpt":{"rendered":"<p>This week, you will download the BlueJ project Week4.zip and write methods to manipulate arrays. Two methods are given to you complete. You don\u2019t have to do anything to them. The method readArray public int[] readArray() reads a list of numbers, one per line, ending with a blank line, and returns an array containing the [&hellip;]<\/p>\n","protected":false},"author":80,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[630],"tags":[],"class_list":["post-381","post","type-post","status-publish","format-standard","hentry","category-lab"],"_links":{"self":[{"href":"https:\/\/blogs.unsw.edu.au\/comp1400\/wp-json\/wp\/v2\/posts\/381","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\/80"}],"replies":[{"embeddable":true,"href":"https:\/\/blogs.unsw.edu.au\/comp1400\/wp-json\/wp\/v2\/comments?post=381"}],"version-history":[{"count":4,"href":"https:\/\/blogs.unsw.edu.au\/comp1400\/wp-json\/wp\/v2\/posts\/381\/revisions"}],"predecessor-version":[{"id":385,"href":"https:\/\/blogs.unsw.edu.au\/comp1400\/wp-json\/wp\/v2\/posts\/381\/revisions\/385"}],"wp:attachment":[{"href":"https:\/\/blogs.unsw.edu.au\/comp1400\/wp-json\/wp\/v2\/media?parent=381"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/blogs.unsw.edu.au\/comp1400\/wp-json\/wp\/v2\/categories?post=381"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/blogs.unsw.edu.au\/comp1400\/wp-json\/wp\/v2\/tags?post=381"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}