3
Create an abstract class Conta
, and two other concrete classes ContaF
and ContaJ
inherited from the main class. Create another class with a method that receives a list of contaF
and ContaJ
and ArrayList<Conta>
and calculate how many elements it has in ContaF
and ContaJ
I’m about to finish:
public class InstanciaDe
{
public static void main( String[] args )
{
ContaF Rafael = new ContaF();
ContaJ Roberto = new ContaJ();
ContaJ Carlos = new ContaJ();
ArrayList<Conta> lista = new ArrayList<Conta>();
lista.add(Rafael);
lista.add(Roberto);
lista.add(Carlos);
for(int i=0 ; i < lista.size() ; i++){
if (lista.get(i) instanceof ContaF) {
}
if (lista.get(i) instanceof ContaJ) {
}
}
}
}
How can I save the amount by instanceof
each and then display?
int nContaF = 0; if(lista.get(i) instanceof ContaF) nContaf++;
– Guilherme Lautert
Thank you, I was thinking of something similar.
– Rafael Augusto