Project 4 - Survey Says Part 1 A popular game show, Family Feud, asks contestant
ID: 3707460 • Letter: P
Question
Project 4 - Survey Says Part 1 A popular game show, Family Feud, asks contestanttoguess answers to a question about which a survey of 100 people has been taken. This project, part 1 of 2, will develop, in Java, a 'SurveySays' class for that purpose. To aide in this project, the game show host, Joe Btfsplk, has provided some starter code. Complete the SurveySays class having the following constructor and instance methods: public SurveySays(String question) public void addAnswer( String answer) public int checkAnswer( String answer) Modily the getSurveybermethod cturn your sudent ID Complete the Answer class having the following constructor and instance methods public Answer( String answer) public void addToCount () public int getCount () public boolean equals (String otherAnswer)Explanation / Answer
Please find the code below with detailed inline comments.
Answer.java
**************************
class Answer() {
String ans;
static int count = 0;
public Answer(String ans) {
this.ans = ans;
addToCount();
}
public void addToCount() {
count ++;
}
public static int getCount() {
return count;
}
public boolean equals(String otherAnswer) {
return ans.equalsIgnoreCase(otherAnswer);
}
}
SurveySays.java (Incompleted methods)
*******************************
public void addAnswer(String answer) {
Answer ans = new Answer(answer);
container.add(Answer.getCount(), ans);
}
public int checkAnswer(String ans) {
int count = 0;
for(int i=0; i<Answer.getCount(); i++) {
if(container.get(i).equals(ans)) {
count ++;
}
}
return count;
}
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.