Worksheet 12.02 - Iterators and Data Structures: Lakeside School, Seattle, WA 1
Worksheet 12.02 - Iterators and Data Structures: Lakeside School, Seattle, WA 1
tosses.remove(new Point(10,10));
System.out.println(tosses);
System.out.println( tosses.contains(new Point(-58,100)) );
System.out.println( tosses.size() );
What method inside of the Point class allows .contains() and .remove() to
work like this?
iterator()
Returns an iterator over the elements in this collection.
e. Optional challenge write a static method named playRound that adds some
number of randomly located tosses to the Set. Assume the tosses are within
250 mm vertically and horizontally from the center of the board. Then write
a method called scoreRound that iterates through the Set and computes the
score with the following system:
10 points if you are within 10 mm of the center
5 points if you are within 20 mm of the center
2 points if you are within 100 mm
1 point if you are within 200 mm
3. Java has many types of data structures, but the ones we will study here are the
following:
Set
Operation
Method
Description
union
addAll
intersection
retainAll
difference
removeAl
l
superset/subs
et
contains
All
IN-CLASS EXERCISE
Find a partner who is also at this point in the worksheet. Work together to
create an application to test one of these data structures your choice
among Stack, Queue, or Map. First go to the JavaDoc to see the constructor
syntax and the available methods. Then you will write a short test program
that uses your groups data structure (along the same lines as the Darts
program you just wrote).
This test program should
o Construct the data structure
o Add a few elements
o Print the structure using its toString().
o Demonstrate the use of any other methods that seem important
o Print the elements using an iterator and a loop