Question: *******************************ArrayStack********************** public class ArrayStack implements StackADT { private final int MAX = 10; private int top; private T[] stack; ArrayStack() { int top = 0;

 *******************************ArrayStack********************** public class ArrayStack implements StackADT { private final int MAX

*******************************ArrayStack**********************

public class ArrayStack implements StackADT {

private final int MAX = 10; private int top; private T[] stack;

ArrayStack() { int top = 0; stack = (T[]) (new Object[MAX]);

}

ArrayStack(int intialCapacity) { int top = 0; stack = (T[]) (new Object[intialCapacity]);

} // @Override

@Override public void push(T element) { stack[top] = element; top++;

}

@Override public String toString() { String result = ""; for (int i = 0; i

public T pop() { double store = 0; top--; return stack[top];

}

@Override public T peek() { return stack[top - 1]; }

@Override public int size() { return top; }

@Override public boolean isEmpty() { return top == 0; } }

Part 2: Using a Stack to Solve Problems 1. Design and Implement a Java program that reads a sentence from the user and prints the sentence with the characters of each word backwards. Use the ArrayStack in part 1 to reverse the characters of each word. A sample output is shown in Figure 1 Note that different sentence will be used for grading. It is required that the ArrayStack class should be utilized in solving this problem. Enter a sentence Hello nice to meet you in CS102 Reversing each word: o1leH ecin ot teem uoy ni 201SC BUILD SUCCESSFUL (total time: 14 seconds) Figure 1:reverse characters

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!