Created
March 25, 2019 20:26
-
-
Save danicunhac/c13214d7225dc2448b40dee5f5086d18 to your computer and use it in GitHub Desktop.
Relogio
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class Aplicacao { | |
public static void main(String[] args) { | |
Relogio r1 = new Relogio(); | |
r1.acertarRelogio(3, 25, 50); | |
System.out.println("Posicao da hora: " + r1.ponteiroHora.posicao); | |
System.out.println("Posicao do minuto: " + r1.ponteiroMinuto.posicao); | |
System.out.println("Posicao do segundo: " + r1.ponteiroSegundo.posicao); | |
int hora = r1.lerHora(); | |
int minuto = r1.lerMinuto(); | |
int segundo = r1.lerSegundo(); | |
System.out.println("Hora: " + hora); | |
System.out.println("Minuto: " + minuto); | |
System.out.println("Segundo: " + segundo); | |
Relogio r2 = new Relogio(); | |
r2.acertarRelogio(23, 0, 0); | |
System.out.println("Hora do segundo relogio: " + r2.lerHora()); | |
} | |
} | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class Ponteiro { | |
int posicao; | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class Relogio { | |
Ponteiro ponteiroHora = new Ponteiro(); | |
Ponteiro ponteiroMinuto = new Ponteiro(); | |
Ponteiro ponteiroSegundo = new Ponteiro(); | |
void acertarRelogio(int hora, int minuto, int segundo) { | |
hora = hora % 12; | |
ponteiroHora.posicao = hora; | |
ponteiroMinuto.posicao = minuto/5; | |
ponteiroSegundo.posicao = segundo/5; | |
} | |
int lerHora() { | |
return ponteiroHora.posicao; | |
} | |
int lerMinuto() { | |
return ponteiroMinuto.posicao*5; | |
} | |
int lerSegundo() { | |
return ponteiroSegundo.posicao*5; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment