Question: I have all the code except for the add method. Please show me how to construct add method. ______________________________________________ For this assignment you are to

I have all the code except for the add method. Please show me how to construct add method.

______________________________________________

I have all the code except for the add method. Please show

me how to construct add method. ______________________________________________ For this assignment you are

For this assignment you are to write a class called SortedIntlist that is a variation of the ArrayIntList class written in our class. Your class has two primary differences from the original list: A Sorted IntList must maintain its list of integers in sorted order (non-decreasing). A sortedIntList has an option to specify that its elements should be unique (no duplicates) * The new class should have the same public methods as ArrayIntList except for the two-parameter add method that adds a value at a particular index. Because we want to keep the list in sorted order, we don't want to give clients the ability to decide where to insert a value, so this method should not be a public method of the new class. Some of the common methods between the two classes will need to be implemented differently in SortedIntList: add and indexOf. You will also add two constructors and the getUnique, setUnique, max, min and count methods. SortedIntList should have the following public methods public sortedIntList () constructs an empty list of a default capacity, allowing duplicates public SortedIntlist (boolean unique) constructs empty list of default capacity and given "unique" setting . * * public SortedIntList(int capacity) constructs an empty list with given capacity, allowing duplicates public SortedIntList (boolean unique, int capacity) constructs an empty list with given capacity and "unique" setting public void add(int value) possibly adds given value to list, maintaining sorted order public void remove (int index) removes value at given index, shifting subsequent values left public int get (int index) returns the element at the given index public int size () returns the number of elements in the list public boolean isEmpty () returns true if the list doesn't contain any elements public int indexOf (int value) same behavior as before, but optimized; see next page public int max ( ) NoSuchElementException if the list is empty) public int min () returns the minimum integer value stored in the list, (throws a NoSuchElementException if the list is empty) public int count(int value) returns the number of times the given value is in the list public boolean getUnique () returns whether only unique values are allowed in the list public void setUnique (boolean unique) sets whether only unique values are allowed in the list; if set to true, immediately removes any existing duplicates from the list . . * . * * * returns the maximum integer value stored in the list, (throws a * * * * . public String tostring) returns a string version of the list, such as "[4, 5, 17]" Your class will have a field to keep track of whether or not it is limited to unique values. The value can be set by your second constructor or by calling setUnique. Think of it as an on/off switch for duplicates that each list has

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!