Answered step by step
Verified Expert Solution
Question
1 Approved Answer
Write a class SortedIntList that is a variation of the ArrayIntList from chapter 1 5 , except: SortedIntList maintains a list of sorted integers in
Write a class SortedIntList that is a variation of the ArrayIntList from chapter except:
SortedIntList maintains a list of sorted integers in nondecreasing order
SortedIntList has an option to specify that its values are unique no duplicates allowed
SortedIntList will have three private fields
int elementData
int size
boolean unique true means duplicates not allowed
The class should have the same public methods as ArrayIntList except for the twoparameter add method. Client
should not have the ability to insert a value at a given index, since this list is sorted, but the class still needs this
ability using a private method. Some of the methods between the two classes are the same, while others will need
to be altered slightly, including add and indexOf.
Required public methods:
Constructors:
Use default capacity and default boolean unique false meaning duplicates allowed
SortedIntListboolean unique, int capacityassigns given unique and given capacity
throws IllegalArgumentException if capacity
SortedIntListboolean uniqueassigns given unique and default capacity
SortedIntListint capacityassigns default unique and given capacity
throws IllegalArgumentException if capacity
SortedIntListassigns default unique and capacity
addint valueadds given value to list, unless unique true and its a duplicate
should utilize indexOfvalue and private addindex value to
reduce redundancy
removeint indexremoves value at given index, shifting subsequent values left
throws IndexOutOfBounds exception, as needed
getint indexreturns the value at the given index
throws IndexOutOfBounds exception as needed
sizereturns the number of values in the list
isEmptyreturns true if the list is empty, false otherwise
indexOfint valueuse Arrays.binarySearchlist size, value to return an index of given value in list
or returns negative the position of where it should be in list if it is not present.
maxreturns the maximum integer value stored in the list
throws a NoSuchElementException if the list is empty
minreturns the minimum integer value stored in the list
throws a NoSuchElementException if the list is empty
countint valuereturns the number of times the given value occurs in the list
utilizes indexOfvalue to avoid sequential search, then
moves forward and back from there to get total
note: binary search returns an index of value, but not necessarily st
getUniquereturns the value of unique truefalse
setUniqueboolean uniquesets unique, if set to true, removes all existing duplicates
toStringreturns a string version of the list, such as
Notes:
SortedIntList will need private methods, to include checkIndex ensureCapacity & addindex value
Test SortedIntList as each method is completed, using a client file.
Do not use any methods from Arrays or Collections objects except Arrays.binarySearch
Look to avoid redundancy throughout, creating private methods as needed to reduce repeated code.
Use Javadoc commenting at the beginning of the class, identifying your information, along with a description
of the class itself. Place additional Javadoc commenting above each method, indicating any parameters,
returned values and preconditions along with throws exception information and concisely listing what the
method does. Additional nonjavadoc commenting can be used to explain any portions of the code that
might be tricky or need further explanation.
Use proper white space conventions and strive for overall clarity in the code.
When you feel everything is working correctly, create a new client or modify the one you are using to test.
Use the client to demonstrate that addvalue works correctly with and without duplicates. Add additional
items to lists then demonstrate that all the methods function as expected. Your output from the client
should print what you are testing. For example:
Adding values to listunique false
Adding same values to listunique true
Remove & from list
setUniquetrue in list
add to listunique true
Etc.
The console output should be copied and pasted into a text or word document and submitted along with a
short reflection on your implementation of SortedIntList. What was easy, what was tricky, what did you need
help with
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started