Answered step by step
Verified Expert Solution
Link Copied!

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 15, except:
SortedIntList maintains a list of sorted integers in non-decreasing 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 two-parameter 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 =10 and default (boolean) unique = false (meaning duplicates allowed)
SortedIntList(boolean unique, int capacity)//assigns given unique and given capacity
//throws IllegalArgumentException if capacity <0
SortedIntList(boolean unique)//assigns given unique and default capacity
SortedIntList(int capacity)//assigns default unique and given capacity
//throws IllegalArgumentException if capacity <0
SortedIntList()//assigns default unique and capacity
add(int value)//adds given value to list, unless unique = true and its a duplicate
//should utilize indexOf(value) and private add(index, value) to
//reduce redundancy
remove(int index)//removes value at given index, shifting subsequent values left
//throws IndexOutOfBounds exception, as needed
get(int index)//returns the value at the given index
//throws IndexOutOfBounds exception as needed
size()//returns the number of values in the list
isEmpty()//returns true if the list is empty, false otherwise
indexOf(int value)//use Arrays.binarySearch(list,0, 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.
max()//returns the maximum integer value stored in the list
//throws a NoSuchElementException if the list is empty
min()//returns the minimum integer value stored in the list
//throws a NoSuchElementException if the list is empty
count(int value)//returns the number of times the given value occurs in the list
//utilizes indexOf(value) 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 1st)
getUnique()//returns the value of unique (true/false)
setUnique(boolean unique)//sets unique, if set to true, removes all existing duplicates
toString()//returns a string version of the list, such as "[4,5,17]"
Notes:
SortedIntList will need private methods, to include checkIndex(), ensureCapacity() & add(index, 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 (non-javadoc) 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 add(value) works correctly with and without duplicates. Add additional
items to list(s), then demonstrate that all the methods function as expected. Your output from the client
should print what you are testing. For example:
Adding values 2,5,7,56,5,56,5 to list1(unique = false)
[2,5,5,5,7,56,56]
Adding same values to list2(unique = true)
[2,5,7,56]
Remove 5 & 7 from list1
[2,56,56]
setUnique(true) in list1
[2,56]
add(56) to list1(unique = true)
[2,56]
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

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Concepts of Database Management

Authors: Philip J. Pratt, Joseph J. Adamski

7th edition

978-1111825911, 1111825912, 978-1133684374, 1133684378, 978-111182591

More Books

Students also viewed these Databases questions

Question

Are there any changes you would recommend in the selection process?

Answered: 1 week ago