Skip to content

Instantly share code, notes, and snippets.

@gustavo-depaula
Created September 12, 2016 19:43
Show Gist options
  • Save gustavo-depaula/99391f207e134abbfce4956593153bb4 to your computer and use it in GitHub Desktop.
Save gustavo-depaula/99391f207e134abbfce4956593153bb4 to your computer and use it in GitHub Desktop.
Casa
package casa;
import java.util.ArrayList;
import java.util.List;
/**
* Created by gustavo-depaula on 05/09/16.
*/
public class Casa {
int cor;
int totalDePortas = 0;
List<Porta> portas = new ArrayList<Porta>();
public int getCor() {
return cor;
}
public void pintar(int cor) {
this.cor = cor;
}
public int quantasPortasEstaoAbertas() {
int qtd = 0;
for (Porta p : portas)
if (p.isAberta())
++qtd;
return qtd;
}
public void adicionaPorta(Porta porta) {
this.portas.add(porta);
++this.totalDePortas;
}
public int totalDePortas() {
return totalDePortas;
}
}
package casa;
/**
* Created by gustavo-depaula on 05/09/16.
*/
public class Porta {
String descricao;
boolean aberta;
public void abre() {
setAberta(true);
}
public void fecha() {
setAberta(false);
}
public void setAberta(boolean aberta) {
this.aberta = aberta;
}
public Porta(String descricao, boolean aberta) {
this.descricao = descricao;
this.aberta = aberta;
}
public boolean isAberta() {
return aberta;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment