Welcome to the Treehouse Community

The Treehouse Community is a meeting place for developers, designers, and programmers of all backgrounds and skill levels to get support. Collaborate here on code errors or bugs that you need feedback on, or asking for an extra set of eyes on your latest project. Join thousands of Treehouse students and alumni in the community today. (Note: Only Treehouse students can comment or ask questions, but non-students are welcome to browse our conversations.)

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and a supportive community. Start your free trial today.

Java Local Development Environments Advanced Tooling Finishing TreeStory

My code works in intelli J not in the challenge for the Tree House Story. Prompter class does not exist?

''''java package com.teamtreehouse;

import java.util.Arrays; import java.util.List;

public class Main {

public static void main(String[] args) {

    Prompter prompter = new Prompter();
    prompter.storyTemplate();
    prompter.run();
}

}

'''

Really like to move on but this challenge is bugging me. Could someone please help.

MAIN CLASS

package com.teamtreehouse;

import java.util.Arrays;
import java.util.List;

public class Main {

    public static void main(String[] args) {

        Prompter prompter = new Prompter();
        prompter.run();

    }
}

PROMPTER CLASS

package com.teamtreehouse;

import java.io.*;
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.Paths;
import java.util.*;


public class Prompter {
    private BufferedReader mReader;
    private Set<String> mCensoredWords;

    public String storyTemplate(){
        System.out.printf("This is your Tree Story.%nPlease write a story with the nouns, adjectives, verbs and names surrounded by double underscore.%n%n" +
                "An example:%n%nThanks __name__ for helping me out. You are really a __adjective__ __noun__ and I owe you a __noun__.%n%n");
        Scanner sc = new Scanner(System.in);
        System.out.printf("Please enter your story:%n");
        String story = sc.nextLine();
        System.out.println("This is the story you entered: " + story);
        System.out.println();
        return story;
    }

    public Prompter() {
        mReader = new BufferedReader(new InputStreamReader(System.in));
        loadCensoredWords();
    }

    private void loadCensoredWords() {
        mCensoredWords = new HashSet<String>();
        Path file = Paths.get("TreeStory2", "TreeStory2","resources", "censored_words.txt");
        List<String> words = null;
        try {
            words = Files.readAllLines(file);
        } catch (IOException e) {
            System.out.println("Couldn't load censored words");
            e.printStackTrace();
        }
        mCensoredWords.addAll(words);
    }

    public void run() {
        Template tmpl = new Template(storyTemplate());
        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));
    }

    /**
     * Prompts user for each of the blanks
     *
     * @param tmpl The compiled template
     * @return
     * @throws IOException
     */
    public List<String> promptForWords(Template tmpl) throws IOException {
        List<String> words = new ArrayList<String>();
        for (String phrase : tmpl.getPlaceHolders()) {
            String word = promptForWord(phrase);
            words.add(word);
        }
        return words;
    }


    /**
     * Prompts the user for the answer to the fill in the blank.  Value is guaranteed to be not in the censored words list.
     *
     * @param phrase The word that the user should be prompted.  eg: adjective, proper noun, name
     * @return What the user responded
     */
    public String promptForWord(String phrase) {
        String userWord;
        boolean isCensored = false;


        do{
            System.out.printf("Please enter a %s:%n", phrase);
            Scanner sc = new Scanner(System.in);
            userWord = sc.nextLine();

            for (String censoredWord : mCensoredWords){
                if(userWord.equals(censoredWord) || userWord.length() <1 ){
                    System.out.printf("That is an invalid entry. Please choose another word.%n");
                    isCensored = true;
                    break;
                } else {
                    isCensored = false;
                }
            }
        }
        while(isCensored);

        return userWord;


    }
}

1 Answer