XP : ClasseEntradaFinal

XP » XP » WebHome » TrabalhosFinais » JogoDoMeio » TestesParaOJogoDoMeio » ClasseEntradaFinal

-- AndreGermanoRegert - 07 Jul 2005


/*
 * Created on 05/07/2005
 */
package Uteis;
/**
 * @author André Germano Regert
 *          Jader Wallauer
 */
public class Entrada {

   public String inString(){
      int aChar;
       String s = "";
       boolean finished = false;

       while(!finished){
          try   {
             aChar = System.in.read();
               if (aChar < 0 || (char)aChar == '\n')
                  finished = true;
               else if ((char)aChar != '\r')
            s = s + (char)aChar;   // Enter into string
           } catch(java.io.IOException e) {
            System.out.println("Input error");
             finished = true;
           }
       }
       return s;
   }

   public int inInt(){
      boolean finished = false;
      int retorno = 0;
      while(!finished){
         //inputFlush();
         //printPrompt(prompt);
         try {
            retorno = Integer.valueOf(inString().trim()).intValue();
            finished = true;
         } catch(NumberFormatException e) { 
            System.out.println("Invalid input. Not an integer");
         }
      }
      return retorno;
   }

   public boolean inBoolean() {
      boolean finished = false;
      boolean retorno = false;
      while(!finished){
         //inputFlush();
         //printPrompt(prompt);
         try {
            int tmp = Integer.valueOf(inString().trim()).intValue();
            if (tmp == 1){
               retorno = true;
            } else if (tmp == 0) {
               retorno = false;
            } else { 
               NumberFormatException nfe = new NumberFormatException();
               throw nfe;
            }
            finished = true;
         } catch(NumberFormatException e) { 
            System.out.println("Invalid input. Not a boolean");
         }
      }
      return retorno;
   } 

}

E D U G R A F - Laboratório de Software Educacional - UFSC - CTC - INE
Campus Universitário - Trindade, Florianópolis, SC, Brasil 88040-090
Fone: +55 48 331 9735 / Fax: +55 48 331-9770