/*
 * ScanOperatore.java
 *
 * Created on 23 febbraio 2004, 21.50
 */
package Calc;
/**
 *
 * @author  stfn
 */
public class ScanOperatore extends ScanKey {
    
    /** Creates a new instance of ScanOperatore */
    public ScanOperatore() {
    }

    public String get(String msg, String msgerr){
        String oper;
        boolean test;
        ScanKey sk=new ScanKey();
        do{
            System.out.print(msg);
            test=true;
            oper=readLine();
            if(!test()){
                System.out.print(msgerr);
                String strtest=sk.readLine();
                if((strtest.startsWith("S"))||(strtest.startsWith("s")))
                    test=true;
                else
                    test=false;
            }
            else
                break;
        }while(test);
        if(!test())
            System.exit(0);
        return oper;
    }

    protected void AppendKey(char rdchar){
        //Questo metodo "specializza" rispetto alla classe base
        //la possibilità di selezionare secondo un preciso
        //criterio il tipo di caratteri che possono
        //essere appesi all'attributo result: vengono
        //aggiunti solo i caratteri operatore delle quattro
        //operazioni
        if(
            (rdchar=='*') ||
            (rdchar=='-') ||
            (rdchar=='/') ||
            (rdchar=='+')
        ){
            result = result + rdchar;
        }
    }
    protected boolean test(){
        //testa se l'attributo result contiene un valore
        //di operatore
        if(
            (result.startsWith("*")) ||
            (result.startsWith("-")) ||
            (result.startsWith("/")) ||
            (result.startsWith("+")) 
        ){
            return true;
        }
        else
            return false;
    }
}
