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.

116 Programación I<br />

}<br />

public void setDia(int unDia) {<br />

dia = unDia;<br />

}<br />

public int getMonto() {<br />

return monto;<br />

}<br />

public void setMonto(int unMonto) {<br />

monto = unMonto;<br />

}<br />

// ------------------------------------------------------<br />

// Impresión<br />

@Override<br />

public String toString() {<br />

return "Gasto " + this.getDescripcion() + " $ " + this.getMonto()<br />

+ " Dia: " + this.getDia();<br />

}<br />

// método compareTo<br />

public int compareTo(Gasto o) {<br />

return this.getMonto() - o.getMonto();<br />

}<br />

// método auxiliar para pedir datos de pantalla para crear un Gasto<br />

public static Gasto crearGasto() {<br />

Gasto unG;<br />

boolean ok;<br />

Scanner input = new Scanner(System.in);<br />

input.useDelimiter(System.getProperty("line.separator"));<br />

unG = new Gasto();<br />

ok = false;<br />

// pide datos, validando formato ok<br />

while (!ok) {<br />

try {<br />

System.out.println("Ingrese dia ");<br />

unG.setDia(input.nextInt());<br />

System.out.println("Ingrese descripcion ");<br />

unG.setDescripcion(input.next());<br />

System.out.println("Ingrese monto ");<br />

unG.setMonto(input.nextInt());<br />

ok = true;<br />

} catch (InputMismatchException e) {<br />

System.out.println("Datos erroneos, reingrese ");<br />

input.next();<br />

}<br />

}<br />

return unG;<br />

}<br />

// Método equals<br />

// Es necesario redefinir el método equals para que cuando<br />

// le pida buscar alguno, compare por este criterio para ver si es =<br />

@Override<br />

public boolean equals(Object parm1) {<br />

// Es necesario hacer cast porque el parámetro es Object

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

Saved successfully!

Ooh no, something went wrong!