Hello, I'd like some help. I'm redoing the caelum object-oriented java handbook and there was a question I'd like some help with.
In the handbook asks to create a simple system of a bank. Going straight to the subject, was created a class account that has attributes such as the name of the client, balance limit these things. It has the sacar
method (it has a return of type boolean
, because it verifies the balance of the client at the time of withdrawal), deposit and transfer.
I've created a method called extrato
which shows the account owner's name, the balance, and the operations he did. I would like it to take a boolean
of the saca
method and print a message based on that information.
The following is the code below:
public class Conta{
int numero;
String dono;
double saldo;
double limite;
//métodos
boolean saca(double valor) {
if (this.saldo < valor) {
return false;
} else {
this.saldo = this.saldo - valor;
return true;
}
}
void deposita(double quantidade) {
this.saldo += quantidade;
}
boolean transfere(Conta destino, double valor) {
boolean retirou = this.saca(valor);
if (retirou == false) {
// não deu pra sacar!
return false;
} else {
destino.deposita(valor);
return true;
}
}
void extrato(){
System.out.println("Nome do Cliente: " +this.dono);
if(this.saca(valor) == true){
System.out.println("Saque de "+this.dono+" realizado com Sucesso!!!");
} else{
System.out.println("Saldo de "+this.dono+" está Insuficiente");
}
System.out.println("Saldo atual: " +this.saldo);
}
}
public class Programa {
public static void main(String[] args) {
Conta minhaConta = new Conta();
Conta minhaConta2 = new Conta();
minhaConta.dono = "Daniel Araújo";
minhaConta2.dono = "Maria Araújo";
minhaConta.saldo = 1000.0;
minhaConta2.saldo = 1500.0;
// saca 200 reais
minhaConta.saca(2000);
minhaConta2.saca(300);
// deposita 500 reais
minhaConta.deposita(500);
minhaConta2.deposita(100);
//transfere
minhaConta.transfere(minhaConta2, 250);
minhaConta.extrato();
minhaConta2.extrato();
}
}