Skip to content

Instantly share code, notes, and snippets.

@parzibyte
Created April 20, 2021 19:30
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save parzibyte/d9c0a9652129817c5081d021e5151fca to your computer and use it in GitHub Desktop.
Save parzibyte/d9c0a9652129817c5081d021e5151fca to your computer and use it in GitHub Desktop.
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