Skip to content

Instantly share code, notes, and snippets.

@joffilyfe
Created November 27, 2015 00:26
Show Gist options
  • Save joffilyfe/2aedd169fa4a1af9ca4c to your computer and use it in GitHub Desktop.
Save joffilyfe/2aedd169fa4a1af9ca4c to your computer and use it in GitHub Desktop.
POO - Implementação da classe Conta.
public class Conta {
private String numero;
private String cliente;
private double saldo;
public Conta(String num, String cli) {
this.numero = num;
this.cliente = cli;
this.saldo = 0;
}
public void creditar(double valor) { this.saldo += valor; }
public boolean debitar(double valor) {
if (this.saldo < valor) {
return false;
}
this.saldo -= valor;
return true;
}
public double getSaldo() { return this.saldo; }
public String getOwner() { return this.cliente; }
public boolean transfer(Conta destino, double valor) {
if (this != destino) {
boolean response = this.debitar(valor);
if (response == true) {
destino.creditar(valor);
return true;
}
}
return false;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment