The goals of this assignment are:
Requirements:
- Every java file should have a header. However, DO NOT PUT YOUR NAME IN YOUR HEADERS. On gradescope we grade your assignments anonymously so including your name in your Java file will defeat that purpose. However, please include your name in your README.txt
- Every method should contain a javdoc that briefly describes the method, lists the params, and the return type/value. Use the notation that we used in lectures.
- All of your instance variables should be
private
. If a subclass will need access to the instance variables, then the instance variables can beprotected
.
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%.
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 String
s.
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..
In addition to implementing all methods in the interface, SuperDuperArray
, the class must include the following:
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.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.
In a text file called README.txt
answer the following questions:
Vet
. Which class would you rather use SuperDuperSortedArray
or SuperDuperSorted
? Make sure to justify your answer - there is no wrong answer here.Dont forget: make sure to fill in the header in all of your java files.
Submit the following files to the assignment called HW09
on Gradescope:
SuperDuperArray.java
SuperDuperSortedArray.java
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.