{"id":124,"date":"2011-08-06T17:11:11","date_gmt":"2011-08-07T00:11:11","guid":{"rendered":"http:\/\/blogs.unsw.edu.au\/infs1609\/?p=124"},"modified":"2011-08-08T18:51:30","modified_gmt":"2011-08-09T01:51:30","slug":"tutorial-week-4","status":"publish","type":"post","link":"https:\/\/blogs.unsw.edu.au\/infs1609\/blog\/2011\/08\/tutorial-week-4\/","title":{"rendered":"Tutorial  &#8211; Week 4"},"content":{"rendered":"<h3>Task 1: Universities<\/h3>\n<p>Suppose we were writing a program to administer a university. Discuss:<\/p>\n<ul>\n<li>What are the different levels of abstraction we might use to represent the university?<\/li>\n<li>Choose an object at the mid-level of your hierarchy. What kind of public interface might it provide? What private implementation details might it hide?<\/li>\n<\/ul>\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 shoud a Ticket carry?<\/li>\n<li>Create a constructor to initialise these fields.<\/li>\n<li>Now modify purchaseTicket on the TicketMachine class so that it creates a new Ticket 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 Ticket 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 TicketMachine. 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\/~is1609\/11s2\/tuts\/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","protected":false},"excerpt":{"rendered":"<p>Task 1: Universities Suppose we were writing a program to administer a university. Discuss: What are the different levels of abstraction we might use to represent the university? Choose an object at the mid-level of your hierarchy. What kind of public interface might it provide? What private implementation details might it hide? Task 2: Return [&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-124","post","type-post","status-publish","format-standard","hentry","category-tutorials"],"_links":{"self":[{"href":"https:\/\/blogs.unsw.edu.au\/infs1609\/wp-json\/wp\/v2\/posts\/124","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=124"}],"version-history":[{"count":6,"href":"https:\/\/blogs.unsw.edu.au\/infs1609\/wp-json\/wp\/v2\/posts\/124\/revisions"}],"predecessor-version":[{"id":137,"href":"https:\/\/blogs.unsw.edu.au\/infs1609\/wp-json\/wp\/v2\/posts\/124\/revisions\/137"}],"wp:attachment":[{"href":"https:\/\/blogs.unsw.edu.au\/infs1609\/wp-json\/wp\/v2\/media?parent=124"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/blogs.unsw.edu.au\/infs1609\/wp-json\/wp\/v2\/categories?post=124"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/blogs.unsw.edu.au\/infs1609\/wp-json\/wp\/v2\/tags?post=124"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}