Created
February 1, 2016 12:34
-
-
Save peas/94f3532e8ee1ca76c56d to your computer and use it in GitHub Desktop.
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
class Pessoa { | |
private String nome; | |
String cpf; | |
String endereco; | |
String getNome() { | |
return this.nome; | |
} | |
void setNome(String nome) { | |
// valida, pesquisa, confere, salva no banco | |
this.nome = nome; | |
} | |
} | |
class Conta { | |
private double saldo; | |
private int numero; | |
private int agencia; | |
private Pessoa titular; | |
private static int totalDeContas; | |
Conta() { | |
Conta.totalDeContas++; | |
} | |
int getTotalDeContas() { | |
return Conta.totalDeContas; | |
} | |
Pessoa getTitular() { | |
return this.titular; | |
} | |
void setTitular(Pessoa titular) { | |
this.titular = titular; | |
} | |
boolean transfere(double valor, Conta destino) { | |
if(!this.saca(valor)) { | |
return false; | |
} | |
destino.deposita(valor); | |
return true; | |
} | |
void deposita(double valor) { | |
// System.out.println("estou depositando " + valor + " em " + this); | |
this.saldo = this.saldo + valor; | |
} | |
boolean saca(double valor) { | |
if(this.saldo < valor) { | |
return false; | |
} else { | |
this.saldo = this.saldo - valor; | |
return true; | |
} | |
} | |
double getSaldo() { | |
return this.saldo; | |
} | |
} | |
class Teste { | |
public static void main(String[] args) { | |
Conta c; | |
c = new Conta(); | |
c.deposita(100); | |
Pessoa p = new Pessoa(); | |
c.setTitular(p); | |
c.getTitular().setNome("paulo"); | |
System.out.println(c.getTitular().getNome()); | |
Pessoa titularDestaConta = c.getTitular(); | |
String nomeDoTitularDestaConta = titularDestaConta.getNome(); | |
System.out.println(nomeDoTitularDestaConta); | |
Conta d; | |
d = new Conta(); | |
d.saca(50); | |
System.out.println(c.getSaldo()); | |
System.out.println(d.getSaldo()); | |
System.out.println(c); | |
System.out.println(d); | |
c.deposita(100); | |
d.deposita(50); | |
c.transfere(10, d); | |
if(!c.saca(80000)) { | |
System.out.println("nao consegui sacar!"); | |
} | |
c.saca(12323); | |
if (c == d) { | |
System.out.println("sim"); | |
} else { | |
System.out.println("nao"); | |
} | |
System.out.println("Total de contas é " + Conta.getTotalDeContas()); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment