Back to 211 Main Page

Mobius strip

Assignment 3

Submission

  • Email your assignment to ztomasze@hawaii.edu.
  • Attach the source code to your email. Send me only the source code (.java files); do not include the .class or any other files. Do not zip or otherwise bundle the .java files.

Requirements

As stated on the assignment handout, you must:

  • Write two methods (one recursive, one iterative) that sum the contents of a set. Each method should do this by removing the two smallest values in the set, and then inserting their sum back into the set.
  • An empty set has an undefined answer, and so each method should throw an exception in this case.
  • Each method should take only one parameter.

Suggestions

You can use whatever data structure you want for the set. "Set" here is the loose definition, meaning simply a collection of values (since the set will sometimes have to include duplicate values during the summation). An array would work, but will be difficult to use as the only parameter--you will have to resize/copy it each time you call the method. You could implement your own ADT, or reuse one from the textbook. Probably the easiest solution is to look around in the java.util package for some kind of Collection you could use to store the set.

At the end of the calculation, you may return either the set containing only the one remaining value, or just return that value.

I strongly suggest you test your method using the main method of the class you write. The easiest test to use would be to create a set of the values passed in as command line arguments, and then pass this set to each of the two methods and print the results. An alternative is to just hard-code a few different sets in main, and then print out the results for each method given those sets.

Grading:

Out of 100 points:

10 - Compiles
45 - Iterative method
  • Method takes only one parameter (10 points)
  • Method iteratively and correctly sums the set (10 points)
  • Method changes the set during the process of summation, as specified (10 points)
  • Method reports error if given set is initially empty (10 points)
  • Method returns a set of one element (or its single value) unchanged. (5 points)
45 - Recursive method
As per Iterative method, only recursively.


~ztomasze Index : TA Details: ICS211: Assignment 3
http://www2.hawaii.edu/~ztomasze
Last Edited: 09 Oct 2006
©2006 by Z. Tomaszewski.