{"id":557,"date":"2013-08-30T04:25:34","date_gmt":"2013-08-30T11:25:34","guid":{"rendered":"http:\/\/blogs.unsw.edu.au\/comp1400\/?p=557"},"modified":"2013-08-30T04:36:04","modified_gmt":"2013-08-30T11:36:04","slug":"week-6-lab-more-classes-and-objects","status":"publish","type":"post","link":"https:\/\/blogs.unsw.edu.au\/comp1400\/blog\/2013\/08\/week-6-lab-more-classes-and-objects\/","title":{"rendered":"Week 6 Lab &#8211; More Classes and Objects"},"content":{"rendered":"<h3>Task 1: Universities<\/h3>\n<p>This first task should be attempted <strong><em>before<\/em><\/strong> coming to the lab.<\/p>\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\/~cs1400\/13s2\/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>Task 1: Universities This first task should be attempted before coming to the lab. 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 [&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-557","post","type-post","status-publish","format-standard","hentry","category-lab"],"_links":{"self":[{"href":"https:\/\/blogs.unsw.edu.au\/comp1400\/wp-json\/wp\/v2\/posts\/557","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=557"}],"version-history":[{"count":5,"href":"https:\/\/blogs.unsw.edu.au\/comp1400\/wp-json\/wp\/v2\/posts\/557\/revisions"}],"predecessor-version":[{"id":562,"href":"https:\/\/blogs.unsw.edu.au\/comp1400\/wp-json\/wp\/v2\/posts\/557\/revisions\/562"}],"wp:attachment":[{"href":"https:\/\/blogs.unsw.edu.au\/comp1400\/wp-json\/wp\/v2\/media?parent=557"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/blogs.unsw.edu.au\/comp1400\/wp-json\/wp\/v2\/categories?post=557"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/blogs.unsw.edu.au\/comp1400\/wp-json\/wp\/v2\/tags?post=557"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}