Created
November 27, 2015 00:26
-
-
Save joffilyfe/2aedd169fa4a1af9ca4c to your computer and use it in GitHub Desktop.
POO - Implementação da classe Conta.
This file contains hidden or 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 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