Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- 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;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement