3
I am creating a question and answer game, with the attributes: question, correct answer and the ArrayList
option (private ArrayList<String> opcao = new ArrayList<String>();
). I need the getter of the options to use in my main class to print the questions and answers on the screen, only I’m not sure how to create the getter of options for being a ArrayList
. I’ve tried a few ways and when I go to the main class I can’t access the getter.
public class Perguntas {
private String pergunta;
private ArrayList<String> opcao = new ArrayList<String>();
private String respostaCorreta;
//Metodo Construtor
public Perguntas(String p, String res, String opc1, String opc2, String opc3) {
this.pergunta = p;
this.opcao.add(opc1);
this.opcao.add(opc2);
this.opcao.add(opc3);
this.respostaCorreta = res;
}
//GET E SET DA PERGUNTA
public String getPergunta() {
return pergunta;
}
public void setPergunta(String p) {
this.pergunta = p;
}
//GET E SET DAS OPCOES
//GET E SET DA RESPOSTA CORRETA
public String getRespostaCorreta() {
return respostaCorreta;
}
public void setRespostaCorreta(String res) {
this.respostaCorreta = res;
}
}
This might help https://answall.com/a/100868/2541
– ramaral