Created
September 12, 2016 19:43
-
-
Save gustavo-depaula/99391f207e134abbfce4956593153bb4 to your computer and use it in GitHub Desktop.
Casa
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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