{"id":87,"date":"2011-07-28T21:02:12","date_gmt":"2011-07-29T04:02:12","guid":{"rendered":"http:\/\/blogs.unsw.edu.au\/infs1609\/?p=87"},"modified":"2011-07-31T06:18:19","modified_gmt":"2011-07-31T13:18:19","slug":"tutorial-week-3-designing-classes","status":"publish","type":"post","link":"https:\/\/blogs.unsw.edu.au\/infs1609\/blog\/2011\/07\/tutorial-week-3-designing-classes\/","title":{"rendered":"Tutorial Week 3 &#8211; Designing Classes"},"content":{"rendered":"<p><strong>Understand Assignment 1<\/strong><\/p>\n<ol>\n<li>Follow the assignment 1 instructions to download the skeleton project.<\/li>\n<li>Make sure you understand what is required. If not ask your tutor.<\/li>\n<\/ol>\n<p><strong>Investigating the TicketMachine:<\/strong><\/p>\n<ol>\n<li>Download the\u00a0<a href=\"http:\/\/www.cse.unsw.edu.au\/~is1609\/11s2\/tuts\/ticketmachine.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<p>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><strong>Design a Class to represent an E-Book. <\/strong><br \/>\nIt should record the following information:<\/p>\n<ul>\n<li>An author<\/li>\n<li>An title<\/li>\n<li>The number of pages<\/li>\n<li>The current page being read.<\/li>\n<\/ul>\n<p>Implement your class in the following steps:<\/p>\n<ol>\n<li>Create a class definition with an appropriate name.<\/li>\n<li>Add appropriate fields. What types will they have? What names will you give them?<\/li>\n<li>Create a constructor to initialise these fields. What starting values will you use?<\/li>\n<li>Create accessor methods to access these fields.<\/li>\n<li>Create mutator methods to allow the use to:\n<ul>\n<li>turn pages forwards and backwards<\/li>\n<li>jump to a specific page<\/li>\n<\/ul>\n<\/li>\n<li>What should happen if they try to access a page outside of the sensible range? How can you implement this?<\/li>\n<li>Create several different books to test your code. What happens if:\n<ul>\n<li>Your book has only one page?<\/li>\n<li>Your book has no pages?<\/li>\n<li>Your book has 1000000000000000000000 pages?<\/li>\n<\/ul>\n<\/li>\n<li>Comment your class to describe what it is for and what each of your methods does.<\/li>\n<\/ol>\n<p>&nbsp;<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Understand Assignment 1 Follow the assignment 1 instructions to download the skeleton project. Make sure you understand what is required. If not ask your tutor. 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 of the TicketMachine class. [&hellip;]<\/p>\n","protected":false},"author":328,"featured_media":0,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[236],"tags":[],"class_list":["post-87","post","type-post","status-publish","format-standard","hentry","category-tutorials"],"_links":{"self":[{"href":"https:\/\/blogs.unsw.edu.au\/infs1609\/wp-json\/wp\/v2\/posts\/87","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/blogs.unsw.edu.au\/infs1609\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/blogs.unsw.edu.au\/infs1609\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/blogs.unsw.edu.au\/infs1609\/wp-json\/wp\/v2\/users\/328"}],"replies":[{"embeddable":true,"href":"https:\/\/blogs.unsw.edu.au\/infs1609\/wp-json\/wp\/v2\/comments?post=87"}],"version-history":[{"count":5,"href":"https:\/\/blogs.unsw.edu.au\/infs1609\/wp-json\/wp\/v2\/posts\/87\/revisions"}],"predecessor-version":[{"id":98,"href":"https:\/\/blogs.unsw.edu.au\/infs1609\/wp-json\/wp\/v2\/posts\/87\/revisions\/98"}],"wp:attachment":[{"href":"https:\/\/blogs.unsw.edu.au\/infs1609\/wp-json\/wp\/v2\/media?parent=87"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/blogs.unsw.edu.au\/infs1609\/wp-json\/wp\/v2\/categories?post=87"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/blogs.unsw.edu.au\/infs1609\/wp-json\/wp\/v2\/tags?post=87"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}