Skip to content

Instantly share code, notes, and snippets.

@steppat
Created September 25, 2017 20:18
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 steppat/799bda914ddcf7b6d8cc389747c06eaa to your computer and use it in GitHub Desktop.
Save steppat/799bda914ddcf7b6d8cc389747c06eaa to your computer and use it in GitHub Desktop.
pequeno exemplo de uma class que representa um Conta
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