Advertisement
Guest User

Untitled

a guest
Mar 25th, 2019
91
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.76 KB | None | 0 0
  1. import java.util.Scanner;
  2.  
  3. public class UseElevator
  4. {  
  5.     Elevator elevador;
  6.     boolean sair;
  7.    
  8.     public UseElevator(Elevator elevador)
  9.     {
  10.         this.elevador = elevador;
  11.         sair = false;
  12.     }
  13.    
  14.     void run()
  15.     {
  16.         while(!sair){
  17.             askForInput();
  18.         }
  19.     }
  20.        
  21.     public void askForInput()
  22.     {
  23.         Scanner s = new Scanner(System.in);
  24.         char c;                
  25.         String option, optionList;
  26.                
  27.         System.out.println();
  28.         System.out.println("******** " + elevador + " ********");
  29.         System.out.println();
  30.        
  31.        
  32.         optionList = "(Q)uit" + (elevador.canGoUp()?", (U)p":"");
  33.         optionList += (elevador.canGoDown()?", (D)own":"");
  34.         optionList += (elevador.isInErrorState()?", (S)afety key" : ", (E)rror");
  35.         optionList += ": ";
  36.        
  37.         System.out.print(optionList);
  38.         option = s.next().toUpperCase();
  39.  
  40.         if(option.length() >= 1){
  41.             c = option.charAt(0);
  42.         }else{
  43.             c = ' ';
  44.         }
  45.  
  46.         switch(c){
  47.             case 'U':
  48.                 elevador.up();
  49.                 break;
  50.             case 'D':
  51.                 elevador.down();
  52.                 break;
  53.             case 'E':
  54.                 elevador.error();
  55.                 break;
  56.             case 'S':
  57.                 elevador.safetyKey();
  58.                 break;
  59.             case 'Q':
  60.                 sair = true;
  61.                 break;
  62.             default:
  63.                 break;
  64.         }                                    
  65.  
  66.     }
  67.  
  68.     public static void correPuta()
  69.     {
  70.         Elevator e = new Elevator();
  71.         UseElevator usaE = new UseElevator(e);
  72.         usaE.run();
  73.     }
  74.        
  75. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement