Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.util.Scanner;
- public class UseElevator
- {
- Elevator elevador;
- boolean sair;
- public UseElevator(Elevator elevador)
- {
- this.elevador = elevador;
- sair = false;
- }
- void run()
- {
- while(!sair){
- askForInput();
- }
- }
- public void askForInput()
- {
- Scanner s = new Scanner(System.in);
- char c;
- String option, optionList;
- System.out.println();
- System.out.println("******** " + elevador + " ********");
- System.out.println();
- optionList = "(Q)uit" + (elevador.canGoUp()?", (U)p":"");
- optionList += (elevador.canGoDown()?", (D)own":"");
- optionList += (elevador.isInErrorState()?", (S)afety key" : ", (E)rror");
- optionList += ": ";
- System.out.print(optionList);
- option = s.next().toUpperCase();
- if(option.length() >= 1){
- c = option.charAt(0);
- }else{
- c = ' ';
- }
- switch(c){
- case 'U':
- elevador.up();
- break;
- case 'D':
- elevador.down();
- break;
- case 'E':
- elevador.error();
- break;
- case 'S':
- elevador.safetyKey();
- break;
- case 'Q':
- sair = true;
- break;
- default:
- break;
- }
- }
- public static void correPuta()
- {
- Elevator e = new Elevator();
- UseElevator usaE = new UseElevator(e);
- usaE.run();
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement