Skip to main content
This is an Extra Credit assignment! But to receive the extra credit, you must submit the full assignment. Partial submissions will not be accepted.

Homework 09: SuperArrays - Extra Credit

The goals of this assignment are:

Requirements:

WARNING: In this assignment you are NOT ALLOWED to import any packages. For example, you cannot use the builtin Arrays java class to print out an array. Doing so will result in earning ZERO POINTS for a method that uses it.

IF YOUR CODE DOES NOT COMPILE, YOUR SUBMISSION WILL BE DEDUCTED ATLEAST 10%.

1. Overview

In this last assignment, you will implement two classes: SuperDuperArray and SuperDuperSortedArray. These classes will implement the interface called SuperArray. We will provide you the interface called SuperArray that we provide.

You can find the interface here.

Both classes will keep track of an array of Strings.

For both of these classes, the toString() method should return one line that contains all the Strings. Each string should be seperated by a comma and space between each item. The last item should not have a trailing comma and space.

Make sure to test all of the instance methods in each class.

In the javadocs, make sure to write the big-O runtime for each method that you implement..

2. SuperDuperArray

In addition to implementing all methods in the interface, SuperDuperArray, the class must include the following:

  1. a method called sort() that takes in an integer to determine whether to sort in ascending or descending order. 1 means ascending and 2 means descending. The sort method must return a new sorted array. You are free to use Bubble or Selection Sort. You can use the built-in String methods for determining whether one String is greater than another.
  2. The class must retain the order in which the elements were added.

2. SuperDuperSortedArray

Unlike SuperDuperArray, this class must always keep the elements sorted. This means the implementation for add() will be a bit different. One approach would be to add the element and then sort the elements, however, this approach would be \(O(n^2)\). For full points, come up with a faster approach.

Since the Strings in SuperDuperSortedArray are stored in order, the implementation for the contains() method can also be faster that SuperDuperArray’s.

README.txt

In a text file called README.txt answer the following questions:

  1. Imagine you are building a program to keep records for a Vet. Which class would you rather use SuperDuperSortedArray or SuperDuperSorted? Make sure to justify your answer - there is no wrong answer here.
  2. Next, make an argument for why it would be a good idea to use the other class that you didnt advocate for before.
  3. How much time did you spend on the homework
  4. What did you learn from this homework
  5. optional: What did you struggle with during this homework
  6. optional: any other feedback you would like to share

Dont forget: make sure to fill in the header in all of your java files.

Submitting

Submit the following files to the assignment called HW09 on Gradescope:

  1. SuperDuperArray.java
  2. SuperDuperSortedArray.java
  3. README.txt

Make sure to name these files exactly what we specify here and name the methods exactly what we specify too. Otherwise, our autograders might not work and we might have to take points off.