{"id":548,"date":"2013-08-22T23:06:05","date_gmt":"2013-08-23T06:06:05","guid":{"rendered":"http:\/\/blogs.unsw.edu.au\/comp1400\/?p=548"},"modified":"2013-08-22T23:06:43","modified_gmt":"2013-08-23T06:06:43","slug":"lab-week-5-arrays-and-classes","status":"publish","type":"post","link":"https:\/\/blogs.unsw.edu.au\/comp1400\/blog\/2013\/08\/lab-week-5-arrays-and-classes\/","title":{"rendered":"Lab Week 5 &#8211; Arrays and Classes"},"content":{"rendered":"<p>If you didn&#8217;t finish last week&#8217;s exercises, continue on with those. In particular, make sure you understand how to use loops and arrays (i.e. the last two exercises).<\/p>\n<h2>Classes<\/h2>\n<p><strong>Investigating the TicketMachine:<\/strong><\/p>\n<ol>\n<li>Download the\u00a0<a href=\"http:\/\/www.cse.unsw.edu.au\/~cs1400\/13s2\/examples\/ticket_machine.zip\">TicketMachine project<\/a> we have been building in lectures. Unzip it on your desktop and open the project with BlueJ.<\/li>\n<li>Create an instance of the TicketMachine class.<\/li>\n<li>Experiment with the addMoney() method. What happens if you:\n<ul>\n<li>Add 0 cents?<\/li>\n<li>Add an negative amount?<\/li>\n<\/ul>\n<\/li>\n<li>Is this behaviour correct?<\/li>\n<li>Experiment with the purchaseTicket() method. Does it work correctly? Try a number of different tests to make sure.<\/li>\n<li>Open up the source and place a breakpoint at the beginning of the purchaseTicket() method by clicking in the grey bar on the left. A little stop sign should appear.<\/li>\n<li>Call the method again and use the Debugger to step through the code.<\/li>\n<li>Try this with different balances to see how the execution varies.<\/li>\n<li>There is a bug in this method. Can you find it?<\/li>\n<\/ol>\n<p><strong>Extending the TicketMachine<\/strong><\/p>\n<p>Let us extend the ticket machine to keep track of the total amount of cash collected and to allow us to change ticket prices.<\/p>\n<ol>\n<li>Add a new field to the class to store the total cash collected.<\/li>\n<li>When does this value change? What methods will you need to modify to track these changes?<\/li>\n<li>Add a new accessor method getTotal() to return the value.<\/li>\n<li>Test your code with a variety of method calls to make sure it does the right thing.<\/li>\n<li>Add a new mutator method setPrice() to allow you to change the ticket price.<\/li>\n<li>What happens if you set the ticket price to zero? a negative number?<\/li>\n<li>Add a conditional statement to set-price to stop the price from being set to a negative value.<\/li>\n<\/ol>\n<p>&nbsp;<\/p>\n","protected":false},"excerpt":{"rendered":"<p>If you didn&#8217;t finish last week&#8217;s exercises, continue on with those. In particular, make sure you understand how to use loops and arrays (i.e. the last two exercises). Classes Investigating the TicketMachine: Download the\u00a0TicketMachine project we have been building in lectures. Unzip it on your desktop and open the project with BlueJ. Create an instance [&hellip;]<\/p>\n","protected":false},"author":328,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1],"tags":[],"class_list":["post-548","post","type-post","status-publish","format-standard","hentry","category-uncategorized"],"_links":{"self":[{"href":"https:\/\/blogs.unsw.edu.au\/comp1400\/wp-json\/wp\/v2\/posts\/548","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=548"}],"version-history":[{"count":3,"href":"https:\/\/blogs.unsw.edu.au\/comp1400\/wp-json\/wp\/v2\/posts\/548\/revisions"}],"predecessor-version":[{"id":551,"href":"https:\/\/blogs.unsw.edu.au\/comp1400\/wp-json\/wp\/v2\/posts\/548\/revisions\/551"}],"wp:attachment":[{"href":"https:\/\/blogs.unsw.edu.au\/comp1400\/wp-json\/wp\/v2\/media?parent=548"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/blogs.unsw.edu.au\/comp1400\/wp-json\/wp\/v2\/categories?post=548"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/blogs.unsw.edu.au\/comp1400\/wp-json\/wp\/v2\/tags?post=548"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}