That does not make much sense. A ArrayList
of avaliacaoMensal
can only contain objects of type avaliacaoMensal
. You need to create an instance of this class and add the element to the list.
public avaliacaoMensal todosMensal(){
List<avaliacaoMensal> dados = new ArrayList<avaliacaoMensal>();
avaliacaoMensal aMensal = new avaliacaoMensal();
// Fazer algo para setar o valor dos atributos questao, potencial e resultado
dados.add(aMensal);
}
Note that the current code of the avaliacaoMensal
class does not contain methods for accessing its properties (the famous getters
and setters
), you need to create them.
It is also good to follow the Java naming pattern for class names (camel case with the first capital letter), the class should be called AvaliacaoMensal
.
A very common practice is also the creation of constructors that receive as parameter some values of attributes, to already create an instance of the class with some determined values.
Your class, following these tips, would look like this:
public class AvaliacaoMensal {
private String questao;
private char potencial;
private int resultado;
public AvaliacaoMensal(String questao, char potencial, int resultado) {
this.questao = questao;
this.potencial = potencial;
this.resultado = resultado;
}
public String getQuestao() {
return questao;
}
public void setQuestao(String questao) {
this.questao = questao;
}
public char getPotencial() {
return potencial;
}
public void setPotencial(char potencial) {
this.potencial = potencial;
}
public int getResultado() {
return resultado;
}
public void setResultado(int resultado) {
this.resultado = resultado;
}
}
In this way, you could use something like the one you tried at the beginning:
public AvaliacaoMensal todosMensal(){
List<AvaliacaoMensal> dados = new ArrayList<AvaliacaoMensal>();
dados.add(new AvaliacaoMensal("Aaa", 'a', 1));
// Continuação do código
}
You can see it working on repl.it.