Skip to content

Instantly share code, notes, and snippets.

@delucas
Created April 26, 2013 23:16
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save delucas/5471052 to your computer and use it in GitHub Desktop.
Save delucas/5471052 to your computer and use it in GitHub Desktop.
UNLaM - Ejercicios de clase - Objetos, 25/04/2013
package ar.edu.unlam.tallerweb;
public class Adivinanza {
private Integer numero;
public Adivinanza(Integer numero) {
this.numero = numero;
}
public Boolean adivinar(Integer numero) {
return numero == this.numero;
}
public Boolean esMasGrandeQue(Integer numero) {
return this.numero > numero;
}
public Boolean esMasChicoQue(Integer numero) {
return this.numero < numero;
}
}
package ar.edu.unlam.tallerweb;
public class CerraduraElectronica {
private Integer clave;
private Boolean abierta = false;
public CerraduraElectronica(Integer clave) {
this.clave = clave;
}
public void abrir(Integer clave) {
if (clave == this.clave) {
this.abierta = true;
}
}
public void cerrar(Integer clave) {
if (clave == this.clave) {
this.abierta = false;
}
}
public Boolean estaAbierta() {
return this.abierta;
}
}
package ar.edu.unlam.tallerweb;
public class Dado {
private Integer caras;
public Dado(Integer caras) {
this.caras = caras;
}
public Integer getCaras() {
return this.caras;
}
public Integer tirar() {
return (int) (Math.random() * this.caras) + 1;
}
}
package ar.edu.unlam.tallerweb;
public class Nota {
private Integer nota;
public Nota(Integer nota) {
this.nota = nota;
}
public Boolean estaAprobado() {
return nota >= 4;
}
public Boolean estaPromocionado() {
return nota >= 7;
}
public Boolean estaReprobado() {
return nota < 4;
}
}
package ar.edu.unlam.tallerweb;
class Subasta {
private Integer valor = 0;
private Boolean abierta = true;
Subasta(Integer valorInicial) {
this.valor = valorInicial;
}
void nuevaOferta(Integer oferta) {
if (this.abierta && oferta > this.valor) {
this.valor = oferta;
}
}
Integer cerrar() {
this.abierta = false;
return this.valor;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment