Skip to content

Instantly share code, notes, and snippets.

@andersonfraga
Created September 2, 2014 13:43
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save andersonfraga/c9b04a989a987917e21d to your computer and use it in GitHub Desktop.
Save andersonfraga/c9b04a989a987917e21d to your computer and use it in GitHub Desktop.
BigDecimal?
class Conta
{
private BigDecimal saldo;
public Teste()
{
saldo = new BigDecimal(0.0);
}
public void depositar(BigDecimal val)
{
if (val.compareTo(BigDecimal.ZERO) > 0) {
saldo = saldo.add(val);
}
}
public void sacar(BigDecimal val)
{
if (val.compareTo(BigDecimal.ZERO) <= 0) {
return;
}
if (saldo.substract(val).compareTo(BigDecimal.ZERO) <= 0) {
return;
}
saldo = saldo.substract(val);
}
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment