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 Parsing Integers

this is not the task, it's the work space prototype. why is the prototype not working

this is not the task, it's the code to the work space prototype. why is the prototype not working. how can I attach my work space code to a post? thank you

ParsingInts.java
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!
        */
int age = 12;
if (age < 13) {
//Insert exit code
console.printf("Sorry you must be at lest 13 to use this program.\n");
System.exit(0); 
}  
String name = console.readLine("Enter a name:  ");
String adjective = console.readLine("Enter an adjective:  ");
String noun = console.readLine("Enter a noun:  ");
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);      


}

1 Answer

Antonio De Rose
Antonio De Rose
20,885 Points

could you please try this, I do not have an answer why the console readLine, always gives an error, it does gives me too, but I am seeing it as an issue for so many, and the recommended class is scanner, try the below code, which I have shaped, as per to your requirement, and as per to fit into java terms, where there will be no errors

package com.example.java;

import java.text.NumberFormat;
import java.util.Locale;
import java.io.Console;
import java.util.Scanner;

public class Main {

    public static void main(String[] args) {

        //Console console = System.console();

        Scanner s = new Scanner(System.in);

        /*  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!
        */
        int age = 16;
        if (age < 13) {
        //Insert exit code
            System.out.println("Sorry you must be at lest 13 to use this program.\n");
            System.exit(0);
        }

        System.out.println("Enter a name:  ");
        String name = s.nextLine();
        System.out.println("Enter an adjective:  ");
        String adjective = s.nextLine();
        System.out.println("Enter a noun:  ");
        String noun = s.nextLine();
        System.out.println("Enter an adverb:  ");
        String adverb = s.nextLine();
        System.out.println("Enter a verb ending with -ing:  ");
        String verb = s.nextLine();

        System.out.println("Your TreeStory:\n--------------\n");
        String result = String.format(name, adjective, noun, "\"%s is a %s %s.  \", ");
        String result1 = String.format("They are always %s %s.\n", adverb, verb);
        System.out.println(result);
        System.out.println(result1);
    }
}