-
-
Save parzibyte/d9c0a9652129817c5081d021e5151fca to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class Cuenta { | |
private double saldo; | |
private Usuario usuario; | |
private List<Gasto> gastos; | |
private List<Ingreso> ingresos; | |
public Cuenta(Usuario usuario) { | |
this.usuario = usuario; | |
this.saldo = 0; | |
this.gastos = new ArrayList<>(); | |
this.ingresos = new ArrayList<>(); | |
} | |
public double getSaldo() { | |
return saldo; | |
} | |
public void setSaldo(double saldo) { | |
this.saldo = saldo; | |
} | |
public Usuario getUsuario() { | |
return usuario; | |
} | |
public void setUsuario(Usuario usuario) { | |
this.usuario = usuario; | |
} | |
public double addIngresos(String description, double cantidad) { | |
this.setSaldo(this.getSaldo() + cantidad); | |
this.ingresos.add(new Ingreso(cantidad, description)); | |
return this.getSaldo(); | |
} | |
public double addGastos(String description, double cantidad) throws GastoException { | |
if (this.getSaldo() < cantidad) { | |
throw new GastoException(); | |
} | |
this.setSaldo(this.getSaldo() - cantidad); | |
this.gastos.add(new Gasto(cantidad, description)); | |
return this.getSaldo(); | |
} | |
public List<Gasto> getGastos() { | |
return gastos; | |
} | |
public List<Ingreso> getIngresos() { | |
return ingresos; | |
} | |
@Override | |
public String toString() { | |
return "Cuenta{" + | |
"saldo=" + saldo + | |
", usuario=" + usuario + | |
", gastos=" + gastos + | |
", ingresos=" + ingresos + | |
'}'; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment