600.226 Data Structures -- Spring 2013
Homework #5 -- 60 Points Total
Due 2:30pm on Wednesday, 2/27

The purpose of this assignment is to solidy (review if necessary) basic Java programming skills, as well as learn to work with generics. All parts are based on the Set ADT.

Part A) Set Implementation [20 points]

Write a complete array based implementation of the Set.java interface that was the basis of last week's assignment. There is no limit to how many values a Set may hold, so you must expand the internal array by doubling its capacity as necessary when adding elements (like we did in the BagArray implementation). You must use built-in arrays, and absolutely may not use any Java Collections classes such as ArrayList, etc.

In addition to the methods declared in the interface, you should overload the toString and equals methods from the Object class. Any code that is adapted from lecture files must be clearly referenced as such in a comment. Most of the credit for this assignment will be awarded to methods that cannot be found in our BagArray.java implementation.

You must name your implementation class SetArray. You can test your program using your JUnit test program from homework 4, and we will post a SetTest226.java solution as well. You will need to adapt either of these to instantiate the sets with SetArray objects before running them.

Part B) Implementation Analysis [10 points]

Once you have written your SetArray.java implementation, you are required to analyze the running time of each method, based on a current (this) Set size of N actual elements. For methods with a second set as a parameter, assume that it has M actual elements. Include the analysis as a comment between the javadoc and the header of each method which states the Theta asymptotic complexity, such as Theta(N), Theta(N*M), Theta(1), etc.. You do not have to justify the complexity, but are encouraged to include a short explanation for your own benefit.

Part C) Using Sets [20 points]

Suppose that you were considering several majors and minors, and had a list of the courses that were required for each. You want to easily determine what the total set of courses is that you would have to take, and if any courses are common to all of them. Make your program so that the user specifies upfront whether the course information will be input as names or (floating point) numbers. If names, ignore capitalization. Also the user should specify at the start how many majors and minors are being considered; you can assume this is at most 10.

Here are two short sample runs. Your program must behave in exactly the same way with respect to input and output format. The order of the courses in the unions and intersections may be different.

How many majors/minors?  3
Input course names or numbers?  numbers
Enter courses for each major/minor on a line, separated by spaces:
550.171 350.294 200.249 600.226
660.290 550.171 226.409 600.226 100.203 200.249
600.107 600.226 600.120 200.350 550.171

Courses needed for all: 
{550.171, 350.294, 200.249, 600.226, 660.290, 226.409, 100.203, 600.107, 600.120, 200.350}

Courses common to all:
{550.171, 600.226}


How many majors/minors?  2
Input course names or numbers?  names
Enter courses for field 1, one per line, "X" to stop:
calc I
discrete math
Expository Writing
X
Enter courses for field 2, one per line, "X" to stop:
expository writing
IFP
X

Courses needed for all:
{calc i, discrete math, expository writing, ifp}

Courses common to all:
{expository writing}

A SetArray.class (right click and save) bytecode file is available for you to use with this part of the assignment in case you do not fully succeed in doing part A of the assignment. In that case, please make sure you include our bytecode in your zipped submission!

Part D) Submission & Style [10 points]

You must zip together all source code files needed to compile, test, and run all parts of this assignment, including our Set.java interface and SetTest226.java JUnit test program. Each submission attempt on Blackboard must contain only one zip file that has all the java files in it. (In other words, you must not submit different parts in different submission attempts.) As usual, we will only grade your final submission attempt. If you do not zip all your files together, you are likely to receive a 0 because Blackboard will rename all your files and we will not be able to compile them successfully.

Please also submit a printout (double sided if possible) of your SetArray.java implementation.

All source code must be written in accordance with our checkstyle configuration. (JUnit test programs are the only exception to this.)