10.05.2014 Views

programación i - Universidad ORT Uruguay

programación i - Universidad ORT Uruguay

programación i - Universidad ORT Uruguay

SHOW MORE
SHOW LESS

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

Programación I 117<br />

}<br />

Casa:<br />

}<br />

package gastosCasa;<br />

return this.getMonto() == ((Gasto) parm1).getMonto();<br />

import java.util.*;<br />

public class Casa {<br />

// var de instancia<br />

ArrayList conjuntoGastos;<br />

String direccion;<br />

// Constructor<br />

public Casa() {<br />

conjuntoGastos = new ArrayList();<br />

this.setDireccion("Sin direccion");<br />

}<br />

// acceso y modificación<br />

public void setDireccion(String unaDireccion) {<br />

direccion = unaDireccion;<br />

}<br />

public String getDireccion() {<br />

return direccion;<br />

}<br />

public void agregarUnGasto(Gasto unGasto) {<br />

this.devolverTodosGastos().add(unGasto);<br />

}<br />

public ArrayList devolverTodosGastos() {<br />

return conjuntoGastos;<br />

}<br />

// devuelve cantidad de elementos<br />

public int cantidadGastos() {<br />

return this.devolverTodosGastos().size();<br />

}<br />

// MAXIMO<br />

// VERSION 1: Máximo a mano - recorro con for<br />

public Gasto devolverGastoMayorManualTotalmente() {<br />

Gasto max = new Gasto();<br />

Gasto aux;<br />

for (int i = 0; i < this.cantidadGastos(); i = i + 1) {<br />

aux = this.devolverTodosGastos().get(i);<br />

if (aux.getMonto() > max.getMonto()) {<br />

max = aux;<br />

}<br />

}<br />

return max;<br />

}<br />

// VERSION 2: Máximo - recorro con Iteración<br />

public Gasto devolverGastoMayorManual() {

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!