CISC 3130 — Lab #1

CISC 3130
Data Structures
Lab #1
A Set Container

How to Develop and Submit your Labs

Make sure you read the sections in the above on how to interpret CodeLab string comparison feedback

Lab 1 — A Resizeable, Generic Set Container

Overview

Write a 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.

Details

You should also create an app illustrating the capabilities of the class; here is the expected output of the app I want you to write:
=== 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
Notes
  • The app is sort of a reverse engineering challenge; I supply the output and you have to figure out code that produces the output.
    • The resulting experience should be quite useful in your understanding the semantics of the container you are writing.
    • I started off using the VectorApp as a guide; you might want to as well
Takeaways
  • This exercise is in close correspondence to the Vector class of the lecture notes; the main difference is in the behavior of a set vs vector
    • Use it to practice your IDE skills of copying from other code: the Vector in the lecture notes
    • A reasonable approach is to start with the code from 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).
  • It's a warm-up for the subsequent labs
  • It acts as a contrast to the more sophisticated versions of these containers we will be look at
  • It gets you used to the notion of writing an app that demos (and eventually tests) the class you implement
  • It gives you practice writing code that produces a given output