Well, I researched a lot, I even know how it works, but I could not implement it, I would like a light. I have the classes House and Building, I need to create a parent class Imovel, taking House and Building as daughter classes, follow my code:
package br.edu.utfpr.exer05;
public class Porta {
boolean aberta;
String cor;
double dimensaoX, dimensaoY, dimensaoZ;
void abre() {
this.aberta = true;
}
void fecha() {
this.aberta = false;
}
void pinta(String cor) {
this.cor = cor;
}
boolean estaAberta() {
boolean estaAberta = false;
if(aberta == true) estaAberta = true;
return estaAberta;
}
}
package br.edu.utfpr.exer05;
import java.util.ArrayList;
public class Edificio {
String cor;
int totalDePortas;
int totalDeAndares;
ArrayList<Porta> portas = new ArrayList<Porta>();
void pinta(String cor) {
this.cor = cor;
}
int quantasPortasEstaoAbertas() {
int qtdPortasAbertas = 0;
for(int i=0; i<portas.size(); i++) {
portas.get(i);
if(portas.get(i).estaAberta() == true) {
qtdPortasAbertas++;
}
}
return qtdPortasAbertas;
}
void adicionaPorta(Porta porta) {
this.portas.add(porta);
}
int totalDePortas() {
return this.portas.size();
}
void adicionaAndar() {
this.totalDeAndares = totalDeAndares += 1;
}
int totalDeAndares() {
return this.totalDeAndares;
}
}
package br.edu.utfpr.exer05;
public class Casa {
String cor;
Porta porta1, porta2, porta3;
void pinta(String cor) {
this.cor = cor;
}
int quantasPortasEstaoAbertas() {
int qtdPortasAbertas=0;
if(porta1.estaAberta() == true) qtdPortasAbertas++;
if(porta2.estaAberta() == true) qtdPortasAbertas++;
if(porta3.estaAberta() == true) qtdPortasAbertas++;
return qtdPortasAbertas;
}
int totalDePortas() {
return 3;
}
}
And here is the class I need to make the "parent":
package br.edu.utfpr.exer05;
import java.util.ArrayList;
public class Imovel {
String cor;
ArrayList<Porta> portas = new ArrayList<Porta>();
}
The classes House and Building are made in different ways because the exercise requested, but has the same goal. Well, how do I create a parent class as described?