MyArrayList++ (Extension Exercise) In this exercise we'll expand upon the MyArrayList exercise but removing the requirem

Business, Finance, Economics, Accounting, Operations Management, Computer Science, Electrical Engineering, Mechanical Engineering, Civil Engineering, Chemical Engineering, Algebra, Precalculus, Statistics and Probabilty, Advanced Math, Physics, Chemistry, Biology, Nursing, Psychology, Certifications, Tests, Prep, and more.
Post Reply
answerhappygod
Site Admin
Posts: 899603
Joined: Mon Aug 02, 2021 8:13 am

MyArrayList++ (Extension Exercise) In this exercise we'll expand upon the MyArrayList exercise but removing the requirem

Post by answerhappygod »

MyArrayList++ (Extension Exercise)
In this exercise we'll expand upon the MyArrayList exercise but
removing the requirement that the maximum size of the list be 6. It
will still be back with an array, but now the final size of the
array can be anything (well, not negative of course). We will also
add the ability to remove elements (so the list can get
smaller).
There are some changes in the details of how the class works, so
read the directions carefully.
This time, you also start with no data members, so you will have
to create your own array (and anything else you need).
The main structure of the task however is the same. To complete
the task, you will need to complete the following methods:
A constructor that accepts nothing (i.e. that has no arguments)
that sets up anything that needs to be set up.
add(int) - adds a new element to the end of the list. This
should always succeed, so we don't need to return anything.
int get(int) - returns the value at the specified position, if
the position exists in the list. If not, return 0.
set(int, int) - replace the element at the specified position
with the new value. If the position doesn't exist in the list, do
nothing.
size() - return the current size of the list.
remove(int) - remove the element at the specified position. If
the position doesn't exist in the list, do nothing.
int[] toArray() - return the elements of the list as an array,
in the same order. The returned array should have the same length
as the size of the list (not the length of the internal array in
the class).
replace(int, int) - replaces the first occurrence of the first
parameter value in the list with the second. Any further
occurrences are untouched.
boolean contains(int) - returns true if the element is in the
list, false otherwise.
boolean isEmpty() - returns true if there are no elements in the
list, false otherwise.
clear() - empties the list.
Join a community of subject matter experts. Register for FREE to view solutions, replies, and use search function. Request answer by replying!
Post Reply