[Solved]Java Provide Main Method Thatinvokes Push Pop Tostring Methods Generic Stack Class Adding Q37157338
java
provide “main” method thatinvokes the “push”, “pop” and”toString” methods of your generic stack class.
Before adding a new object in the “push”method:
Check to see if the array has an element to hold it.
If it doesn’t, declare the new array with twice the number ofelements as the original one.
Loop through the original and copy each element to the newarray.
Assign the original array to the new one.
———————————————————————–
this is the code, need to make a driver:import java.util.Arrays;public class Stack { int CAPACITY=100; private int capacity = CAPACITY; private int size; private int[] array = new int[capacity]; Stack() { } public int getSize() { return size; } public int peek() { if (size == 0) return null; else return array[size – 1]; } public void push(int x) { int VALUE_TO_MULTIPLY=2; array[size++] = x; if (size == capacity) { int[] temp = new int[capacity *= VALUE_TO_MULTIPLY]; System.arraycopy(array, 0, temp, 0, array.length); array = temp; } } public int pop() { if (size == 0) return null; else return array[–size]; } public boolean isEmpty() { return size == 0; } public String toString() { return “Stack: ” + Arrays.toString(array); }}
![]()
Expert Answer
Answer to java provide “main” method thatinvokes the “push”, “pop” and “toString” methods of your generic stack class. Before addi… . . .
OR

