Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- while (entrada.hasNextLine() && this.cont < 3) {
- saida.println("Situação?");
- String sit = entrada.nextLine();
- System.out.println(sit);//recebe situação
- if ("Ocupada".equals(sit)) {
- this.cont++;
- } else if(temporizador.getStop() == 0 && temporizador.getDifTime() == 0 ) { // faz o stop e exibe tempo
- temporizador.stop();
- temporizador.difTempo(this.nomeDispositivo);
- }else{
- this.cont = 0;
- }
- System.out.println(this.cont);
- }
- //inicia a contagem aqui e só exibe quando o temporizador.stop() for chamado ( dentro do while)
- if (temporizador.getStart() == 0){
- temporizador.start();
- System.out.println("Start no tempo!");
- }
- public class temporizador {
- private static long startValue = 0;
- private static long stopValue = 1;
- private static long difTime = 1;
- public static void start() {
- startValue = System.currentTimeMillis();
- stopValue = 0;
- difTime = 0;
- }
- public static void stop() {
- stopValue = System.currentTimeMillis();
- difTime = stopValue - startValue;
- }
- public static void difTempo(String nome) throws SQLException {
- String format = String.format("%02d:%02d:%02d", difTime / 3600000, (difTime / 60000) % 60, (difTime / 1000) % 60);
- System.out.println(nome + " levou " + format);
- startValue = 0;
- stopValue = 1;
- difTime = 1;
- }
- public static long getStart(){
- return startValue;
- }
- public static long getStop(){
- return stopValue;
- }
- public static long getDifTime(){
- return difTime;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement