/* StringsInReverse.java         Authors: Koffman & Wolz
 * Reads and stores a collection of strings on a stack
 * and displays them in reverse order.
 * Uses StackList and JOptionPane.
 */
import javax.swing.*;
import java.util.*;

public class StringsInReverse  {

	// Methods
	// postcondition: Reads a group of strings & pushes
  //   them onto its stack argument
	public static void readStringStack(StackList s) {
		String next =
       JOptionPane.showInputDialog("Enter a string or ***:");
		while (!next.equals("***")) {
			s.push(next);
			next = JOptionPane.showInputDialog("Enter a string or ***:");
	  }
  }

	// postcondition: Pops strings off its stack
  //   argument and displays them.
	public static void showStringStack(StackList s) {
		// Pop each string and display it.
		while (!s.isEmpty()) {
			Object next = s.pop();
			System.out.println(next);
		}
  }

  public static void main(String[] args) {

    StackList stackOfStrings = new StackList();

    readStringStack(stackOfStrings);

    showStringStack(stackOfStrings);
  }
}



