I want to create a ArrayList
to store information about students (name, typing number and status) but I can not get ArrayListadded the information.
The code I have is the following:
Turma.java
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?