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

I think Workspace is having issues! please help! when i run i get no ERRORS but no RESULTS!! as the code OUTPUT

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!
       */
       String ageAsString = console.readLine ("How old are you?");

      int age = Integer.parseInt(ageAsString);
      if (age < 13) {
        console.printf(" sorry you must be 13 and above to use this code  \n");
        System.exit(0);
      }
       String name = console.readLine("Enter your name:  ");
       String adjective = console.readLine("Enter an adjective:  ");
       String noun = console.readLine("Enter a noun:  ");

       if(noun.equalsIgnoreCase("dork") || noun.equalsIgnoreCase("jerk")) {
         console.printf("This language is not allowed exiting..\n");
         System.exit(0);
       }    


       String adverb = console.readLine("Enter an adjective: ");
       String verb = console.readLine("Enter an adverd ending in-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);
   }   
}

[MOD: edited code block - sh]

2 Answers

That works OK here - try refreshing the workspace.

Steve.

Hi Steve....actually

if(noun.equalsIgnoreCase("dork") || noun.equalsIgnoreCase("jerk")) {
         console.printf("This language is not allowed exiting..\n");
         System.exit(0);
       }  

can you try this? try run it again type dork or jerk with block letters or small letters.. its supposed to stop and exit but its not doing that.

[MOD: edited code block - sh]

Yes, I tried that and "dork" stopped execution.

DORK and JERK stop execution if entered as a noun; nowhere else - but that's what the code does, so I assume that's what you're trying to achieve?

Hi Steve thanks i think i got it now. After i restarted my machine and re-compiled from the top. It worked! I appreciate your help.. Thanks a lot. Am just eager to learn.

Yes, do make sure that whenever you change any code, you save the file and run the full compile command, javac TreeStory.java && java TreeStory otherwise, you'll be running old code. You shouldn't need to restart your machine, though!

Keep on learning!

Steve.

treehouse:~/workspace$ java TreeStory                                                  
How old are you?34                                                                     
Enter your name:  Some Name                                                            
Enter an adjective:  fast                                                              
Enter a noun:  ball                                                                    
Enter an adjective: incandescent                                                       
Enter an adverd ending in-ing:  ring                                                   
your TreeStory:                                                                        
---------------                                                                        
Some Name is a fast ball.  they are always incandescent ring.                          
treehouse:~/workspace

seemed to work okay when i copied your code into a workspace.

Hi Simon..actually

if(noun.equalsIgnoreCase("dork") || noun.equalsIgnoreCase("jerk")) {
         console.printf("This language is not allowed exiting..\n");
         System.exit(0);
       }    

can you try this? try run it again type dork or jerk with block letters or small letters.. its supposed to stop and exit but its not doing that.

[MOD: edited code block - sh]

Hi.. would you happen to know if treehouse has got a hotline no??? i have edited this code saved and its not saving properly. Am pretty much sure something is going on my work-space.

treehouse:~/workspace$ java TreeStory                                                  
How old are you?43                                                                     
Enter your name:  some name                                                            
Enter an adjective:  red                                                               
Enter a noun:  jerk                                                                    
This language is not allowed exiting..                                                 
treehouse:~/workspace

are you recompiling?

Hi Simon i think i got it..after I restarted my machine and re-compiled it worked! thank you for the help. I like the response here!