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
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 ArrayStackStep 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