{"id":609,"date":"2013-10-04T08:14:44","date_gmt":"2013-10-04T15:14:44","guid":{"rendered":"http:\/\/blogs.unsw.edu.au\/comp1400\/?p=609"},"modified":"2013-10-04T08:25:34","modified_gmt":"2013-10-04T15:25:34","slug":"week-10-lab-random-class","status":"publish","type":"post","link":"https:\/\/blogs.unsw.edu.au\/comp1400\/blog\/2013\/10\/week-10-lab-random-class\/","title":{"rendered":"Week 10 Lab &#8211; Random Class"},"content":{"rendered":"<p><strong>Monday labs:<\/strong> Since Monday is a public holiday, the Monday groups should try to go to another lab just for this week.<\/p>\n<p>These exercises are taken from Chapter 5 of the text book. You should also use this week to catch up with previous labs.<\/p>\n<p><strong>Exercise 5.14<\/strong> Write some code (in BlueJ) to test the generation of random numbers. To do this, create a new class called <strong>RandomTester<\/strong>. You can create this class in a new project. In class <strong>RandomTester<\/strong>, implement two methods: <strong>printOneRandom<\/strong> (which prints out one random number) and <strong>printMultiRandom(int howMany)<\/strong> (which has a parameter to specify how many numbers you want, and then prints out the appropriate number of random numbers).<\/p>\n<p><strong>Exercise 5.15<\/strong> Find the <strong>nextInt<\/strong> method in class <strong>Random<\/strong> that allows the target range of random numbers to be specified. What are the possible random numbers that are generated when you call this method with 100 as its parameter?<\/p>\n<p><strong>Exercise 5.16<\/strong> Write a method in your <strong>RandomTester<\/strong> class called <strong>throwDice<\/strong> that returns a random number between 1 and 6 (inclusive).<\/p>\n<p><strong>Exercise 5.17<\/strong> Write a method called <strong>getResponse<\/strong> that randomly returns one if the strings &#8220;yes&#8221;, &#8220;no&#8221;, or &#8220;maybe&#8221;.<\/p>\n<p><strong>Exercise 5.18<\/strong> Extend your <strong>getResponse<\/strong> method so that it uses an <strong>ArrayList<\/strong> to store an arbitrary number of responses and randomly returns one of them. to Store<\/p>\n<p><strong>Exercise 5.19<\/strong> Add a method to your <strong>RandomTester<\/strong> class that takes a parameter max and generates a random number in the range 1 to max (inclusive).<\/p>\n<p><strong>Exercise 5.20<\/strong> Add a method to your <strong>RandomTester<\/strong> class that takes two parameters, <strong>min<\/strong> and <strong>max<\/strong>, and generates a random number in the range <strong>min<\/strong> to <strong>max<\/strong> (inclusive). Rewrite the body of the method you wrote for the previous exercise so that it now calls this new method to generate its result. Note that it should not be necessary to use a loop in this method.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Monday labs: Since Monday is a public holiday, the Monday groups should try to go to another lab just for this week. These exercises are taken from Chapter 5 of the text book. You should also use this week to catch up with previous labs. Exercise 5.14 Write some code (in BlueJ) to test the [&hellip;]<\/p>\n","protected":false},"author":328,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[630],"tags":[],"class_list":["post-609","post","type-post","status-publish","format-standard","hentry","category-lab"],"_links":{"self":[{"href":"https:\/\/blogs.unsw.edu.au\/comp1400\/wp-json\/wp\/v2\/posts\/609","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=609"}],"version-history":[{"count":2,"href":"https:\/\/blogs.unsw.edu.au\/comp1400\/wp-json\/wp\/v2\/posts\/609\/revisions"}],"predecessor-version":[{"id":613,"href":"https:\/\/blogs.unsw.edu.au\/comp1400\/wp-json\/wp\/v2\/posts\/609\/revisions\/613"}],"wp:attachment":[{"href":"https:\/\/blogs.unsw.edu.au\/comp1400\/wp-json\/wp\/v2\/media?parent=609"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/blogs.unsw.edu.au\/comp1400\/wp-json\/wp\/v2\/categories?post=609"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/blogs.unsw.edu.au\/comp1400\/wp-json\/wp\/v2\/tags?post=609"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}