Question
// make a class that has Array methods that are equivalent to the // methods that are currently available for ArrayLists. // // This is
// make a class that has Array methods that are equivalent to the // methods that are currently available for ArrayLists. // // This is a template provided for you. // Write the code that will make these methods work on an Array. // // Make these methods work with string, only. // These methods must be "public static" methods. //--------------------------------------------------------------------- import java.util.Arrays; public class IST242_ArrayMethods { //--------------------------------------------------------------------- // This method will add a string to the array, if possible. // Parameters: // The string array that is to be worked on. // The string that is to be added to the end of the array. // Returns values: // -1, if add() has no room to add the item into the array. // -2, if the string passed in is a null string. // 0-n, index number //--------------------------------------------------------------------- public static int add (String[] names, String newValue) { int retVal = -1; System.out.println ("add> array = " + Arrays.toString(names)); return retVal; } //--------------------------------------------------------------------- // This method will remove an item from the list, based on an index // nuber into the array. All other itemds, after the removed item, will be moved up. // // Parameters: // The string array that is to be worked on. // The index value of the item to be removed. // // Returns values: // false, if removeIdx is not a valid index into the array. // true, if the removed worked. //--------------------------------------------------------------------- public static boolean remove (String[] names, int removeIdxIdx) { boolean removedWorked = false; System.out.println ("remove> array = " + Arrays.toString(names)); return removedWorked; }
//--------------------------------------------------------------------- // Given a serach string, find the index of the string in the array // Parameters: // - The string array holding the data. // - The string looking for. // //-- Returns: -1 if indexOf() did not work. // 0-n, index number. //--------------------------------------------------------------------- public static int indexOf (String[] names, int searchVal) { int foundIdx = -1; //-- This is a debug print, to help see whats happening // System.out.println ("indexOf> array = " + Arrays.toString(names)); return foundIdx; } } // end of class
Attached is a start to the methods you need to create.. You will also need to make a IST242_ArrayMethods_Main class to test these methods.
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