1
I want to create a ArrayList
to store information about students (name, number and status) but I’m not getting Arraylistadicione the information.
The code I have is this::
Java class.
package turma;
public class Aluno {
public String nome;
public int nmec;
public String estatuto;
public Aluno(int nmec, String nome) {
this.nome = nome;
this.nmec = nmec;
estatuto = "Regular";
}
public String getNome() {
return nome;
}
public int getNMec() {
return nmec;
}
public String getEstatuto() {
return estatuto;
}
public void getInfo() {
System.out.print(getNome() + " - " + getNMec() + " - " + getEstatuto());
}
}
Turmamax.java.
package turma;
import java.util.ArrayList;
/**
*
* @author Z
*/
public class TurmaMax {
public ArrayList<Aluno> turma;
private int i;
public TurmaMax() {
turma = new ArrayList<Aluno>();
}
public void novoAluno (int nmec, String nome){
if(turma.size() < 30) {
turma.add(new Aluno(nmec,nome));
} else {
System.out.print("Turma cheia");
}
}
public void listaAlunos(){
for (i=0; i<turma.size(); i++) {
System.out.println(turma.getInfo()); // o erro acontece nesta linha
}
}
}
What’s wrong with my code?