{"id":736,"date":"2014-08-31T21:17:11","date_gmt":"2014-08-31T11:17:11","guid":{"rendered":"http:\/\/blogs.unsw.edu.au\/comp1400\/?p=736"},"modified":"2014-08-31T21:39:08","modified_gmt":"2014-08-31T11:39:08","slug":"week-6-lab-catch-up-and-more-on-classes-and-objects","status":"publish","type":"post","link":"https:\/\/blogs.unsw.edu.au\/comp1400\/blog\/2014\/08\/week-6-lab-catch-up-and-more-on-classes-and-objects\/","title":{"rendered":"Week 6 Lab &#8211; Catch Up and More on Classes and Objects"},"content":{"rendered":"<h3>The self-test quiz for this week is <a href=\"http:\/\/cse.unsw.edu.au\/~cs1400\/14s2\/quizzes\/Week%206%20Quiz.pdf\">here<\/a><\/h3>\n<h3>Task 1: Catch Up<\/h3>\n<p>If you haven&#8217;t completed exercises from previous labs, you may use this week&#8217;s lab to catch up on unfinished work.<\/p>\n<p>If you are up-to-date, you can carry on with the following exercises.<\/p>\n<h3>Task 2: Return to the Ticket Machine<\/h3>\n<p>Go back to the ticket machine project you worked on in last week\u2019s tut.<\/p>\n<ol>\n<li>Create a new class\u00a0<tt>Ticket<\/tt> which represents a ticket.<\/li>\n<li>Create appropriate fields. What information should a Ticket carry?<\/li>\n<li>Create a constructor to initialise these fields.<\/li>\n<li>Now modify <strong>purchaseTicket<\/strong> on the <strong>TicketMachine<\/strong> class so that it creates a new <strong>Ticket<\/strong> object and returns it, rather than printing it.<\/li>\n<\/ol>\n<p>Let\u2019s suppose now that a ticket has 10 charges. Each time we use it, one charge is lost.<\/p>\n<ol>\n<li>Change your <strong>Ticket<\/strong> class to track charges. What changes do you need to make to do this?<\/li>\n<\/ol>\n<p>Now let\u2019s add a\u00a0<tt>recharge<\/tt> method to the <strong>TicketMachine<\/strong>. It should take a\u00a0<tt>Ticket<\/tt> as a parameter and reset its charges to 10 but at the cost of 1\/10th of the ticketPrice for every charge added (if the user has enough balance). Implement this in stages:<\/p>\n<ol>\n<li>Make the method just recharge the Ticket for free.<\/li>\n<li>Compute how much the recharge will cost. You will need to use an accessor method on the Ticket to find out how much charge it has.<\/li>\n<li>Add a test to see if the user has enough balance.<\/li>\n<li>If there is not enough balance print an error message and do not recharge.<\/li>\n<li>Subtract the charge from the balance.<\/li>\n<\/ol>\n<h3>Task 3: Clock (if time permits)<\/h3>\n<p>Take a look at the\u00a0<a href=\"http:\/\/www.cse.unsw.edu.au\/~cs1400\/14s2\/examples\/clock-display.zip\">clock project<\/a> from Chapter 3 of the textbook.<\/p>\n<ol>\n<li>Investigate the NumberDisplay class first. How does it work?<\/li>\n<li>Look at the\u00a0<tt>setValue<\/tt> method. What does the &amp;&amp; operator do? This is a boolean operator. Try experimenting with it in the Code Pad.<\/li>\n<li>Look at the\u00a0<tt>increment<\/tt> method. What does the % operator do? Try experimenting with it in the BlueJ Code Pad.<\/li>\n<li>Now take a look at the ClockDisplay class. Try to understand how it works.<\/li>\n<li>ClockDisplay has two constructors. How do they differ?<\/li>\n<li>The second constructor does not call updateDisplay. Is this a bug? Why\/why not?<\/li>\n<li>Change this class to have a seconds field as well as hours and minutes.<\/li>\n<li>Change the class to show a 12 hour clock with AM\/PM.<\/li>\n<\/ol>\n<p>&nbsp;<\/p>\n","protected":false},"excerpt":{"rendered":"<p>The self-test quiz for this week is here Task 1: Catch Up If you haven&#8217;t completed exercises from previous labs, you may use this week&#8217;s lab to catch up on unfinished work. If you are up-to-date, you can carry on with the following exercises. Task 2: Return to the Ticket Machine Go back to 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-736","post","type-post","status-publish","format-standard","hentry","category-lab"],"_links":{"self":[{"href":"https:\/\/blogs.unsw.edu.au\/comp1400\/wp-json\/wp\/v2\/posts\/736","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=736"}],"version-history":[{"count":2,"href":"https:\/\/blogs.unsw.edu.au\/comp1400\/wp-json\/wp\/v2\/posts\/736\/revisions"}],"predecessor-version":[{"id":738,"href":"https:\/\/blogs.unsw.edu.au\/comp1400\/wp-json\/wp\/v2\/posts\/736\/revisions\/738"}],"wp:attachment":[{"href":"https:\/\/blogs.unsw.edu.au\/comp1400\/wp-json\/wp\/v2\/media?parent=736"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/blogs.unsw.edu.au\/comp1400\/wp-json\/wp\/v2\/categories?post=736"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/blogs.unsw.edu.au\/comp1400\/wp-json\/wp\/v2\/tags?post=736"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}