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

Thread: Can someone help me out with this

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

    Default Can someone help me out with this

    Hey guys so I made this code for wind chill temp and Im stuck on one part.
    the part Im stuck on is that he wants a programs with dialog boxs and restriction

    "temp ranges -58 - 41 and wind speed greater than or equal to 2. He wants us to have in there that if the user types in an invalid number for both parts a box will pop up and say error.
    I have tried if and else statemnts but i get red line so can someone look over it and help me modify it please

    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);
     
            String Wind = JOptionPane.showInputDialog("What is the MPH of the wind ex: q.2.3.4.5.6 ect.");
            double WindSpeed = Double.parseDouble(Wind);
     
            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);
     
            System.out.println("The Wind-Chill Temperature is:" + Chill);
     
        }//end of main method
     
    }
    Last edited by costello20; October 5th, 2014 at 04:32 PM.

  2. #2
    Member
    Join Date
    Aug 2013
    Posts
    95
    Thanks
    3
    Thanked 14 Times in 14 Posts

    Default Re: Can someone help me out with this

    What do you mean a redline? Where are your if / else statements for error checking? You should be able to check if windSpeed is out of range or Temperature is out of range.

  3. #3
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,140
    Thanks
    65
    Thanked 2,720 Times in 2,670 Posts

    Default Re: Can someone help me out with this

    Please edit your post and wrap your code with code tags:
    [code=java]
    YOUR CODE GOES HERE
    [/code]
    to get highlighting and preserve formatting.
    If you don't understand my answer, don't ignore it, ask a question.

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

    Default Re: Can someone help me out with this

    Thanks for the info Norm

    so are you guys able to help
    I need to add in the where if the user punches in a number not in the guidelines then a box pops up saying "Error" or "invalid number"

  5. #5
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,140
    Thanks
    65
    Thanked 2,720 Times in 2,670 Posts

    Default Re: Can someone help me out with this

    I need to add...
    What problems are you having with that? Do you have any specific questions about what to do?
    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: Can someone help me out with this

    yes how do I add in a statement to or a line to where if the user inputs a temp like 85
    it will show a box that says Error or invalid number

  7. #7
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,140
    Thanks
    65
    Thanked 2,720 Times in 2,670 Posts

    Default Re: Can someone help me out with this

    Use an if statement to test for the bad value:
    if (bad data) {
    show a message
    }
    If you don't understand my answer, don't ignore it, ask a question.