Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Description Feedback In this exercise we'll expand upon the MyArrayList exercise but removing the requirement that the maximum size of the list be 6.

image text in transcribedimage text in transcribedimage text in transcribedimage text in transcribedimage text in transcribedimage text in transcribed

Description Feedback 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 index position, if the position exists in the list. If not, return 0. Workspace Description Feedback set(int, int) - replace the element at the specified index position with the new value. If the index 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 index 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. Hint Expand Workspace + MyArrayList.java 1 public class MyArrayList { public MyArrayList() { 3 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 } public void add(int value) { } public int get(int position) { return -1; } Runner.java public void set(int position, int value) { } public int size() { /home/MyArrayList.java Spaces: 4 (Auto) Console Terminal > [] * All changes saved Run Mark 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 + 36 27 } public int size() { } MyArrayList.java } public void remove(int position) { X } public int[] toArray() { return new int[] {}; return Integer.MIN_VALUE; 2 Runner.java public void replace(int oldValue, int newValue) { public boolean contains (int value) { return false; /home/MyArrayList.java 25:6 Spaces: 4 (Auto) Console Terminal >_ [] * All changes saved Run Mark + 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 } } } MyArrayList.java public void replace(int oldValue, int newValue) { ...LJ } public boolean contains (int value) { return false; return new int[] {}; Runner.java public boolean isEmpty() { return false; } public void clear() { 44 45 46 } /home/MyArrayList.java 25:6 Spaces: 4 (Auto) Console Terminal >_ [] All changes saved Run Mark + MyArrayList.java 1 public class Runner { 2 GAWN 3 4 5} public static void main(String[] args) { //Again, this is just to test things, not part of the assessment } Runner.java /home/Runner.java Spaces: 4 (Auto) Console Terminal > [] * All changes saved Run Mark

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_2

Step: 3

blur-text-image_3

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

Income Tax Fundamentals 2013

Authors: Gerald E. Whittenburg, Martha Altus Buller, Steven L Gill

31st Edition

1111972516, 978-1285586618, 1285586611, 978-1285613109, 978-1111972516

More Books

Students also viewed these Programming questions