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: Compute Wind Chill Assignment

  1. #1
    Junior Member
    Join Date
    Sep 2010
    Posts
    14
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Question Compute Wind Chill Assignment

    Not in a rush but trying to adjust my own code for an online class. I wrote this code following an example for computing interest but doesnt seem to like my double assignment. The problem is compute windchill using the formula below. It will only work if temp is between -58 and 41 degrees with the wind is above 2 mph.

    windchill =35.74 + (0.6215*outsideTemp) - (35.75*windspeed^0.16) + (0.4275*outsideTemp*windSpeed^0.16)

    original code that i made and ran through online compiler to find errors...

    import javax.swing.JOptionPane;
     
    public class ComputeWindChill {
    	public static void main(String[] args){
     
            //Enter outside temperature
    	String outsideTemp = JOptionPane.showInputDialog(
    		"Enter Outside Temperature in Farhrenheit. Must be above or equal to -58 degrees and below or equal to 41 degrees.");
     
    	//Convert outsideTemp String to a double
    	double outsideTemp =
    		Double.parseDouble(outsideTemp);
     
    	//Enter outside wind speed
    	String windSpeed = JOptionPane.showInputDialog(
    		"Enter Outside Wind Speed in Miles per Hour. Wind speed must be above or equal to 2 MPH.");
     
    	//Convert windSpeed String to a double
    	double windSpeed =
    		Double.parseDouble(windSpeed);
     
    	//Calculate windChill
    	double windChill = 35.74 + (0.6215 * outsideTemp) - (35.75 * (Math.pow(windSpeed,0.16))) + (0.4275 * (outsideTemp(Math.pow(windSpeed,0.16))));
     
    	//Format to keep the windChill to 2 digits after decimal
    	windChill = (int)(windChill*100)/100.0;
     
    	//Display results
    	String output = "The current outside wind-chill temperature is" + windChill;
    	JOptionPane.showMessageDialog(null, output);
    	}
    }

    I followed another example in the book and it did not work. I would like to know why it doesnt work since i am currently only in chapter 3. Thank you for the 5 minutes of your time. -JavaCow


  2. #2
    Member
    Join Date
    Jul 2010
    Location
    Washington, USA
    Posts
    307
    Thanks
    16
    Thanked 43 Times in 39 Posts

    Default Re: Compute Wind Chill Assignment

    Next time please surround your code in [highlight=java][/highlight] tags. Your problem is that you use different data types, and you use the same name. (outsideTemp was an int and a String) Here is the fixed code:

    import javax.swing.JOptionPane;
     
    public class computeWindChill {
    	public static void main(String[] args){
     
    		//Enter outside temperature
    		String outsideTemp = JOptionPane.showInputDialog(
    		"Enter Outside Temperature in Farhrenheit. Must be above or equal to -58 degrees and below or equal to 41 degrees.");
     
    		//Convert outsideTemp String to a double
    		double outsideTempDBL =
    			Double.parseDouble(outsideTemp);
     
    		//Enter outside wind speed
    		String windSpeed = JOptionPane.showInputDialog(
    		"Enter Outside Wind Speed in Miles per Hour. Wind speed must be above or equal to 2 MPH.");
     
    		//Convert windSpeed String to a double
    		double windSpeedDBL =
    			Double.parseDouble(windSpeed);
     
    		//Calculate windChill
    		double windChill = 35.74 + (0.6215 * outsideTempDBL) - (35.75 * (Math.pow(windSpeedDBL,0.16))) + (0.4275 * (outsideTempDBL*(Math.pow(windSpeedDBL,0.16))));
     
    		//Format to keep the windChill to 2 digits after decimal
    		windChill = (int)(windChill*100)/100.0;
     
    		//Display results
    		String output = "The current outside wind-chill temperature is: " + windChill;
    		JOptionPane.showMessageDialog(null, output);
    	}
    }

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

    JavaPF (September 14th, 2010)

  4. #3
    Junior Member
    Join Date
    Sep 2010
    Posts
    14
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: Compute Wind Chill Assignment

    I see the difference. What i need to do if i want to change or nest the parameters of the number is to change the name of the variable. Because it started as an int named outsideTemp it needs to be assigned another name to be identified as the double version. Thanks i will highlight next time.

  5. #4
    Member
    Join Date
    Jul 2010
    Location
    Washington, USA
    Posts
    307
    Thanks
    16
    Thanked 43 Times in 39 Posts

    Default Re: Compute Wind Chill Assignment

    Glad to hear you understood the problem. Happy programming!

  6. #5
    Junior Member
    Join Date
    Sep 2010
    Posts
    14
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Red face Re: Compute Wind Chill Assignment

    My professor stated in lecture that someone who was studying windchill would want as precise of a number as possible. I would assume that I can eliminate the following statement in my java code because all it does is round. Seeing that this actually takes place after the computation; there should be no issue with removing the statement. Is this a correct assumption?

    //Format to keep the windChill to 2 digits after decimal
            windChill = (int)(windChill*100)/100.0;

  7. #6
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    SW Missouri
    Posts
    20,376
    Thanks
    49
    Thanked 2,208 Times in 2,181 Posts

    Default Re: Compute Wind Chill Assignment

    Try it both ways and see which gives the desired results.

  8. #7
    Junior Member
    Join Date
    Sep 2010
    Posts
    14
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: Compute Wind Chill Assignment

    Yes I have tried both. It seemed to work just the same so I assumed there is no additional code needed when I removed the statement. Thanks all....

Similar Threads

  1. calculator GUI needs to compute
    By javanovice in forum AWT / Java Swing
    Replies: 3
    Last Post: May 4th, 2010, 02:16 PM
  2. need help on an assignment :(
    By gamfreak in forum What's Wrong With My Code?
    Replies: 6
    Last Post: February 23rd, 2010, 03:20 PM
  3. Replies: 1
    Last Post: February 22nd, 2010, 07:20 AM
  4. Compute the frequency count and big-oh notation for a certain code segment
    By maykel_trinidad in forum Java Theory & Questions
    Replies: 3
    Last Post: November 13th, 2009, 09:23 AM
  5. Replies: 6
    Last Post: October 23rd, 2009, 03:53 AM