Vector
class and the lab had you implement a Set
container that has the same properties as the last version (Version 5) of Vector
, i.e., resizeable and generic
(there is no exception handling for Set
.
I would proceed somewhat differently than my recommendation for the Lab #1. There I suggested starting off by copying the
Vector
class and making modifications to it (e.g., removing set
)
to bring it in line with Set
. For this lab I would recommend starting off with your working Set
class of Lab #1, and then merging in the resining code (i.e., checkCapacity), and once that is working,
making it generic. Again. In other words, I'm still suggesting you do one facility at a time (there is no exception handling in this version of Set
since the only exception in the previous version was overflow, which no longer
applies in the context of Details
You should also create an app with the following output:
checkCapacity
method.
=== Basic Functionality ===
--- Creating a Set
VectorApp
at the end of Lecture 2; that's what I started from
Set
of Lab #1 only had overflow, since there was
no get
set there was no bounds-checking exceptions. Now that the container is resizeable, the overflow
exception goes away as well.
{1, 2 ... 9, 10}
) of the set (when it grew too large) is also gone. Without a get
method, there is currently no way to
go through the elements of the set. We will address this eventually.
Codelab Notes
Lab 2.1 has been split into 2.1.1 and 2.1.2 for the purposes of submitting to CodeLab. Lab 2.1.1 is the Set
class, while 2.1.2 is the SetApp
. You should
develop both in IntelliJ first and then submit them separately in CodeLab. (The rationale is to have one working class provided to you, hopefully this should make any errors
easier to detect and fix).
Vector
class of the lecture notes, but it is also very similar to
the Set
container of Lab 1.
Set
and bring in the relvant code from Lecture 2's Vector
.
HashSet
HashSet
(Lab 2.2) and TreeSet
(Lab 2.3).
The spec for each of these two labs is nothing more than the output of the app. Please make sure you read the notes after each output to see what is expected.
Here is the output of Lab 2.2:
=== Basic Functionality === --- Creating a HashSet<Integer> and printing it and its initial stats --- [] (0) --- Loading it up to 10 with add --- Adding 0 -> [0] (1) Adding 1 -> [0, 10] (2) Adding 2 -> [0, 20, 10] (3) Adding 3 -> [0, 20, 10, 30] (4) Adding 4 -> [0, 20, 40, 10, 30] (5) Adding 5 -> [0, 50, 20, 40, 10, 30] (6) Adding 6 -> [0, 50, 20, 40, 10, 60, 30] (7) Adding 7 -> [0, 50, 20, 70, 40, 10, 60, 30] (8) Adding 8 -> [0, 80, 50, 20, 70, 40, 10, 60, 30] (9) Adding 9 -> [0, 80, 50, 20, 70, 40, 10, 90, 60, 30] (10) --- Loading it up with the same elements --- Adding 0 -> [0, 80, 50, 20, 70, 40, 10, 90, 60, 30] (10) Adding 1 -> [0, 80, 50, 20, 70, 40, 10, 90, 60, 30] (10) Adding 2 -> [0, 80, 50, 20, 70, 40, 10, 90, 60, 30] (10) Adding 3 -> [0, 80, 50, 20, 70, 40, 10, 90, 60, 30] (10) Adding 4 -> [0, 80, 50, 20, 70, 40, 10, 90, 60, 30] (10) Adding 5 -> [0, 80, 50, 20, 70, 40, 10, 90, 60, 30] (10) Adding 6 -> [0, 80, 50, 20, 70, 40, 10, 90, 60, 30] (10) Adding 7 -> [0, 80, 50, 20, 70, 40, 10, 90, 60, 30] (10) Adding 8 -> [0, 80, 50, 20, 70, 40, 10, 90, 60, 30] (10) Adding 9 -> [0, 80, 50, 20, 70, 40, 10, 90, 60, 30] (10) --- Membership checking --- set does not contain -50 set does not contain -40 set does not contain -30 set does not contain -20 set does not contain -10 set contains 0 set contains 10 set contains 20 set contains 30 set contains 40 set contains 50 set contains 60 set contains 70 set contains 80 set contains 90 set does not contain 100 set does not contain 110 set does not contain 120 set does not contain 130 set does not contain 140 === Generics === --- HashSet<Double> --- [0.0, 1.0, 2.0, 4.0, 8.0, 9.0, 5.0, 3.0, 6.0, 7.0] --- HashSet<String> --- [Str6, Str5, Str4, Str3, Str2, Str1, Str0] --- HashSet<HashSet<Integer>> --- [[], [0], [0, 1], [0, 1, 2], [0, 1, 2, 3]] === Element Order === --- Adding 10 random values to a HashSet<Integer> using a Random object with seed=12345 --- adding 51 -> [51] adding 80 -> [80, 51] adding 41 -> [80, 51, 41] adding 28 -> [80, 51, 41, 28] adding 55 -> [80, 51, 55, 41, 28] adding 84 -> [80, 51, 84, 55, 41, 28] adding 75 -> [80, 51, 84, 55, 41, 75, 28] adding 2 -> [80, 2, 51, 84, 55, 41, 75, 28] adding 1 -> [80, 1, 2, 51, 84, 55, 41, 75, 28] adding 89 -> [80, 1, 2, 51, 84, 55, 41, 89, 75, 28] [80, 1, 2, 51, 84, 55, 41, 89, 75, 28]
HashSetApp
(CodeLab will probably reject it itherwise anyway)
HashSet
which — while it does have a capacity
qconstructor, does not provide any capacity information to the user, so there's nothing for us to see (as opposed to
our getCapacity
method).
HashSet
printed by the app.
TreeSet
TreeSet
=== Basic Functionality === --- Creating a TreeSet<Integer> and printing it and its initial stats --- [] (0) --- Loading it up to 10 with add --- Adding 0 -> [0] (1) Adding 1 -> [0, 10] (2) Adding 2 -> [0, 10, 20] (3) Adding 3 -> [0, 10, 20, 30] (4) Adding 4 -> [0, 10, 20, 30, 40] (5) Adding 5 -> [0, 10, 20, 30, 40, 50] (6) Adding 6 -> [0, 10, 20, 30, 40, 50, 60] (7) Adding 7 -> [0, 10, 20, 30, 40, 50, 60, 70] (8) Adding 8 -> [0, 10, 20, 30, 40, 50, 60, 70, 80] (9) Adding 9 -> [0, 10, 20, 30, 40, 50, 60, 70, 80, 90] (10) --- Loading it up with the same elements --- Adding 0 -> [0, 10, 20, 30, 40, 50, 60, 70, 80, 90] (10) Adding 1 -> [0, 10, 20, 30, 40, 50, 60, 70, 80, 90] (10) Adding 2 -> [0, 10, 20, 30, 40, 50, 60, 70, 80, 90] (10) Adding 3 -> [0, 10, 20, 30, 40, 50, 60, 70, 80, 90] (10) Adding 4 -> [0, 10, 20, 30, 40, 50, 60, 70, 80, 90] (10) Adding 5 -> [0, 10, 20, 30, 40, 50, 60, 70, 80, 90] (10) Adding 6 -> [0, 10, 20, 30, 40, 50, 60, 70, 80, 90] (10) Adding 7 -> [0, 10, 20, 30, 40, 50, 60, 70, 80, 90] (10) Adding 8 -> [0, 10, 20, 30, 40, 50, 60, 70, 80, 90] (10) Adding 9 -> [0, 10, 20, 30, 40, 50, 60, 70, 80, 90] (10) --- Membership checking --- set does not contain -50 set does not contain -40 set does not contain -30 set does not contain -20 set does not contain -10 set contains 0 set contains 10 set contains 20 set contains 30 set contains 40 set contains 50 set contains 60 set contains 70 set contains 80 set contains 90 set does not contain 100 set does not contain 110 set does not contain 120 set does not contain 130 set does not contain 140 === Generics === --- TreeSet<Double> --- [0.0, 1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0, 9.0] --- TreeSet<String> --- [Str0, Str1, Str2, Str3, Str4, Str5, Str6] === Element Order === --- Adding 10 random values to A TreeSet<Integer> using a Random object with seed=12345 --- adding 51 -> [51] adding 80 -> [51, 80] adding 41 -> [41, 51, 80] adding 28 -> [28, 41, 51, 80] adding 55 -> [28, 41, 51, 55, 80] adding 84 -> [28, 41, 51, 55, 80, 84] adding 75 -> [28, 41, 51, 55, 75, 80, 84] adding 2 -> [2, 28, 41, 51, 55, 75, 80, 84] adding 1 -> [1, 2, 28, 41, 51, 55, 75, 80, 84] adding 89 -> [1, 2, 28, 41, 51, 55, 75, 80, 84, 89] [1, 2, 28, 41, 51, 55, 75, 80, 84, 89]
TreeSet
doesn't even have a capacity constructor.
Vector
class of the lecture notes, but it is also very similar to
the Set
container of Lab 1.
Set
and bring in the relvant code from Lecture 2's Vector
.