This is the assignment: http://www.eng.auburn.edu/~cross/comp1210/Lab/Projects/P
ID: 3632556 • Letter: T
Question
This is the assignment: http://www.eng.auburn.edu/~cross/comp1210/Lab/Projects/Project_09.pdf
I need help with the displayQuestion method in the QuizQuestion class. I need to split the text of the question after 50 characters but not splitting a word. This is what I have so far:
public String displayQuestion() {
Scanner s = new Scanner(question);
if (index.length() == 0) {
if (question.length() <= 50) {
output = "Question __:"
+ " " + question;
}
else if (question.length() > 50) {
while (s.hasNext()) {
output = "Question __:" //This only prints the last word of the question so it's wrong
+ " " + s.next();
}
}
return output;
}
else if (index.length() > 0) {
output = "Question: " + index
+ " ";
if (question.length() <= 50) {
output += question;
}
else if (question.length() > 50) {
while (s.hasNext()) {
output += question.split(" ") + " " + s.next(); //This prints every word in a new line, also wrong.
}
}
}
return output;
}
return output;
}
Explanation / Answer
import java.util.ArrayList;
import java.util.List;
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.