Advertisement
Guest User

Untitled

a guest
Nov 25th, 2015
66
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.00 KB | None | 0 0
  1. package demoeccezioni;
  2.  
  3. public class GestioneOrari {
  4.  
  5. /* Verifica la validità di un orario espresso nel formato h:m:s (ore, minuti e secondi) */
  6. private static boolean orarioValido(int h, int m, int s) {
  7. if (h>=0 && h<24 && m>=0 && m<60 && s>=0 && s<60) return true;
  8. else
  9. return false;
  10. }
  11. /* Calcola la differenza in secondi fra 2 orari espressi nel formato h:m:s (ore, minuti e secondi)
  12. */
  13. public static int differenzaOrari(int h1, int m1, int s1, int h2, int m2, int s2) throws OrarioNonValido {
  14. if (!orarioValido(h1, m1, s1)){
  15. throw new OrarioNonValido(h1,m1,s1);
  16. }
  17. if (!orarioValido(h2,m2,s2)){
  18. throw new OrarioNonValido(h2,m2,s2);
  19. }
  20. else {
  21. int sec1, sec2;
  22. sec1 = h1*3600 + m1*60 + s1; sec2 = h2*3600 + m2*60 + s2;
  23. return (sec2-sec1);
  24. }
  25. }
  26.  
  27. public static boolean confrontaOrari(int h1, int m1, int s1, int h2, int m2, int s2) throws OrarioNonValido {
  28. if (differenzaOrari(h1, m1, s1, h2, m2, s2) == 0)
  29. return true;
  30. else
  31. return false;
  32. }
  33.  
  34. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement