Good the problem is that I deposit 100, then remove 50, and when I want to check my balance (calling the method toString) it puts me 0.0, when I would have to say 60, since in the initial balance I put 10 and deposit 100, what could be the error?
Then I leave the code and the slogan of the exercise:
Implement the Account class, knowing that:
a. When you create an account, your balance is zero.
b. It is only possible to extract an amount less than or equal to the balance in the account.
public class Cuenta {
//Atributos
private String titular;
private double saldo;
//Constructor
public Cuenta() {
}
public Cuenta (String titular , double saldo_incial) {
this.titular=titular;
this.saldo = saldo;
}
//Metodos
public String getTitular() {
return this.titular;
}
public void setTitular() {
this.titular= titular;
}
public double getSaldo() {
return this.saldo;
}
public String toString() {
return "Titular : "+ this.titular + " saldo : "+ this.saldo;
}
public void depositar(double cantidad) {
System.out.println("Se deposito : "+cantidad);
}
public void retirar(double cantidad) {
if(cantidad>=saldo) {
System.out.println("Se extrae : "+cantidad);
}
else {
System.out.println("Solo es posible extraer un importe menor o igual al saldo que se tenga en la cuenta" );
}
}
}
-------------
public class PruebaCuenta {
public static void main(String[] args) {
Cuenta cuenta1 = new Cuenta();
Cuenta cuenta2 = new Cuenta ("jose" , 10);
cuenta1.getSaldo();
cuenta2.getSaldo();
System.out.println(cuenta2.toString());
cuenta2.depositar(100);
cuenta2.retirar(50);
System.out.println(cuenta2.toString());
}
}