{"id":753,"date":"2014-09-14T19:30:36","date_gmt":"2014-09-14T09:30:36","guid":{"rendered":"http:\/\/blogs.unsw.edu.au\/comp1400\/?p=753"},"modified":"2014-09-22T00:09:09","modified_gmt":"2014-09-21T14:09:09","slug":"week-8-lab-arraylists-and-classes-2","status":"publish","type":"post","link":"https:\/\/blogs.unsw.edu.au\/comp1400\/blog\/2014\/09\/week-8-lab-arraylists-and-classes-2\/","title":{"rendered":"Week 8 Lab &#8211; ArrayLists and Classes"},"content":{"rendered":"<p><strong>The self-test quiz for week 8 is <a href=\"http:\/\/cse.unsw.edu.au\/~cs1400\/14s2\/quizzes\/Week%208%20Quiz.pdf\">here<\/a>.<\/strong><\/p>\n<h2>ArrayLists and Classes<\/h2>\n<p>Download the BlueJ project\u00a0<a title=\"club.zip\" href=\"http:\/\/www.cse.unsw.edu.au\/~cs1400\/14s2\/examples\/club.zip\">club.zip<\/a> for this week\u2019s exercises. There are three classes in the project that help you to represent a club and its members.<\/p>\n<p>The\u00a0<strong>Member<\/strong> class is fully defined and contains all the methods you need. Note a couple of things we haven\u2019t covered in lectures. The constructor uses a\u00a0<strong>throw<\/strong> statement to create a Java runtime error. Try entering a month with a number outside the range 1 .. 12 and see what happens.<\/p>\n<p>The\u00a0<strong>Member<\/strong> class also defines a method called\u00a0<strong>toString<\/strong>. This returns a string representation of the object. If you try to print the object using System.out.println, the system will used\u00a0<strong>toString<\/strong> to convert your object into a string for printing.<\/p>\n<p>The\u00a0<strong>ClubDemo<\/strong> class is the \u201cmain\u201d class that we use to create a club and members and test the other classes.<\/p>\n<p>The\u00a0<strong>Club<\/strong> class is incomplete. The methods in the class are empty and your job is to write the code inside to make them work.<\/p>\n<h3>Question 1<\/h3>\n<p>The club class needs a way of storing a collection of members. You should use an ArrayList to do that. The class includes two constructors. Let\u2019s start with the first one. It should initialise the ArrayList and leave it empty.<\/p>\n<h3>Question 2<\/h3>\n<p>The\u00a0<strong>Join<\/strong> method is passed a new member as an argument. You should add this member to the ArrayList.<\/p>\n<h3>Question 3<\/h3>\n<p>The\u00a0<strong>numberOfMembers<\/strong> should return the number of elements in the ArrayList.<\/p>\n<h3>Question 4<\/h3>\n<p>The\u00a0<strong>listMembers<\/strong> method should go through the ArrayList of members and print each one, one per line.<\/p>\n<h3>Question 5<\/h3>\n<p>The\u00a0<strong>removeMember<\/strong> method should remove a member from the ArrayList when a member decides to leave the club. The argument to the method is a string, which is the member\u2019s name. You have to search the ArrayList to find the member with that name. Use a simple algorithm, just go through the list, one-by-one until you find the member with the given name and remove it from the ArrayList.<\/p>\n<h3>Question 6<\/h3>\n<p>The second constructor in the class allows you to pass an array of members. Initialise the club membership with the members in the array.<\/p>\n<p>&nbsp;<\/p>\n","protected":false},"excerpt":{"rendered":"<p>The self-test quiz for week 8 is here. ArrayLists and Classes Download the BlueJ project\u00a0club.zip for this week\u2019s exercises. There are three classes in the project that help you to represent a club and its members. The\u00a0Member class is fully defined and contains all the methods you need. Note a couple of things we haven\u2019t [&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-753","post","type-post","status-publish","format-standard","hentry","category-lab"],"_links":{"self":[{"href":"https:\/\/blogs.unsw.edu.au\/comp1400\/wp-json\/wp\/v2\/posts\/753","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=753"}],"version-history":[{"count":5,"href":"https:\/\/blogs.unsw.edu.au\/comp1400\/wp-json\/wp\/v2\/posts\/753\/revisions"}],"predecessor-version":[{"id":767,"href":"https:\/\/blogs.unsw.edu.au\/comp1400\/wp-json\/wp\/v2\/posts\/753\/revisions\/767"}],"wp:attachment":[{"href":"https:\/\/blogs.unsw.edu.au\/comp1400\/wp-json\/wp\/v2\/media?parent=753"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/blogs.unsw.edu.au\/comp1400\/wp-json\/wp\/v2\/categories?post=753"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/blogs.unsw.edu.au\/comp1400\/wp-json\/wp\/v2\/tags?post=753"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}