Transfer system ( options)

Asked

Viewed 112 times

-1

Good afternoon!

Guys, I’m a beginner and I wanted to know how to simulate a bank transfer (Account + Conta2), being "Conta2" a class created outside the Class "Account".

I made the Withdraw and Deposit methods within the "Account Class".

My code is like this:

public class Conta {

String nome; String numero; double saldo;

public void Depositar(double NovoValor) {

if (NovoValor > 0) this.saldo = this.saldo + NovoValor; }

public void Sacar(double NovoSaque) {

if (this.saldo > NovoSaque) this.saldo = this.saldo - NovoSaque;

}

}
  • As you are beginning I will ask before giving my answer, you have already read about static methods?

  • Not yet, I’m on the 1° facul, this is an exercise and it’s as far as I can get with what I know so far.

1 answer

0

You must do a function to perform the transfer that will have as parameters: the target account and the value, this function will call the two other functions you have already done after all, if we can reuse the code is better.

public void transferir(Conta destino, double valor){
    destino.Depositar(valor);
    this.Sacar(valor);
}

Browser other questions tagged

You are not signed in. Login or sign up in order to post.