Question: This is java Client . You'll now write a client program called FSclient.java. It should use (and test) your implementations of the two classes above.

This is java

Client. You'll now write a client program called FSclient.java. It should use (and test) your implementations of the two classes above. Your code should work like the Unit Test from the ResizingArrayStack from Lab2, so that it takes a sequence of tokens like:

 to be or not to - be - - that - - - is 

treating non-dash tokens as "push" requests, and dash characters as pop requests. It should run like:

 % java-alg4 FSclient 4 < tobe.txt 

The result of such a command should be (a) the stack is limited to size 4, so it should never contain more than 4 items, and (b) on each pop request, the popped term should be printed. You may use the main function from ResizingArrayStack as a guide:

public static void main(String[] args) { ResizingArrayStack stack = new ResizingArrayStack(); while (!StdIn.isEmpty()) { String item = StdIn.readString(); if (!item.equals("-")) stack.push(item); else if (!stack.isEmpty()) StdOut.print(stack.pop() + " "); } StdOut.println("(" + stack.size() + " left on stack)"); } 

Once you have implemented it, test with several input files, to ensure that it is working as expected. How does it deal with pop requests on an empty stack? You may find it useful to test the contents of the FS-stack after each action, using its iterator.

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!