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: Hey guys I can figure it out

  1. #1
    Junior Member
    Join Date
    Oct 2014
    Posts
    16
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Hey guys I can figure it out

    Hey guys so my teacher switched it up on me so now he want the input and output Dialog boxes. I got the Input but I cant figure out the output so if anyone could look it over and reformat it for me so it actually works that would be amazing (Im using Netbeans if that helps) and this is the error message it gives me "Exception in thread "main" java.lang.RuntimeException: Uncompilable source code - Erroneous tree type: <any>
    at Temperature.main(Temperature.java:28)

    import javax.swing.JOptionPane;
     
    public class Temperature {
     
        public static void main(String[] args) {
     
            String Temp = JOptionPane.showInputDialog("Enter outside Temperature in Farhrenheit. Temp should be between -58F and 41F");
            double Temperature = Double.parseDouble(Temp);
            if(Temperature > 41){
                System.out.println("Error: Invalid Temperature");
            }else if(Temperature < -58){
                System.out.println("Error: Invalid Temperature");
            }
     
            String Wind = JOptionPane.showInputDialog("What is the MPH of the wind ex: q.2.3.4.5.6 ect.");
            double WindSpeed = Double.parseDouble(Wind);
     
            if(WindSpeed < 2){
                System.out.println("WindSpeed is to Low");
            }
     
            double Chill = 35.74 + (0.6215 * Temperature) + (35.75 * (Math.pow(WindSpeed, 0.16))) + (0.4275 * (Temperature * (Math.pow(WindSpeed, 0.16))));
     
           Chill = (int) (Chill * 100 / 100.0);
     
     
           JOptionPane.showMessageDialog(null,output);
     
     
        }//end of main method
     
    }


  2. #2
    Senior Member PhHein's Avatar
    Join Date
    Mar 2013
    Location
    Germany
    Posts
    609
    My Mood
    Sleepy
    Thanks
    10
    Thanked 93 Times in 86 Posts

    Default Re: Hey guys I can figure it out

    You have never defined output. What are you trying to display?

  3. #3
    Junior Member
    Join Date
    Oct 2014
    Posts
    4
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: Hey guys I can figure it out

    At line 28: 'output' is not defined. It's supposed to be a String. Fill in:

    JOptionPane.showMessageDialog(null,""+ Chill +"");

    Also: Is this code being taught to you by your teacher? to be honest there's a lot wrong with it.

    You start primitive types with a Capital, which is usually reserved for classes.
    Also you're filling your main method with so much code, you're gonna have lots of trouble reading it, especially when you're code is gonna expand.
    Try making seperate methods, like:

    int calculateWindChill(short windSpeed, short temperature)
    {
    /* Return something
    }

    and then calling it out in your main method:

    calculateWindChill(windSpeed, temperature);
    Last edited by TheBeginning; October 6th, 2014 at 04:30 AM.

  4. #4
    Junior Member
    Join Date
    Oct 2014
    Posts
    16
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: Hey guys I can figure it out

    Im trying to get a dialog box to pop up and display the final calculation of everything

    --- Update ---

    For you top code you gave me and showed me what to change is that the correction and that what i should put in?

  5. #5
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    22,664
    Thanks
    53
    Thanked 2,420 Times in 2,373 Posts

    Default Re: Hey guys I can figure it out

    Your code should work if output was defined and had a value.
    If you don't understand my answer, don't ignore it, ask a question.

  6. #6
    Junior Member
    Join Date
    Oct 2014
    Posts
    16
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: Hey guys I can figure it out

    so since the error is showing for line 28

    would this be a fix for it and correct it all

    JOptionPane.showMessageDialog(null,""+ Chill +"");

  7. #7
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    22,664
    Thanks
    53
    Thanked 2,420 Times in 2,373 Posts

    Default Re: Hey guys I can figure it out

    would this be a fix for it
    Type it into the program, compile it and execute it to see.

    If there are error messages, copy the full text and paste it here.
    If you don't understand my answer, don't ignore it, ask a question.

  8. #8
    Junior Member
    Join Date
    Oct 2014
    Posts
    7
    Thanks
    1
    Thanked 1 Time in 1 Post

    Default Re: Hey guys I can figure it out

    You can't access a variable that does not exist. You have to declare the variable output or change it to "" + Chill + "", as TheBeginning said above:

    At line 28: 'output' is not defined. It's supposed to be a String. Fill in:

    JOptionPane.showMessageDialog(null,""+ Chill +"");
    If you are using an IDE (Integrated Development Environment) , you should get a red underline under output.
    If you are not using an ide, I suggest you to download any free one.
    Using an IDE will make debugging, testing, compiling, exporting, creating complex applications and write long files easier!
    My favourite IDE is Eclipse. It's free and you can download it from Eclipse's official website!
    Eclipse has great debugging tools, file managing system and is very customizable with built-in-, user created- and customizable themes, syntax highlighting and more.

    EDIT: Also, you have named your Temperature-variable with the same name as your class, and that might cause problems when you call it (It doesn't seem to do that for you, because the program executes until it gets to the last line of code (which means that it has passed the lines with the calls for the Temperature-variable)).

    /TheDDestroyer12
    Last edited by TheDDestroyer12; October 6th, 2014 at 10:39 AM.

Similar Threads

  1. hey guys
    By Chach_30 in forum Member Introductions
    Replies: 3
    Last Post: August 10th, 2014, 06:31 PM
  2. Hey Guys!
    By MikeeSevern in forum Member Introductions
    Replies: 3
    Last Post: May 8th, 2013, 05:49 PM
  3. Hey guys
    By Squishy in forum Member Introductions
    Replies: 2
    Last Post: December 19th, 2012, 01:42 PM
  4. hey guys....
    By prince joseph in forum Member Introductions
    Replies: 2
    Last Post: March 27th, 2010, 11:15 PM