#1
  1. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jun 2013
    Posts
    5
    Rep Power
    0

    Beginners Program from Book doesn't work...


    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

    Code:
    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

    Code:
    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
  3. Contributing User
    Devshed Expert (3500 - 3999 posts)

    Join Date
    Aug 2010
    Location
    Eastern Florida
    Posts
    3,711
    Rep Power
    348
    it didn't work.
    Can you explain what "didn't work" means?
    If there are errors, copy the full text and paste it here.
    If the output is wrong, copy it here and explain what is wrong with it.
  4. #3
  5. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jun 2013
    Posts
    5
    Rep Power
    0
    There was nothing at all as an output
  6. #4
  7. Contributing User
    Devshed Expert (3500 - 3999 posts)

    Join Date
    Aug 2010
    Location
    Eastern Florida
    Posts
    3,711
    Rep Power
    348
    Please copy the contents of the console from when you execute it using the java command to show what it does when it is executed.
  8. #5
  9. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jun 2013
    Posts
    5
    Rep Power
    0
    This is all I get

    Code:
    debug:
    BUILD SUCCESSFUL (total time: 0 seconds)
  10. #6
  11. Contributing User
    Devshed Expert (3500 - 3999 posts)

    Join Date
    Aug 2010
    Location
    Eastern Florida
    Posts
    3,711
    Rep Power
    348
    That looks like a message from an IDE. I have no idea how to make your IDE execute the program.

    Try using the java command in a command prompt window:
    java VolcanoApplication

    The window will have to be open in the folder containing the
    VolcanoApplication.class file.
  12. #7
  13. Contributing User
    Devshed Expert (3500 - 3999 posts)

    Join Date
    Aug 2010
    Location
    Eastern Florida
    Posts
    3,711
    Rep Power
    348
    Have you gotten the "HelloWorld" program to compile, execute and print out its message?
    See this http://docs.oracle.com/javase/tutori.../netbeans.html
  14. #8
  15. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jun 2013
    Posts
    5
    Rep Power
    0
    I have
  16. #9
  17. Contributing User
    Devshed Expert (3500 - 3999 posts)

    Join Date
    Aug 2010
    Location
    Eastern Florida
    Posts
    3,711
    Rep Power
    348
    If your HelloWorld program worked, then use the same technique to execute this program.
  18. #10
  19. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jun 2013
    Posts
    5
    Rep Power
    0
    No idea what I did, but it suddenly works in the IDE...
  20. #11
  21. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jun 2013
    Posts
    7
    Rep Power
    0
    i suggest for u eclipse,

    and dont stack on that book that focus on netbeans, u should search on the net for the different way to compile ur code
    Last edited by Winters; June 24th, 2013 at 08:58 AM. Reason: Removed fake sig

IMN logo majestic logo threadwatch logo seochat tools logo