Last active
March 24, 2017 22:26
-
-
Save jeffersontpadua/5353939294b49e0952c709b63e51708e to your computer and use it in GitHub Desktop.
Tratamento de erros em java
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 BungeeJumping { | |
public void executarSaltosDoDia(List<Pessoa> pessoas) { | |
for(Pessoa pessoa : pessoas) { | |
try { | |
if (podeSaltar(pessoa)) { | |
System.out.println(pessoa.getGritoDeEmocao()); | |
} | |
} catch (IllegalArgumentException e) { | |
System.out.println(pessoa.getNome() + " não pode saltar por ter mais de 60 anos."); | |
} | |
} | |
} | |
private boolean podeSaltar(Pessoa pessoa) { | |
if(pessoa.getIdade() >= 60){ | |
throw new IllegalArgumentException("Pessoas com mais de 65 anos não devem saltar."); | |
}else { | |
if(pessoa.getIdade() >= 18) { | |
return true; | |
}else { | |
System.out.println("Menores de 18 anos não podem saltar."); | |
return false; | |
} | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment