Simple stack implementation
please help
(looks like a lot but actually isnt, everything is already set up for you below to make it even easier)
help in any part you can, please be clear, thank you
Given an interface for Stack
- Without using the java collections interface (ie do not import java.util.List,
LinkedList, Stack, Queue...)
- Create an implementation of Stack interface provided
- For the implementation create a tester to verify the implementation of that
data structure performs as expected
Get on the bus – Stack (lifo)
- Implement the provided Stack interface ( fill out the implementation shell)
- Put your implementation through its paces by exercising each of the methods in
a test harness
- Add to your ‘BusClient’ the following functionality using your Stack
-
o Create (push) 6 riders by name
§ Iterate over the stack, print all riders
o Peek at the stack / print the result
o Remove (pop) the top of the stack
§ Iterate over the stack, print all riders
o Peek at the stack / print the result
o Add two more riders to the stack
o Peek at the stack & print the result
o Remove all riders from the stack
o Verify the stack is now empty ( print that result )
4 CLASSES TO BEGIN WITH BELOW (edit these classes to fulfill the easy requirements above)
import linkedList.LinkedList;
import linkedList.LinkedListImpl;
import queue.Queue;
import queue.QueueImpl;
import stack.Stack;
import stack.StackImpl;
public class BusClient {
public static void main(String[] args) {
// create implementation, then
System.out.println("-----S T A C K T E S T------");
//StackRunTestMethod...
}
}
----------
package stack;
public interface Stack {
public void push(String s);
public String pop();
public Boolean isEmpty();
public Boolean isFull();
public int size();
public String peek();
public void setCapacity(int size);
public void display();
}
----------
package stack;
public class StackImpl implements Stack {
String[] arr = new String[5];
int index = 0;
@Override
public void push(String s) {
if (isFull()) {
System.out.println("Sorry, no room left..");
return;
}
//uh
//move each element in array to pos + 1
for (int i = index; i > 0; i--) {
arr[i] = arr[i - 1];
}
//after all moved, add new element to 0th
arr[0] =s;
index++;
}
@Override
public String pop() {
// TODO Auto-generated method stub
return null;
}
@Override
public Boolean isEmpty() {
// TODO Auto-generated method stub
return null;
}
@Override
public Boolean isFull() {
// TODO Auto-generated method stub
return false;
}
@Override
public int size() {
// TODO Auto-generated method stub
return 0;
}
@Override
public String peek() {
// TODO Auto-generated method stub
return null;
}
@Override
public void setCapacity(int size) {
// TODO Auto-generated method stub
}
@Override
public void display() {
// TODO Auto-generated method stub
}
}
----------
package stack;
public class StackTester {
public static void main(String[] args) {
Stack s = new StackImpl();
runTests(s);
}
public static void runTests(Stack stack) {
stack.push("silly");
stack.push("sally");
stack.push("sells");
stack.push("used cars");
//check this is used cars
stack.pop();
//
}
}