programación i - Universidad ORT Uruguay
programación i - Universidad ORT Uruguay
programación i - Universidad ORT Uruguay
You also want an ePaper? Increase the reach of your titles
YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.
118 Programación I<br />
}<br />
Gasto max = new Gasto();<br />
Gasto aux;<br />
Iterator lista;<br />
lista = this.devolverTodosGastos().iterator();<br />
while (lista.hasNext()) {<br />
aux = lista.next();<br />
if (aux.getMonto() > max.getMonto()) {<br />
max = aux;<br />
}<br />
}<br />
return max;<br />
// BUSQUEDA DE UN GASTO DE MONTO DADO<br />
// VERSION 1: Método estaElGastoManualmente - recorre con Iteración<br />
// Busca un objeto Gasto del monto indicado<br />
public boolean estaElGastoManualmente(int unMonto) {<br />
Gasto unG;<br />
unG = new Gasto();<br />
unG.setMonto(unMonto);<br />
Iterator e = this.devolverTodosGastos().iterator();<br />
boolean esta = false;<br />
while (e.hasNext() && !esta) {<br />
Gasto g = e.next();<br />
if (g.equals(unG)) {<br />
esta = true;<br />
}<br />
}<br />
return esta;<br />
}<br />
// VERSION 2: Método estaElGasto - usa Contains<br />
// Busca un objeto Gasto del monto indicado<br />
public boolean estaElGasto(int unMonto) {<br />
Gasto unG;<br />
// creo un objeto Gasto, similar al que busco<br />
unG = new Gasto();<br />
unG.setMonto(unMonto);<br />
// para comparar, internamente usa el método equals de Gasto<br />
return (this.devolverTodosGastos().contains(unG));<br />
}<br />
// VERSION 3: Método buscarGastoDeMonto, usa indexOf<br />
// Otra posible implementación de buscar un Gasto<br />
// a partir del monto, utilizando métodos de la colección<br />
public Gasto buscarGastoDeMonto(int unMonto) {<br />
Gasto unG;<br />
// creo un objeto Gasto, similar al que busco<br />
// (similar implica que el método equals dara true)<br />
unG = new Gasto();<br />
unG.setMonto(unMonto);<br />
int aux;<br />
aux = (this.devolverTodosGastos().indexOf(unG));<br />
Gasto retorno = null;<br />
if (aux != -1) {<br />
retorno= (this.getListaGastos().get(aux));