Set
container class that is analogous to the Vector
class presented in class, but is a container with the storage/retrieval properties of a set,
i.e., the container does not contain duplicate values, and allows one to determine if a value is an element of the set.
The set should have dynamic, fixed capacity, i.e., the capacity should be specified in the constructor, thus allowing for sets of different capacities.
get
and set
methods are not present in this class
contains
that accepts a value and returns whether the value is an element of the set
add
that accepts a value and adds it to the set if it's not already there
Vector
, your Set
should have a default constructor, as well as a single argument constructor that accepts a capacity
toString
method, again analogous to Vector
.
=== Testing a Set capacity: 5 size: 0 s: {} Filling up the set Added 10 -> {10} Added 20 -> {10, 20} Added 30 -> {10, 20, 30} Added 40 -> {10, 20, 30, 40} Added 50 -> {10, 20, 30, 40, 50} Adding the same numbers again Added 10 -> {10, 20, 30, 40, 50} Added 20 -> {10, 20, 30, 40, 50} Added 30 -> {10, 20, 30, 40, 50} Added 40 -> {10, 20, 30, 40, 50} Added 50 -> {10, 20, 30, 40, 50} Adding 999 -- a new value Successfully caught: java.lang.IllegalStateException: Exceeded capacity of 5 === Testing a Set capacity: 10 size: 0 s: {} Filling up the set Added 10 -> {10} Added 20 -> {10, 20} Added 30 -> {10, 20, 30} Added 40 -> {10, 20, 30, 40} Added 50 -> {10, 20, 30, 40, 50} Added 60 -> {10, 20, 30, 40, 50, 60} Added 70 -> {10, 20, 30, 40, 50, 60, 70} Added 80 -> {10, 20, 30, 40, 50, 60, 70, 80} Added 90 -> {10, 20, 30, 40, 50, 60, 70, 80, 90} Added 100 -> {10, 20, 30, 40, 50, 60, 70, 80, 90, 100} Adding the same numbers again Added 10 -> {10, 20, 30, 40, 50, 60, 70, 80, 90, 100} Added 20 -> {10, 20, 30, 40, 50, 60, 70, 80, 90, 100} Added 30 -> {10, 20, 30, 40, 50, 60, 70, 80, 90, 100} Added 40 -> {10, 20, 30, 40, 50, 60, 70, 80, 90, 100} Added 50 -> {10, 20, 30, 40, 50, 60, 70, 80, 90, 100} Added 60 -> {10, 20, 30, 40, 50, 60, 70, 80, 90, 100} Added 70 -> {10, 20, 30, 40, 50, 60, 70, 80, 90, 100} Added 80 -> {10, 20, 30, 40, 50, 60, 70, 80, 90, 100} Added 90 -> {10, 20, 30, 40, 50, 60, 70, 80, 90, 100} Added 100 -> {10, 20, 30, 40, 50, 60, 70, 80, 90, 100} Adding 999 -- a new value Successfully caught: java.lang.IllegalStateException: Exceeded capacity of 10
VectorApp
as a guide; you might want to as well
Vector
class of the lecture notes; the main difference is in the behavior
of a set vs vector
Vector
in the lecture notes
Vector and begin your modifications from there.
- This is in contrast to my advice to 1115 students where I tell them (at least in the beginning) NOT to copy any code; they
need to train their muscle memory. ASt the 3130 stage, however, that memory is already ingrained, and copy is the name of the game
when possible (and permissiboe).