(Solved) : Source Code Java Package Prog02 Class Implements Methods Java Arraylist Class Data Stored Q42725600 . . .

This is the source code in JAVA

package prog02;/** * This class implements some of the methods of the Java ArrayList class. * * The data stored in the List can only be String objects */public class LucasStringArrayList { /** The default initial capacity */ private static final int INITIAL_CAPACITY = 6; /** The underlying data array */ private String[] theData; /** The current size */ private int size = 0; /** The current capacity */ private int capacity = 0; /** * Construct an empty List with the default * initial capacity */ public LucasStringArrayList() { capacity = INITIAL_CAPACITY; theData = new String[capacity]; } /** * Get a value in the array based on its index. * @param index – The index of the item desired * @return The contents of the array at that index * @throws ArrayIndexOutOfBoundsException – if the index * is not a legal value */ public String get(int index) { return “foo”; } /** * Set the value in the array based on its index. * @param index – The index of the item desired * @param newValue – The new value to store at this position * @return – The old value at this position * @throws – ArrayIndexOutOfBoundsException – if the index * is not a legal value */ public String set( int index, String newValue ) { return “foo”; } /** * Remove an entry based on its index * @param index – The index of the entry to be removed * @return The value removed * @throws ArrayIndexOutOfBoundsException – if the index * is not a legal value */ public String remove(int index) { return “foo”; } /** * Add an entry to the data at the end of the list * Dynamically increase the size of the array if needed * @param theValue – The value to be inserted * @throws ArrayIndexOutOfBoundsException if index is * less than zero or greater than size * @return true iff the Collection has changed */ public boolean add( String theValue ) { return false; } /** * Add an entry to the data inserting it at the specified index. * Dynamically increase the size of the array if needed * @param index – Location where the new item should be placed in the List * @param theValue – The value to be inserted * @throws ArrayIndexOutOfBoundsException if index is * not a legal value * @return true iff the Collection has changed */ public boolean add(int index, String theValue) { return false; } /** * Allocate a new, larger array and move all the data into this * larger array */ private void reallocate() { } /** * @return The current size of the array */ public int size() { return -99; } /** * @return true iff the List contains no items */ public boolean isEmpty() { return false; } /** * Return a String that represents all of the items in the List */ public String toString() { String result = “[“; for ( int i=0; i < size; i++ ) { result += theData[i] + “, “; } if ( ! result.equals(“[“) ) // remove trailing comma result = result.substring( 0, result.length() – 2 ); result += “]”; return result; }}

For this assignment, you will implement a simplified version of the ArrayList class. An ArrayList is one kind of Collection.You may create private helper methods in this class, if you choose to do so. An ArrayList is dynamically sized. In other wo

For this assignment, you will implement a simplified version of the ArrayList class. An ArrayList is one kind of Collection. HashSet andPriority Queue are two other kinds of Collections. Your ArrayList will store String objects. You are given the shell of the LucasStringArrayList class, and you must complete the code for the following methods of the class. The instance fields of the LucasStringArrayList class are already defined for you. One of these fields is the actual array that will store the String values. The functionality of each method is described in the header-comment of that method. This functionality matches what is provided by the ArrayList class in the Java Collections Framework. You should be sure that your code returns the correct value after it modifies the ArrayList. An ArrayList stores data in an array, keeping the Strings in consecutive locations in the array. So when you remove(4), i.e., you remove the item in position 4 in the array, your code will need to “slide over to the left by one place” all the Strings in the array that are to the right of position 4. public String get(int index) public String set( int index, String new Value ) public int size public boolean isEmpty public boolean add(String theValue) public boolean add(int index, String theValue) public String remove(int index) You may create private “helper” methods in this class, if you choose to do so. An ArrayList is dynamically sized. In other words, there is no set upper bound on the number of Strings that can be stored in the ArrayList. This is unlike an array, which has a fixed, static number of entries. The provided code for a LucasStringArrayList contains a field that is the actual array of Strings in the ArrayList. If the user ever tries to add a new String, and the array does not have enough room, then your code should dynamically create a new, larger array, and copy all the Strings from the old array into the new array. You should double the size of the array, to prevent this re-allocation operation from occurring too frequently. Your LucasStringArrayList should check for error conditions and throw an appropriate exception when an error is detected. For example, in the removed index) method, it is an error for the index to be <0. Your code would look like: public String remove (int index ) { if (index <0) throw new ArrayIndexOutOfBoundsException(); // more code here ………. Basically your code will “punt” and “give up” whenever an error condition occurs, and your code will “throw” the problem back to the Tester class to handle. Show transcribed image text For this assignment, you will implement a simplified version of the ArrayList class. An ArrayList is one kind of Collection. HashSet andPriority Queue are two other kinds of Collections. Your ArrayList will store String objects. You are given the shell of the LucasStringArrayList class, and you must complete the code for the following methods of the class. The instance fields of the LucasStringArrayList class are already defined for you. One of these fields is the actual array that will store the String values. The functionality of each method is described in the header-comment of that method. This functionality matches what is provided by the ArrayList class in the Java Collections Framework. You should be sure that your code returns the correct value after it modifies the ArrayList. An ArrayList stores data in an array, keeping the Strings in consecutive locations in the array. So when you remove(4), i.e., you remove the item in position 4 in the array, your code will need to “slide over to the left by one place” all the Strings in the array that are to the right of position 4. public String get(int index) public String set( int index, String new Value ) public int size public boolean isEmpty public boolean add(String theValue) public boolean add(int index, String theValue) public String remove(int index)
You may create private “helper” methods in this class, if you choose to do so. An ArrayList is dynamically sized. In other words, there is no set upper bound on the number of Strings that can be stored in the ArrayList. This is unlike an array, which has a fixed, static number of entries. The provided code for a LucasStringArrayList contains a field that is the actual array of Strings in the ArrayList. If the user ever tries to add a new String, and the array does not have enough room, then your code should dynamically create a new, larger array, and copy all the Strings from the old array into the new array. You should double the size of the array, to prevent this re-allocation operation from occurring too frequently. Your LucasStringArrayList should check for error conditions and throw an appropriate exception when an error is detected. For example, in the removed index) method, it is an error for the index to be

Expert Answer


Answer to This is the source code in JAVA package prog02; /** * This class implements some of the methods of the Java ArrayList c…

Leave a Comment

About

We are the best freelance writing portal. Looking for online writing, editing or proofreading jobs? We have plenty of writing assignments to handle.

Quick Links

Browse Solutions

Place Order

About Us