Created
September 25, 2017 20:18
-
-
Save steppat/799bda914ddcf7b6d8cc389747c06eaa to your computer and use it in GitHub Desktop.
pequeno exemplo de uma class que representa um 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
class Conta { | |
//atributos | |
private int numero; | |
private String titular; | |
private double saldo; | |
private double limite; | |
//construtor | |
Conta(int numero, String titular, double saldo, double limite) { | |
this.numero = numero; | |
this.titular = titular; | |
this.saldo = saldo; | |
this.limite = limite; | |
} | |
private boolean podeSacar(double valor_a_sacar) { | |
double valorDisponivelASacar = this.saldo + this.limite; | |
return valor_a_sacar <= valorDisponivelASacar; | |
} | |
boolean saca(double valor) { | |
if(this.podeSacar(valor)) { | |
this.saldo -= valor; | |
return true; | |
} | |
throw new IllegalArgumentException("O valor passou o limite"); | |
} | |
void deposita(double valor) { | |
this.saldo += valor; | |
} | |
void extrato() { | |
System.out.println("Saldo de " + this.saldo + " do titular " + this.titular); | |
} | |
void transfere(double valor, Conta conta) { | |
this.saca(valor); | |
this.deposita(valor); | |
} | |
public double getLimite() { | |
return limite; | |
} | |
public void setLimite(double limite) { | |
this.limite = limite; | |
} | |
public int getNumero() { | |
return numero; | |
} | |
public String getTitular() { | |
return titular; | |
} | |
public double getSaldo() { | |
return saldo; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment