Design and implement a class that uses an array to mimic the
Design and implement a class that uses an array to mimic the behavior of some of the methods in the Array list class. Include the following methods: Add(): Adds an element to the array. Clear(): Removes all elements from the array. Contains(): Determines if a specified item is in the array Index Of(): Returns the index of the first occurrence of the specified item Insert(): insert an element into the array at a specify index Remove(): Removes the first occurrence of the specify item Remove At(): Removes an clement at the specified index. Reverse(): Reverses the order of the elements in the array. Note, as you review the methods above, some may need arguments sent to them. For example Add() may need the object sent that is added to the data structure. Write a program to test your implementation. Maximum credit awarded for solutions that are readable, modularized, follow proper naming and spacing conventions. AFTER YOU COMPLETE YOUR WORK, close the solution, zip it and then upload the zipped solution to Blackboard under Course Documents > Exam 1. Print your source code and a sample run. Recall you print a sample run by capturing the output screen using the Alt + PrtScn keys to place the active screen in the clipboard. Once it\'s in the clipboard, paste the clipboard\'s contents into a Word document using Ctrl + V. If there is still an issue with printing your source from within Visual Studio, you can also copy the program statements into the clipboard and paste that into Word.
Solution
package com.example.shreya.mychegg; import android.support.v7.app.AppCompatActivity; import android.os.Bundle; import java.util.*; public class MainActivity extends AppCompatActivity { @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); } public static void main(String[] args) { // create array list object ArrayList arrayList = new ArrayList(); // populate the list arrayList.add(\"a\"); arrayList.add(\"b\"); arrayList.add(\"e\"); arrayList.add(\"d\"); arrayList.add(\"e\"); arrayList.add(\"f\"); arrayList.add(\"g\"); arrayList.add(\"h\"); // print all available elements for (Object num : arrayList) { System.out.println(\"Element = \" + num); } // check if the specified item exists in the array boolean eIsFound = arrayList.contains(\"g\"); if (eIsFound == true) { System.out.println(\"Element \\\"g\\\" is in the list\"); } else { System.out.println(\"Element \\\"g\\\" does not exist in the list\"); } // to get an index of specified element int index = arrayList.indexOf(\"e\"); if (index == -1) { System.out.println(\"Element doest not exist\"); } else { System.out.println(\"Element is at index\" + index); } //insert element into array at specified position arrayList.add(2,\"l\"); // print all available elements for (Object num : arrayList) { System.out.println(\"Element = \" + num); } // remove the first occurence of e arrayList.remove(\"e\"); // print all available elements for (Object num : arrayList) { System.out.println(\"Element = \" + num); } // remove element at thirs position arrayList.remove(2); // print all available elements for (Object num : arrayList) { System.out.println(\"Element = \" + num); } // reverse the list Collections.reverse(arrayList); // print all available elements for (Object num : arrayList) { System.out.println(\"Element = \" + num); } // remove all the elements of the array arrayList.clear(); // print all available elements for (Object num : arrayList) { System.out.println(\"Element = \" + num); } } }