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 trialChokdee Srisuk
19,384 PointsI get an error "Looks like you didn't present the TreeStory(3)"
I run the same code in intelliJ, the result is fine. It can show the completed story. It seems Craig's program tries to check something and I miss out of it, resulting in this error "Looks like you didn't present the TreeStory(3)". Please find my code associated in this discussion.
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);
}
System.out.printf("%nYour TreeStory:%n%n%s", tmpl.render(results));
}
public String promptForWord(String phrase) throws IOException {
String inputtedWord;
System.out.printf("Please input your word for %s : ", phrase);
inputtedWord = mReader.readLine().toLowerCase().trim();
while (inputtedWord.length() == 0 || mCensoredWords.contains(inputtedWord) ) {
System.out.printf("%nYou didn't input any word or it's censored, please input %s again: ", phrase);
inputtedWord = mReader.readLine().toLowerCase().trim();
}
return inputtedWord;
}
public String promptForStoryTemplate() throws IOException {
String storyTemplate = mReader.readLine();
return storyTemplate;
}
Below is Main.java
public class Main {
public static void main(String[] args) {
// write your code here
Prompter prompter = new Prompter();
String story = null;
System.out.println("Please input your story: ");
try {
story = prompter.promptForStoryTemplate();
} catch (IOException e) {
System.out.println("There's a problem inputting a story");
e.printStackTrace();
System.exit(0);
}
Template tmpl = new Template(story);
prompter.run(tmpl);
}
}
2 Answers
Seth Kroger
56,413 PointsIn promptForWord() you don't need to use toLowerCase(). Just let any capitalization go through as-is.
Seth Kroger
56,413 PointsI believe you need to include phrase in the output when you ask for a word in promptForWord().
System.out.printf("Enter a %s: ", phrase);
Luis Garcia
1,552 PointsAwesome! That was it!
Thanks a lot, Luis
Chokdee Srisuk
19,384 PointsChokdee Srisuk
19,384 PointsI get passed this challenge. Thank you for helping me out. I owe you a high five.
Luis Garcia
1,552 PointsLuis Garcia
1,552 PointsHey Seth,
Would you mind kinly having a look at mine? It works just fine in IntelliJ
Main.java
Prompter.java