4
I have a problem to implement this code, I can not enter the data in Arraylist.
public class Principal {
public static void main(String[] args) {
Faltas faltas = new Faltas();
faltas.inserirDados(111,3,5);
for(int j=0;j<faltas.size();j++){
System.out.println(faltas.get(j).getDados());
}
}
}
import java.util.ArrayList;
import java.util.List;
public class Faltas {
int matricula;
int mes;
int dia;
ArrayList<Faltas> faltas = new ArrayList();
public Faltas(int matricula, int mes, int dia) {
this.matricula = matricula;
this.mes = mes;
this.dia = dia;
}
public void inserirDados(int matricula,int mes, int dia) {
faltas.addAll(matricula,mes,dia);
}
public String getDados(){
return "matricula: "+this.matricula+
"\nMes: "+this.mes+
"\nDia: "+this.dia+
"\n";
}
}
Compile error:
Exception in thread "main" java.lang.Error: Unresolved compilation problems:
The constructor Faltas() is undefined
The method size() is undefined for the type Faltas
The method get(int) is undefined for the type Faltas
at TesteArray.Principal.main(Principal.java:9)
Hello André Lins, actually these data are enrollment 111, month 3 , day 5. My idea is to put this data in Arraylist to work later picking up the day and month absences of a student referenced by his enrollment (111).
– Bruno
@Bruno, see how you can do that in my answer
– Ivan Silva
André, I can keep the main as fouls.Inserted(111,3,5); ie without the new.
– Bruno