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 11 of 11

Thread: Code doesn't work despite being from book

  1. #1
    Junior Member
    Join Date
    Jun 2013
    Posts
    6
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Default Code doesn't work despite being from book

    As a quick preface, I bought the book Teach yourself Java in 21 Days to, strangely enough, learn Java. Being a complete beginner who has no idea what I'm doing, I tried running the first example program that they gave me, and it didn't work. I reverted back the the Netbeans they used in the book but no luck..Here are the files

    class VolcanoRobot {
        String status;
        int speed;
        float temperature;
     
        void checkTemperature() {
            if (temperature > 660) {
                status = "returning home";
                speed = 5;
            }
        }
     
        void showAttributes() {
            System.out.println("Status: " + status);
            System.out.println("Speed: " + speed);
            System.out.println("Temperature: " + temperature);
        }
    }

    File 2

    class VolcanoApplication {
        public static void main(String[] arguments) {
            VolcanoRobot dante = new VolcanoRobot();
            dante.status = "exploring";
            dante.speed = 2;
            dante.temperature = 510;
     
            dante.showAttributes();
            System.out.println("Increasing speed to 3.");
            dante.speed = 3;
            dante.showAttributes();
            System.out.println("Changing temperature to 670.");
            dante.temperature = 670;
            dante.showAttributes();
            System.out.println("Checking the temperature.");
            dante.checkTemperature();
            dante.showAttributes();
        }
    }

    Thanks in advance


  2. #2
    Member
    Join Date
    May 2011
    Location
    west palm beach, FL
    Posts
    189
    My Mood
    Tired
    Thanks
    41
    Thanked 11 Times in 10 Posts

    Default Re: Code doesn't work despite being from book

    Does it give an error message or Something? what doesnt work?

  3. #3
    Junior Member
    Join Date
    Jun 2013
    Posts
    6
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Default Re: Code doesn't work despite being from book

    No, no error message. It just does absolutely nothing at all, despite the book saying that there was supposed to be an output.

  4. #4
    Junior Member
    Join Date
    Apr 2013
    Posts
    8
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: Code doesn't work despite being from book

    try using debugging mode and see where it doesnot print,the code seems prety fine

  5. #5
    Junior Member
    Join Date
    Jun 2013
    Posts
    6
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Default Re: Code doesn't work despite being from book

    Still does nothing in debug mode...

  6. #6
    Member
    Join Date
    May 2011
    Location
    west palm beach, FL
    Posts
    189
    My Mood
    Tired
    Thanks
    41
    Thanked 11 Times in 10 Posts

    Default Re: Code doesn't work despite being from book

    works for me this is what it output to the console

    Status: exploring
    Speed: 2
    Temperature: 510.0
    Increasing speed to 3.
    Status: exploring
    Speed: 3
    Temperature: 510.0
    Changing temperature to 670.
    Status: exploring
    Speed: 3
    Temperature: 670.0
    Checking the temperature.
    Status: returning home
    Speed: 5
    Temperature: 670.0

  7. #7
    Junior Member
    Join Date
    Jun 2013
    Posts
    6
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Default Re: Code doesn't work despite being from book

    Hmmm.....I'll have to do some reinstalling

  8. #8
    Member
    Join Date
    May 2011
    Location
    west palm beach, FL
    Posts
    189
    My Mood
    Tired
    Thanks
    41
    Thanked 11 Times in 10 Posts

    Default Re: Code doesn't work despite being from book

    what IDE are you using? eclipse? netbeans? if you can try to refresh the project and see if it works

  9. #9
    Junior Member
    Join Date
    Jun 2013
    Posts
    6
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Default Re: Code doesn't work despite being from book

    Quote Originally Posted by derekxec View Post
    what IDE are you using? eclipse? netbeans? if you can try to refresh the project and see if it works

    Netbeans....And it's too late I'm reinstalling

    --- Update ---

    This is all I get

    debug:
    BUILD SUCCESSFUL (total time: 0 seconds)

  10. #10
    Administrator copeg's Avatar
    Join Date
    Oct 2009
    Location
    US
    Posts
    5,318
    Thanks
    181
    Thanked 833 Times in 772 Posts
    Blog Entries
    5

    Default Re: Code doesn't work despite being from book

    Being a complete beginner who has no idea what I'm doing
    Quote Originally Posted by Math2 View Post
    Netbeans....And it's too late I'm reinstalling
    My advice: toss the IDE for the time being. Compile and run from the command line - you will learn a lot more of the nuts and bolts that are critical concepts that an IDE hides
    See: Lesson: The "Hello World!" Application (The Java™ Tutorials > Getting Started)

  11. The Following User Says Thank You to copeg For This Useful Post:

    Math2 (June 16th, 2013)

  12. #11
    Junior Member
    Join Date
    Jun 2013
    Posts
    6
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Default Re: Code doesn't work despite being from book

    Thanks, I'll try that

    --- Update ---

    No idea what I did, but it suddenly works in the IDE...And my command prompt says that javac is not recognized as an internal or external command....

    --- Update ---

    Sorry for another edit, but it seems that I have to do something with packages? I know you said the IDE isn't the best option, but when I added the package volcano into the IDE thing it seemed to like that, and didn't when I took it out....I don't know why I would need it however if they A) hadn't introduced it in the book, or B) used it in the source code

Similar Threads

  1. Replies: 7
    Last Post: May 8th, 2013, 02:33 PM
  2. actionListner code doesn't work ????
    By sciences in forum AWT / Java Swing
    Replies: 4
    Last Post: February 27th, 2012, 06:46 AM
  3. Code is working in Eclipse but when exported to Runnable Jar doesn't work
    By jjain.jitendra@gmail.com in forum What's Wrong With My Code?
    Replies: 1
    Last Post: August 24th, 2011, 07:12 AM
  4. File Reading code doesn't work
    By koryvandell in forum What's Wrong With My Code?
    Replies: 1
    Last Post: April 25th, 2011, 08:40 AM
  5. [SOLVED] "possible loss of precision", except not, code doesn't work, simple question
    By Perd1t1on in forum What's Wrong With My Code?
    Replies: 2
    Last Post: July 24th, 2010, 07:11 PM