public class Answer { private String answer; private int points; public Answer()
ID: 3575766 • Letter: P
Question
public class Answer {
private String answer;
private int points;
public Answer() {
}
public Answer(String answer, int points) {
this.answer = answer;
this.points = points;
}
public void setAnswer(String answer) {
this.answer = answer;
}
public String getAnswer() {
return answer;
}
public void setPoints(int points) {
this.points = points;
}
public int getPoints() {
return points;
}
@Override
public String toString() {
return String.format("%s %3d", answer, points);
}
}
If you want to keep some questions in the game then you can go to following one
public class Question() {
private String question;
private Answer[] answers;
public Question(String question, Answer[] answers) {
this.question = question;
this.answers = answers;
}
public Question() {
answers = new Answer[5];
}
public setQuestion(String question) {
this.question = question;
}
public String getQuestion() {
return question;
}
public void setAnswers(Answer[] answers) {
this.answers = answers;
}
public void setAnswer(int index, String answer, int points) {
if(index < answers.length) {
answers[index] = new Answer(answer, points);
}
}
public Answer[] getAnswers() {
return answers;
}
public Answer getAnswer(int index) {
if (index < answers.length) {
if (answers[index] != null) {
return answers[index];
}
else {
return null;
}
}
}
public String getAnswerStrings() {
StringBuilder sb = new StringBuilder();
for(Answer a : answers) {
sb.append(a.toString() + " ");
}
return sb.toString();
}
@Override
public String toString() {
StringBuilder sb = new StringBuilder();
sb.append(question + " ");
sb.append(getAnswerStrings);
}
}
can someone put this into a GUI
Explanation / Answer
import java.util.*;
import java.awt.*;
class addgraphics implements actionlistener{
Jpanel j=new Jpanel();
b1 = new jbutton("answer",left buttonicon);
b1.addActionListener(this);
b2= new jbutton("get next question",right buttonicon);
b2.addActionListener(this);
b3= new jbuttom("getpoints" midllebuttonicon);
b3.addActionListener(this);
public void actionperformed(actionevent ae)
{
ae.b1.addactionlistener(getanswers());
ae.b2.addactionlisterner(getquestions());
ae.b3.addactionlistner(getpoints());
}
}
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.