import java.util.Scanner; public class Reloj { private int horas, minutos, segundos; // ------------ Constructores public Reloj() { horas = 12; minutos = 0; segundos = 0; } public Reloj(int h, int m, int s) { horas = h; minutos = m; segundos = s; } public Reloj(int segundos2) { horas = segundos2 / 3600; minutos = (segundos2 - (3600 * horas)) / 60; segundos = segundos2 - ((horas * 3600) + (minutos * 60)); System.out.println("[" + horas + ":" + minutos + ":" + segundos + "]"); } // ---------- Metodos ----------------- public void setReloj(int segundos2) { horas = segundos2 / 3600; minutos = (segundos2 - (3600 * horas)) / 60; segundos = segundos2 - ((horas * 3600) + (minutos * 60)); toString1(); } public int getHoras() { //retornar las horas return horas; } public int getMinutos() { //Retornar minutos return minutos; } public int getSegundos() { //retornar segundos return segundos; } public void setHoras(int h) { //retornar las horas horas = h; } public void setMinutos(int m) { //Retornar minutos minutos = m; } public void setSegundos(int s) { //retornar segundos segundos = s; } public void tick() { int[] array1 = convertToSeconds(horas, minutos); int relojAux = array1[0] + array1[1] + segundos + 1; setReloj(relojAux); } public void addReloj(Reloj relojX) { int[] array1 = convertToSeconds(relojX.horas, relojX.minutos); int[] array2 = convertToSeconds(horas, minutos); int newReloj = array1[0] + array2[0] + array1[1] + array2[1] + segundos + relojX.segundos; setReloj(newReloj); } public void toString1() { System.out.println("[" + horas + ":" + minutos + ":" + segundos + "]"); } public void restaReloj(Reloj relojX) { //toma un parametro tipo Reloj y returna la diferencia de tiempo representada en el objeto de reloj //actual y el representado en el parametro. int[] array1 = convertToSeconds(relojX.horas, relojX.minutos); int[] array2 = convertToSeconds(horas, minutos); if ( relojX.horas < horas) { int newReloj = (array1[0] - array2[0] - array1[1] - array2[1] - segundos - relojX.segundos) * (-1); setReloj(newReloj); } else { int newReloj = array1[0] - array2[0] - array1[1] - array2[1] - segundos - relojX.segundos; setReloj(newReloj); } } public int[] convertToSeconds(int h, int m) { int[] array1 = new int[2]; array1[0] = h * 3600; array1[1] = m * 60; return array1; } public static void main(String[] args) { System.out.println("Ingrese un numero: "); Scanner in = new Scanner(System.in); int x = in.nextInt(); Reloj reloj1 = new Reloj(x); Reloj reloj2 = new Reloj(1,0,0); reloj2.restaReloj(reloj1); for (int i = 0; i < 10; i++) { reloj1.tick(); } } }