The main purpose of this lab exercise is to:
HashSet)
How to get started
cs102 for this lab: $ cd cs102 $ mkdir lab5 $ cp -r /home/cs102/bluej/projects/chapter05/bouncing-balls/ ./lab5 Java Exercises
The bouncing-balls BlueJ project is the basis for today’s lab and for next week’s assignment. For today’s lab, read section 5.12.3 on page 190 of the OFJ text. Complete exercises 5.62 – 5.64.
Change the method bounce in class BallDemo to let the user choose how many balls should be bouncing.
For this exercise, you should use a collection to store the balls. This way, the method can deal with 1, 3, or 75 balls–any number you want. The balls should initially be placed in a row along the top of the canvas.
Which type of collection should you choose? So far, we have seen an ArrayList, a HashMap, and a HashSet. Try the next exercises first, before you write your implementation.
Which type of collection (ArrayList, HashMap, HashSet) is moswt suitable for storing the balls for the new bounce method? Discuss in writing, and justify your choice.
Change the bounce method to place the balls randomly anywhere in the top half of the screen.
Whatever methods you implement need a purpose statement (header comment), and tests in the Examples class. Since we’ve now covered Javadoc comments, be sure you use them, and test them in BlueJ by switching between “Source Code” and “Documentation” view when editing your class definition.
Assignment 4. The remaining exercises, 5.65 and 5.66, are left for Assignment 4. You will use your completed Lab 5 as the starting point for Assignment 4.
When you’ve completed the above exercises, alert Marc or one of our coaches to take a look, and check you off as having completed the lab. After you are checked off, follow the submit procedure detailed below.
Submitting your work
From a terminal window, type the following commands at the Linux prompt:
cd cd cs102 submit102 lab5
Log out
When you are done, close BlueJ and logout. Always remember to log out when you are finished using the system, to ensure that no one else uses your account.