Welcome to the Java Programming Forums


The professional, friendly Java community. 21,500 members and growing!


The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


>> REGISTER NOW TO START POSTING


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 8 of 8

Thread: Simple Text Quest Help

  1. #1
    Junior Member
    Join Date
    Jan 2012
    Posts
    2
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Default Simple Text Quest Help

    I am trying to create a text related a quest with just words.
    I'm about 5 days into java and I'm not very good at it. (using eclipse btw)

    I am trying to make something like..

    it prints a line saying 'cats or dogs?'
    and you type dogs
    and it types back to you 'dogs it is'
    something like you can say something and it does something else.

    I am really new at this so try not to confuse me, thanks


  2. #2
    Forum VIP
    Join Date
    Jun 2011
    Posts
    317
    My Mood
    Bored
    Thanks
    47
    Thanked 89 Times in 74 Posts
    Blog Entries
    4

    Default Re: Simple Text Quest Help

    I wrote an class not long ago to help new users get user input from the command line. You can get it here:
    Valid user input.

    Create a new class in eclipse called Console.java and copy all the code from the article. You do not need to change anything in this class. Now in your main method you can use it like so:

    //Ask the user for input
    String userInput = Console.readString("Enter dogs or cats: ");
     
    //Print the result
    if (userInput.equals("dogs")) {
         System.out.println("Dogs it is.");
    }
    else if (userInput.equals("cats")) {
         System.out.println("Cats it is.");
    }
    else {
         System.out.println("Invalid input.");
    }
    Last edited by ChristopherLowe; January 15th, 2012 at 01:10 AM.

  3. The Following User Says Thank You to ChristopherLowe For This Useful Post:

    cshaffer123 (January 15th, 2012)

  4. #3
    Junior Member
    Join Date
    Jan 2012
    Posts
    2
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Default Re: Simple Text Quest Help

    Thank you very much for the help!

  5. #4
    Member
    Join Date
    Dec 2011
    Location
    United States
    Posts
    94
    My Mood
    Amused
    Thanks
    5
    Thanked 8 Times in 8 Posts

    Default Re: Simple Text Quest Help

    The easiest and most efficient way is to use the switch statement. Research on that and you will be fine with it soon.

  6. #5
    Think of me.... Mr.777's Avatar
    Join Date
    Mar 2011
    Location
    Pakistan
    Posts
    1,136
    My Mood
    Grumpy
    Thanks
    20
    Thanked 82 Times in 78 Posts
    Blog Entries
    1

    Default Re: Simple Text Quest Help

    Quote Originally Posted by elisha.java View Post
    The easiest and most efficient way is to use the switch statement. Research on that and you will be fine with it soon.
    If you are not aware of Java 7, how can you think switch will work for String?
    Well, in Java 7, it does

  7. #6
    Member
    Join Date
    Dec 2011
    Location
    United States
    Posts
    94
    My Mood
    Amused
    Thanks
    5
    Thanked 8 Times in 8 Posts

    Default Re: Simple Text Quest Help

    Perhaps it should help to spark a programmer's curiosity! Thank you for pointing out though. You always have a point.

  8. #7
    Think of me.... Mr.777's Avatar
    Join Date
    Mar 2011
    Location
    Pakistan
    Posts
    1,136
    My Mood
    Grumpy
    Thanks
    20
    Thanked 82 Times in 78 Posts
    Blog Entries
    1

    Default Re: Simple Text Quest Help

    Quote Originally Posted by elisha.java View Post
    Perhaps it should help to spark a programmer's curiosity! Thank you for pointing out though. You always have a point.
    Everyone has the point and we all are here to help others in learning stage. I am too in a learning stage and this stage never gonna end. So, i try my best to help others to improve their concepts by simply pointing them out, as the best of my knowledge. And one more thing, i am not always correct because i am also a learner so comments are open to all to read and comment about. Hope you don't take them personal.

  9. #8
    Member
    Join Date
    Dec 2011
    Location
    United States
    Posts
    94
    My Mood
    Amused
    Thanks
    5
    Thanked 8 Times in 8 Posts

    Default Re: Simple Text Quest Help

    Thanks. I do not take anything personal. Learning is a lifelong process!

Similar Threads

  1. simple program for reading text file
    By johnpipes in forum What's Wrong With My Code?
    Replies: 5
    Last Post: December 21st, 2011, 05:55 PM
  2. Replies: 0
    Last Post: October 29th, 2011, 02:37 AM
  3. printing simple 3d text
    By cutie in forum Java Theory & Questions
    Replies: 3
    Last Post: September 1st, 2011, 07:31 AM
  4. Button Text into Label text
    By bluewhale in forum What's Wrong With My Code?
    Replies: 1
    Last Post: June 6th, 2011, 10:15 AM
  5. Text file to text area and Radiobuttons?
    By donaldmax in forum What's Wrong With My Code?
    Replies: 9
    Last Post: May 27th, 2011, 04:45 AM