Question

In: Computer Science

How cold is it outside? The temperature alone is not enough to provide the answer. Other...

How cold is it outside? The temperature alone is not enough to provide the answer. Other factors including wind speed, relative humidity, and sunshine play important roles in determining coldness outside. In 2001, the National Weather Service (NWS) implemented the new wind-chill temperature to measure the coldness using temperature and wind speed. The formula is:

twc = 35.74 + 0.6215ta - 35.75v0.16 + 0.4275tav0.16

t w c = 3.74 + 0.6215 t a − 35.75 v 0.16 + 0.4275 t a v 0.16

where ta is the outside temperature measured in degrees Fahrenheit, v is the speed measured in miles per hour, and twc is the wind-chill temperature. The formula cannot be used for wind speeds below 2mph or temperatures below -58°F or above 41°F.

Write a program that prompts the user to enter a temperature between -58°F and 41°F and a wind speed greater than or equal to 2 then displays the wind-chill temperature. Use Math.pow(a, b) to compute v0.16. Your class must be named Windchill. Here is a sample run:

Enter a temperature between -58°F and 41°F: 5.3
Enter the wind speed (>= 2) in miles per hour: 6
The wind chill index is -5.567068455881625

This is what I made:

import java.util.Scanner;
public class Windchill
{
public static void main(String[]args)
{
//create Scanner
Scanner s=new Scanner(System.in);
double ta= 5.3;
int v= 6;
double v2= Math.pow(v,.16);
double Windchill= 35.74 + 0.6215 * ta-35.75 * v2+0.4275 * ta * v2;
//get temperature in Fahrenheit
System.out.println("Enter a temperature between -58°F and 41°F:" +" "+ ta);
//get wind speed
System.out.println("Enter the wind speed (>= 2) in miles per hour"+" "+ v);
//get windchill index
System.out.println("The windchill index is"+" "+ Windchill);
}
}

My teacher told me: "your program needs to let the user enter the temperature and wind speed at the keyboard."

How do I fix this? please help.

Solutions

Expert Solution

Please find the updated java program below:

////////////////////Windchill.java////////////////////

import java.util.Scanner;
/**
* Class: Windchill
*   1.    Instead of taking direct values for variables ta and v,
*   scanner instance(s) is used to read double and int value from user console.
*   2. An if condition is introduced to check if the formula can be used or not i.e to print a message
*   if value of v is less than 2 or ta is less than -58 or greater than 41
*/
public class Windchill
{
   public static void main(String[]args)
   {
       //create Scanner
       Scanner s=new Scanner(System.in);
      
       //get temperature in Fahrenheit
       System.out.println("Enter a temperature between -58°F and 41°F:");
       double ta = s.nextDouble();//read the double value from console
      
       //get wind speed
       System.out.println("Enter the wind speed (>= 2) in miles per hour:");
       int v = s.nextInt(); //read the integer value from console
      
       s.close(); //close the scanner as all user inputs are taken
      
       if(v < 2 || ta < -58 || ta > 41){//check if the formula can be used
           System.out.println("The windchill index cannot be measured for wind speeds "
                   + "below 2mph or temperatures below -58°F or above 41°F.");
       }else{
           double v2= Math.pow(v,0.16);//get v0.16  
           //using the formula
           double windchill= 35.74 + 0.6215 * ta -35.75 * v2 + 0.4275 * ta * v2;      
           //print windchill index
           System.out.println("The windchill index is"+" "+ windchill);
       }
   }
}

============================================

OUTPUT

===========================================

RUN1

Enter a temperature between -58°F and 41°F:
5.3
Enter the wind speed (>= 2) in miles per hour:
6
The windchill index is -5.567068455881625

RUN2

Enter a temperature between -58°F and 41°F:
-60
Enter the wind speed (>= 2) in miles per hour:
5
The windchill index cannot be measured for wind speeds below 2mph or temperatures below -58°F or above 41°F.


Related Solutions

How does pollens and cold temperature contribute to the pathophysiology os asthma? Briefly explain.
How does pollens and cold temperature contribute to the pathophysiology os asthma? Briefly explain.
If the temperature inside a room is 25°C and the temperature outside is ?10°C: a. What...
If the temperature inside a room is 25°C and the temperature outside is ?10°C: a. What is the maximum relative humidity that can be accommodated inside the room before the window fogs over? (Assume the inside of the window is not insulated from the outside temperature). b. If it is a double-pane window such that the inside of the window is perfectly insulated from the outside, what will the maximum relative humidity be?
1. A balloon is floating around outside your window. The temperature outside is -15 ∘C ,...
1. A balloon is floating around outside your window. The temperature outside is -15 ∘C , and the air pressure is 0.800 atm . Your neighbor, who released the balloon, tells you that he filled it with 4.00 moles of gas. What is the volume of gas inside this balloon? Express your answer to three significant figures and include the appropriate units. Vballoon = 2. A 18.0 L gas cylinder is filled with 9.80 moles of gas. The tank is...
PART A A balloon is floating around outside your window. The temperature outside is -19 ∘C...
PART A A balloon is floating around outside your window. The temperature outside is -19 ∘C , and the air pressure is 0.700 atm . Your neighbor, who released the balloon, tells you that he filled it with 3.00 moles of gas. What is the volume of gas inside this balloon? Express your answer to three significant figures and include the appropriate units. PART B A 20.0 L gas cylinder is filled with 7.20 moles of gas. The tank is...
Part A A balloon is floating around outside your window. The temperature outside is 33 ∘C...
Part A A balloon is floating around outside your window. The temperature outside is 33 ∘C , and the air pressure is 0.800 atm . Your neighbor, who released the balloon, tells you that he filled it with 3.90 moles of gas. What is the volume of gas inside this balloon? Express your answer to three significant figures and include the appropriate units. Part B A 20.0 L gas cylinder is filled with 6.60 moles of gas. The tank is...
Research and provide an example of how race is socially constructed in a culture outside of...
Research and provide an example of how race is socially constructed in a culture outside of the United States.  
A) Suppose you dump a bucket of water (5.00kg at 15.0C) outside on a cold night...
A) Suppose you dump a bucket of water (5.00kg at 15.0C) outside on a cold night where T = -10.0C, and the water spreads out over an area so large that the temperature of the ground remains at -10.0C, acting like an ideal “cold reservoir.” Calculate the entropy change of the water in going from 15.0C to -10.0C, and calculate the entropy change of the environment, absorbing heat while staying (approximately) at -10.0C. This problem requires you to use TWO...
assuming that linear heat rate, fuel outside temperature and outside diameter for a solid fuel pellet...
assuming that linear heat rate, fuel outside temperature and outside diameter for a solid fuel pellet and an annular fuel pellet are the same, how does the maximum temperature compare between the two pellet? Why? assuming that linear heat rate, fuel outside temperature and outside diameter for a solid fuel pellet and an annular fuel pellet are the same, how does the maximum temperature compare between the two pellet? Why?
A composite series wall has an inside surface temperature of 1600F and outside surface temperature of...
A composite series wall has an inside surface temperature of 1600F and outside surface temperature of 500F. If it consists of 3.5 in. of mineral wool, 0.05 in. of plaster on the outside, and 0.75 in. of cork board on the inside, determine the heat loss in a 120 square foot of wall.
Suppose outside temperature is 55◦F, while the temperature inside a building is 72◦F. The building is...
Suppose outside temperature is 55◦F, while the temperature inside a building is 72◦F. The building is heated but not air conditioned, so the partial pressure of water vapor is the same both inside and outside the building. Finally, suppose the dew point outside is 40◦F. What is the dew point inside? What are the relative humidities inside and outside the building? (We are most comfortable if relative humidity is between 30% and 50%. This question shows why air in heated...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT