Answered step by step
Verified Expert Solution
Question
1 Approved Answer
Could somebody please help with the following question. Please. Thank you so much. Write a java program name MyArrayList.java that create/build the ArrayList data Structure
Could somebody please help with the following question. Please. Thank you so much.
Write a java program name MyArrayList.java that create/build the ArrayList data Structure that exist in the java library. The class must be written to accept any type of Objects. The following must be implemented i.e. YOU must write the code (do not import them from the Java Library): 1. One default constructor that will create an MyArrayList object with a default size (capacity) of 10 public MyArrayList(); 2. Another constructor that accepts a parameter of type int and sets the size to this parameter public MyArrayList(int n); 3. A method that allows you to place a value at the end of the MyArrayList public void add(Object x); 4. A method that allows you to place a value at a given location public void add(int index, Object x); 5. A method that allows you to retrieve a value from a given location public Object get(int index); 6. A method that allows you the number of elements in the MyArrayList public int size(); 7. A method would test to see if the MyArrayList is empty public boolean isEmpty(); 8. A method that see if a particular object exists in the ArrayList public boolean isln(Object ob); public 9. A method that will return the location of first occurrence of an Object starting from location int find (Object n); 10. A method that will remove the first occurrence of an Object starting from location 0 public void remove (Object n); Now, write a driver program (the class with the public static void main(String[] args) method) name Testarray.java to test the MyArrayList data structure you just created. That is, you must test all ten (including the default constructor) of the above methods. -For those that are returning a value, print out the returned value to the screen and -For those that are not returning a value, print a message that indicate if it successfully completed its task. After you test each method, please print the list. To test the MyArrayList, you must randomly generate 15 integer numbers ranging from 1 to 25 and add to the two MyArrayList you created (One using the no-parameter constructor and the other using the one-parameter constructor). Of course, to use the one-parameter constructor, you must prompt the user for an initial size of the ArrayList. Remember! The size function should be based upon the actual number of elements you have in the MyArrayList at any given timeStep 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