Welcome to the Treehouse Community
Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.
Looking to learn something new?
Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.
Start your free trial
Conor Graham
7,956 PointsHelp with TODOs Java Challenge
Hi there, I am having problems with the last challenge which consists of the TODOs. The first TODO I am stuck on is :
//TODO:csd - Instantiate a new prompter object and prompt for the story template.
I was thinking of doing something like the following:
Prompter prompter = new Prompter();
//Instantiate object in main class
//Then in Prompter class create a method that will get the story such as:
public String promptForStory() {
System.out.printf("Enter your story Template:")
String story = null;
try {
story = mReader.readLine();
}
catch(Exception e) {
e.printStackTrace();
}
return story;
}
Would something like this be correct for the first TODO?
3 Answers
Seth Kroger
56,416 PointsYes, what you have there is pretty much what the TODO is asking for.
Conor Graham
7,956 PointsHi Seth, perfect. Now the next TODO is:
// TODO:csd - Print out the results that were gathered here by rendering the template
For this TODO I was thinking of doing:
public void run(Template tmpl) {
List<String> results = null;
try {
results = promptForWords(tmpl);
} catch (IOException e) {
System.out.println("There was a problem prompting for words");
e.printStackTrace();
System.exit(0);
}
// TODO:csd - Print out the results that were gathered here by rendering the template
String finalResult = tmpl.render(results);
System.out.printf("Your TreeStory:%n%n%s", finalResult);
}
Would this be correct?
Conor Graham
7,956 PointsThanks for the plus 1 Craig. Just taking this step by step. The next TODO I am having trouble with is:
// TODO:csd - Prompt the user for the response to the phrase, make sure the word is censored, loop until you get a good response.
For this, I have coded this function. Am I far away?
public String promptForWord(String phrase) throws IOException {
System.out.printf("Enter your %s",phrase);
String response = null;
response = mReader.readLine();
while (mCensoredWords.contains(response)) {
System.out.printf("That is bad language. Try again: ");
response = mReader.readLine();
}
System.out.printf("Thanks for the response.");
// TODO:csd - Prompt the user for the response to the phrase, make sure the word is censored, loop until you get a good response.
//Post this to forum
return phrase;
}