Created
October 2, 2020 21:20
-
-
Save lucastizzo/2f1f9a60b750b11a8f78c72cb6859e9b to your computer and use it in GitHub Desktop.
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
package horario; | |
public class Horario { | |
private int hora; | |
private int minutos; | |
private int segundo; | |
public Horario(int hora) { | |
this.hora = hora; | |
this.minutos = 0; | |
this.hora = 0; | |
} | |
public void setHora(int hora) { | |
this.hora = hora; | |
} | |
public void setMinutos(int minutos) { | |
this.minutos = minutos; | |
} | |
public void setSegundo(int segundo) { | |
this.segundo = segundo; | |
} | |
public void setHorario(int horas, int minutos, int segundo){ | |
this.hora = horas; | |
this.segundo = segundo; | |
this.segundo = segundo; | |
} | |
public Horario(int hora, int minutos, int segundo) { | |
this.hora = hora; | |
this.minutos = minutos; | |
this.segundo = segundo; | |
} | |
public static boolean validaHora(int hora){ | |
if(hora <= 24){ | |
return true; | |
} | |
else{ | |
return false; | |
} | |
} | |
public static boolean validaMinutos(int minutos){ | |
if(minutos<=60){ | |
return true; | |
} | |
else{ | |
return false; | |
} | |
} | |
public static boolean validaSegundo(int segundo){ | |
if(segundo<=60){ | |
return true; | |
} | |
else{ | |
return false; | |
} | |
} | |
public String mostraHora(){ | |
return "\nO horario é: " + getHora() + ":" + getMinutos() + ":" + getSegundo() + "\n"; | |
} | |
public static int calculaDiferenca(int hora1, int minuto1, int segundo1, int hora2, int minuto2, int segundo2){ | |
int diferenca = 0; | |
if(hora1 < hora2){ | |
diferenca = hora2 - hora1; | |
diferenca = diferenca * 60; | |
if(minuto1 < minuto2){ | |
diferenca = diferenca + (minuto2 - minuto1); | |
} | |
if(minuto2 <= minuto1){ | |
diferenca = diferenca - (minuto1 - minuto2); | |
} | |
if(segundo1 > segundo2){ | |
diferenca = diferenca + 1; | |
} | |
if(segundo2 > segundo1){ | |
diferenca = diferenca - 1; | |
} | |
} | |
if(hora1 > hora2){ | |
diferenca = hora1 - hora2; | |
diferenca = diferenca * 60; | |
if(minuto1 > minuto2){ | |
diferenca = diferenca + (minuto1 - minuto2); | |
} | |
if(minuto2 > minuto1){ | |
diferenca = diferenca - (minuto2 - minuto1); | |
} | |
if(segundo1 > segundo2){ | |
diferenca = diferenca - 1; | |
} | |
if(segundo1 < segundo2){ | |
diferenca = diferenca + 1; | |
} | |
} | |
System.out.println("\n esta é a diferença:" + diferenca); | |
return diferenca; | |
} | |
public int getHora() { | |
return hora; | |
} | |
public int getMinutos() { | |
return minutos; | |
} | |
public int getSegundo() { | |
return segundo; | |
} | |
} |
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
/* | |
* To change this license header, choose License Headers in Project Properties. | |
* To change this template file, choose Tools | Templates | |
* and open the template in the editor. | |
*/ | |
package horario; | |
import java.util.Scanner; | |
import java.util.ArrayList; | |
public class Programa { | |
public static void main(String[] args) { | |
Scanner texto = new Scanner(System.in); | |
int horas, minutos, segundos; | |
System.out.println("\n##POR FAVOR INFORME AS HORAS##\n"); | |
horas = Integer.parseInt(texto.nextLine()); | |
Horario a1 = new Horario(horas); | |
a1.setHora(horas); | |
a1.validaHora(a1.getHora()); | |
System.out.println("\n##POR FAVOR INFORME OS MINUTOS##\n"); | |
a1.setMinutos(Integer.parseInt(texto.nextLine())); | |
a1.validaMinutos(a1.getMinutos()); | |
System.out.println("\n##POR FAVOR INFORME OS SEGUNDOS##\n"); | |
a1.setSegundo(Integer.parseInt(texto.nextLine())); | |
a1.validaSegundo(a1.getSegundo()); | |
a1.setHorario(a1.getHora(),a1.getMinutos(), a1.getSegundo()); | |
System.out.println("\n##POR FAVOR INFORME O AS HORAS"); | |
horas = Integer.parseInt(texto.nextLine()); | |
Horario a2 = new Horario(horas); | |
a2.setHora(horas); | |
a2.validaHora(a2.getHora()); | |
System.out.println("\n##POR FAVOR INFORME OS MINUTOS##\n"); | |
a2.setMinutos(Integer.parseInt(texto.nextLine())); | |
a2.validaMinutos(a2.getMinutos()); | |
System.out.println("\n##POR FAVOR INFORME OS SEGUNDOS##\n"); | |
a2.setSegundo(Integer.parseInt(texto.nextLine())); | |
a2.validaSegundo(a2.getSegundo()); | |
a2.setHorario(a2.getHora(), a2.getMinutos(), a2.getSegundo()); | |
System.out.println("\nprimmeiro" + a1.mostraHora() + "\n" | |
+ "segundo é:" + a2.mostraHora() + "\n" + a1.calculaDiferenca(a1.getHora(),a1.getMinutos(), a1.getSegundo(), a2.getHora(), a2.getMinutos(), a2.getSegundo())); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment