Advertisement
Guest User

Untitled

a guest
Jul 30th, 2016
55
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.96 KB | None | 0 0
  1. while (entrada.hasNextLine() && this.cont < 3) {
  2.  
  3. saida.println("Situação?");
  4. String sit = entrada.nextLine();
  5. System.out.println(sit);//recebe situação
  6.  
  7. if ("Ocupada".equals(sit)) {
  8. this.cont++;
  9. } else if(temporizador.getStop() == 0 && temporizador.getDifTime() == 0 ) { // faz o stop e exibe tempo
  10. temporizador.stop();
  11. temporizador.difTempo(this.nomeDispositivo);
  12. }else{
  13. this.cont = 0;
  14. }
  15. System.out.println(this.cont);
  16. }
  17. //inicia a contagem aqui e só exibe quando o temporizador.stop() for chamado ( dentro do while)
  18. if (temporizador.getStart() == 0){
  19. temporizador.start();
  20. System.out.println("Start no tempo!");
  21. }
  22.  
  23. public class temporizador {
  24.  
  25. private static long startValue = 0;
  26. private static long stopValue = 1;
  27. private static long difTime = 1;
  28.  
  29. public static void start() {
  30. startValue = System.currentTimeMillis();
  31. stopValue = 0;
  32. difTime = 0;
  33. }
  34.  
  35. public static void stop() {
  36. stopValue = System.currentTimeMillis();
  37. difTime = stopValue - startValue;
  38. }
  39.  
  40. public static void difTempo(String nome) throws SQLException {
  41. String format = String.format("%02d:%02d:%02d", difTime / 3600000, (difTime / 60000) % 60, (difTime / 1000) % 60);
  42. System.out.println(nome + " levou " + format);
  43.  
  44. startValue = 0;
  45. stopValue = 1;
  46. difTime = 1;
  47. }
  48.  
  49. public static long getStart(){
  50. return startValue;
  51. }
  52. public static long getStop(){
  53. return stopValue;
  54. }
  55. public static long getDifTime(){
  56. return difTime;
  57. }
  58. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement