import struktury.StosLiczb;
import java.io.*;

public class TestStosLiczb
{
    static PrintWriter wy = new PrintWriter(new OutputStreamWriter(System.out),true);
    static BufferedReader we = new BufferedReader(new InputStreamReader(System.in));

    public static void main (String[] arg) throws Exception
    {
        StosLiczb stos = new StosLiczb(10);
        while (true)
        {
            String kom;
            wy.print("Podaj komende (? - pomoc): "); wy.flush();
            kom = we.readLine();
            if (kom==null) return;
            kom = kom.trim();
            if (kom.equals("wy"))
            {
                wy.println("    - wyjscie z programu -");
                break;
            }
            if (kom.equals("?"))
            {
                wy.println("?     - pomoc");
                wy.println("druk  - wydrukowanie zawartosci stosu");
                wy.println("wstaw - wstawienie nowej wartosci na szczyt stosu");
                wy.println("usun  - usuniecie wartosci ze szczytu stosu");
                wy.println("spr   - sprawdzenie jaka wartosc jest na szczycie stosu");
                wy.println("rozm  - rozmiar stosu");
                wy.println("wy    - wyjscie z programu");
            }
            else if (kom.equals("druk"))
            {
                wy.println("    "+stos);
            }
            else if (kom.matches("wstaw[ \t]+[\\-]?\\d+"))
                try
                {
                    String[] tab = kom.split("[ \t]+");
                    int k = Integer.parseInt(tab[1]);
                    stos.wstaw(k);
                    wy.println("    wstawiono "+k);
                }
                catch (IllegalStateException ex) { wy.println("    stos przepelniony"); }
                catch (NumberFormatException ex) { wy.println("    bledna liczba"); }
            else if (kom.equals("usun"))
                try
                {
                    int k = stos.usun();
                    wy.println("    usunieto "+k);
                }
                catch (IllegalStateException ex) { wy.println("    stos pusty"); }
            else if (kom.equals("spr"))
                try
                {
                    int k = stos.sprawdz();
                    wy.println("    znaleziono "+k);
                }
                catch (IllegalStateException ex) { wy.println("    stos pusty"); }
            else if (kom.equals("rozm"))
            {
                int k = stos.ile();
                wy.println("    rozmiar stosu = "+k);
            }
            else wy.println("    - nieznane polecenie ("+kom+") -");
        }
    }
}
