Java Eclipse You are to write a program name Array List that
Java Eclipse
You are to write a program name Array List that creates Array list data structure similar to the Ana Last data Structure float exist library. The class must be written to accept any type of Objects. The follower must be eject with a default size of 10 public Array default that actor that parameter of type into and sets the this p public n) Array List aloud that and to replace public id add(ob. 4. A method that allows you to place a value at a given location paler avid add(in index, ob. et) ethos that aloe from a give locate public object getting index yon to retry ethos that auto you to return toe of elements that entry the the Aura public into Amount would to -eye due Arm public b ethos that if a portico object the ArrayLi public bool Object ob. ethos that will return the of fur object starting form location 0 public into find (Object 0. A nettled hat will bloc void Non: write a driver program (the class with the public static void Sting] rags method) name test array java to test the ArrayList data structure you just created. Fill the set with Card Objects (i.e. you are creating a Deck of Cards 52) aid paint these to the screen. Now. white d take this Aural of Cards display the snaffled Array List icky Cards Al set all hoods. F lose value. print out their hammed vane to the careen am for those that are not resuming a value print a message that indicate if aura Fully completed it rail Remember loud be based upon the tubal unwater the Aryl at that poutSolution
import java.util.Arrays;
/**
* @author Srinivas Palli
*
*/
public class ArrayList {
private Object[] myStore;
private int actSize = 0;
public ArrayList() {
myStore = new Object[10];
}
public ArrayList(int size) {
myStore = new Object[size];
}
public void add(Object obj) {
if (myStore.length - actSize <= 5) {
increaseListSize();
}
System.out.println(\"acts \" + actSize + \" obj=\" + obj);
myStore[actSize++] = obj;
}
public void add(int index, Object obj) {
if (myStore.length - actSize <= 5) {
increaseListSize();
}
myStore[actSize++] = obj;
}
public Object get(int index) {
if (index < actSize) {
return myStore[index];
} else {
throw new ArrayIndexOutOfBoundsException();
}
}
public Object remove(int index) {
if (index < actSize) {
Object obj = myStore[index];
myStore[index] = null;
int tmp = index;
while (tmp < actSize) {
myStore[tmp] = myStore[tmp + 1];
myStore[tmp + 1] = null;
tmp++;
}
actSize--;
return obj;
} else {
throw new ArrayIndexOutOfBoundsException();
}
}
/**
* @return
*/
public int size() {
return actSize;
}
/**
* @return
*/
public boolean isEmpty() {
if (actSize == 0)
return true;
else
return false;
}
/**
* @param ob
* @return
*/
public boolean isIn(Object ob) {
for (int i = 0; i < actSize; i++) {
if (get(i).equals(ob))
return true;
}
return false;
}
/**
* @param n
* @return
*/
public int find(Object n) {
for (int i = 0; i < actSize; i++) {
if (get(i).equals(n))
return i;
}
return -1;
}
private void increaseListSize() {
myStore = Arrays.copyOf(myStore, myStore.length * 2);
System.out.println(\"\ New length: \" + myStore.length);
}
}
package prob3;
/**
* @author Srinivas Palli
*
*/
public class testarray {
/**
* @param a
*/
public static void main(String a[]) {
ArrayList mal = new ArrayList(52);
for (int i = 0; i < 52; i++) {
mal.add(i);
}
System.out.println(mal.size());
for (int i = 0; i < 52; i++) {
System.out.print(mal.get(i) + \" \");
}
mal.add(new Integer(29));
System.out.println(\"Element at Index 5:\" + mal.get(5));
System.out.println(\"List size: \" + mal.size());
System.out.println(\"Removing element at index 2: \" + mal.remove(2));
for (int i = 0; i < mal.size(); i++) {
System.out.print(mal.get(i) + \" \");
}
}
}
OUTPUT:
acts 0 obj=0
acts 1 obj=1
acts 2 obj=2
acts 3 obj=3
acts 4 obj=4
acts 5 obj=5
acts 6 obj=6
acts 7 obj=7
acts 8 obj=8
acts 9 obj=9
acts 10 obj=10
acts 11 obj=11
acts 12 obj=12
acts 13 obj=13
acts 14 obj=14
acts 15 obj=15
acts 16 obj=16
acts 17 obj=17
acts 18 obj=18
acts 19 obj=19
acts 20 obj=20
acts 21 obj=21
acts 22 obj=22
acts 23 obj=23
acts 24 obj=24
acts 25 obj=25
acts 26 obj=26
acts 27 obj=27
acts 28 obj=28
acts 29 obj=29
acts 30 obj=30
acts 31 obj=31
acts 32 obj=32
acts 33 obj=33
acts 34 obj=34
acts 35 obj=35
acts 36 obj=36
acts 37 obj=37
acts 38 obj=38
acts 39 obj=39
acts 40 obj=40
acts 41 obj=41
acts 42 obj=42
acts 43 obj=43
acts 44 obj=44
acts 45 obj=45
acts 46 obj=46
New length: 104
acts 47 obj=47
acts 48 obj=48
acts 49 obj=49
acts 50 obj=50
acts 51 obj=51
52
0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 acts 52 obj=29
Element at Index 5:5
List size: 53
Removing element at index 2: 2
0 1 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 29



