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

Java Java Basics Perfecting the Prototype Censoring Words - Looping Until the Value Passes

Arjun Vemperala
Arjun Vemperala
1,212 Points

Censoring Words - Looping Until the Value Passes

i am getting these two errors, please explain what is wrong with the code and how to correct it

TreeStory.java:36: error: reached end of file while parsing
console.printf("They are always %s %s.\n", adverb, verb);
^
TreeStory.java:38: error: reached end of file while parsing

  ^                                                                                                            

2 errors

This is the entire code

import java.io.Console;

public class TreeStory {

public static void main(String[] args) {
    Console console = System.console();
    /*  Some terms:
        noun - Person, place or thing
        verb - An action
        adjective - A description used to modify or describe a noun
        Enter your amazing code here!
    */
  // Name__ is a __ adjective__ __ noun__. They are always __adverb__ __ verb__.
  String ageAsString = console.readLine("How old are you?");
  int age = Integer.parseInt(ageAsString);
  if (age < 13) {
    // Insert or exit code
    console.printf("Sorry you must be at least 13 to use this program.\n");
                   System.exit(0);
                   }

  String name = console.readLine("Enter a name:  ");

String adjective = console.readLine("Enter an adjective: "); do{ String noun = console.readLine("Enter a noun: "); if (noun.equalsIgnoreCase("dork") || noun.equalsIgnoreCase("jerk")){ console.printf("That language is not allowed. Try again \n\n"); } while(noun.equalsIgnoreCase("dork") || noun.equalsIgnoreCase("jerk")); String adverb = console.readLine("Enter an adverb: "); String verb = console.readLine("Enter a verb ending with -ing: "); console.printf("Your TreeStory:\n-----------\n"); console.printf("%s is a %s %s. ", name , adjective, noun); console.printf("They are always %s %s.\n", adverb, verb);

3 Answers

Simon Coates
Simon Coates
28,694 Points

i think your code is malformed. Can you fix the markdown (see the markdown cheatsheet) and confirm that you posted everything. It that is the entire code, you're ending the code with a statement not a }, hence your structure is messed up.

Arjun Vemperala
Arjun Vemperala
1,212 Points

took snapshot of the worksheet please use the link below https://w.trhou.se/u2qkl5ouq5

Jennifer Nordell
seal-mask
STAFF
.a{fill-rule:evenodd;}techdegree
Jennifer Nordell
Treehouse Teacher

I'm in agreement with Simon Coates we're going to need to see this more clearly formatted. Alternatively, you can link us a snapshot to your workspace :smiley: But this error that you're getting is very likely because you are missing an ending curly brace at the bottom of the code. What it's saying is that it ran out of code and never got to the last curly brace. So I'm suspicious that what you posted is the entirety of your code, but I'd like to see it for myself.

Arjun Vemperala
Arjun Vemperala
1,212 Points

took snapshot of the worksheet please use the link below https://w.trhou.se/u2qkl5ouq5

Simon Coates
Simon Coates
28,694 Points

I'm having some problems with the workspace, but you need to have two } at the end of the file, and there's an if condition that isn't closed. Then you need to declare noun earlier in the code. In java scope is the containing {}, hence you have a reference to noun outside scope. And better indenting. The following code compiles, but i haven't taken a look at if it does what you want it to do.

import java.io.Console;

public class TreeStory {

    public static void main(String[] args) {
        Console console = System.console();
        /*  Some terms:
            noun - Person, place or thing
            verb - An action
            adjective - A description used to modify or describe a noun
            Enter your amazing code here!
        */
      // Name__ is a __ adjective__ __ noun__. They are always __adverb__ __ verb__.
      String ageAsString = console.readLine("How old are you?");
      int age = Integer.parseInt(ageAsString);
      if (age < 13) {
        // Insert or exit code
        console.printf("Sorry you must be at least 13 to use this program.\n");
                       System.exit(0);
                       }
       String noun;         //here       
      String name = console.readLine("Enter a name:  ");
String adjective = console.readLine("Enter an adjective:  ");
      do{
       noun = console.readLine("Enter a noun:  ");
      if (noun.equalsIgnoreCase("dork") ||noun.equalsIgnoreCase("jerk")){
        console.printf("That language is not allowed. Try again \n\n");
        }
      }
      while(noun.equalsIgnoreCase("dork") ||  noun.equalsIgnoreCase("jerk"));
      String adverb = console.readLine("Enter an adverb:  ");
      String verb = console.readLine("Enter a verb ending with -ing:  ");
      console.printf("Your TreeStory:\n-----------\n");
     console.printf("%s is a %s %s.  ", name , adjective, noun);
      console.printf("They are always %s %s.\n", adverb, verb);

      }       //here   
    }       //here   

All { need to have corresponding }, and indenting can help you see the matching tags.