## Homework J1## Due: Friday, 11 February 2005 by 10 a.m. |

For this homework, you will write a program that will compute the wind chill temperature. Given an ambient temperature (i.e. the temperature without the wind) and the wind speed (in miles per hour (mph)), the wind chill temperature is how cold the wind feel like to human skin. For example, given a temperature of 19° Fahrenheit and a wind of 11 mph, the wind chill temperature makes it feel like 7° Fahrenheit (-14° Celsius).

The program will have the following steps

- Define the constants, if you are using any
- Print out an appropriate legend (see below)
- Set up the input stream
- Ask the user for the ambient temperature (in Fahrenheit)
- Ask the user for the wind velocity (in mph)
- Compute the wind chill temperature in degrees Fahrenheit
- Convert the wind chill temperature to degrees Celsius (NOTE: you are converting the temperature from the previous step, not computing it again)
- Print out the wind chill in Fahrenheit
- Print out the wind chill in Celsius

These formulae are needed for this assignment. The formula for the wind chill temperature, obtained from here, is:

*windchill* = 35.74 + 0.6215**t* - 35.75**v*^{0.16} + 0.4275**t***v*^{0.16}

Where *windchill* is the wind chill temperature,* t *is the ambient temperature
(in Fahrenheit) and *v* is the wind speed (in mph). To compute an
exponent in Java, use the `Math.pow()` method. For example, if the wind speed was
stored in a double variable `v`, then `Math.pow(v,0.16)` would compute *v*^{0.16}.

To convert a temperature in Fahrenheit to a temperature in Celsius, the formula is:

*c* = 5 * (*f* - 32) / 9

Where *c* is the temperature in Celsius, and *f* is the temperature in
Fahrenheit.

All values should be printed out rounded to the nearest integer. This
can be done by calling the `Math.round()` method. For example,
consider the following code:

double d = 3.6; int a = (int) Math.round(d); int b = (int) Math.round(-d); System.out.println (a + ", " + b);

This will print out `4, -4`. Thus, it will be easiest to compute
the temperatures as doubles, then round them to the nearest integer. Note that `Math.round()`
returns a `long`, and you need to cast it to an `int`, as
done above. Also note that negative numbers are rounded away from zero, so
that -3.6 is rounded to -4, not to -3.

We have provided a WindChill.java file for you to start with. Changing the class name will cause a loss of lots of points.

Look at the code for BMICalculator.java (page 75 of the textbook, and
available online
here) for an idea
how to start, as that program is somewhat similar to the one that must be
written for this homework. The 8 parts of the `main()` method for
BMICalculator.java (each part is separated by a blank line in the textbook) will
be replaced by the 9 parts (mentioned above) for WindChill.java.

The following are considered good programming practices. * All homeworks
and lab quizzes must include these whenever possible.* Not including them
will receive points off from the grade. Note that the BMICalculator.java
program (on page 75 of the textbook) is an example of a program that follows all
these practices.

- Header: The comments at the beginning of the file, and need to include
your name, e-mail ID, 101 section (or 101-E, if appropriate), and a line or
two about what this program does.

- Comments: A line or two before each major "block" (section of code,
class, method, variable, etc.) describing what it does.

- Whitespace: A line or two between separate elements of the code
(methods, code segments, etc.) and good indentation.

- Legend: The program should print out a line or two that states what the
purpose of the program is (i.e. "This is a BMI calculator", or "This program
computes the wind chill temperature"). This should be the first line(s) printed.

- Echoing input: All user input should be echoed back to the screen. This
can be a line saying "you entered 5" after the user enters the input, but
can also be a line saying, "The product of the two numbers you entered, 5
and 7, is 35".

- Variable names: All final variables should be in all caps with
underscores between the words, such as BOX_WIDTH. Non-final variable names should have the firstLetterOfEachWordCaptilized
in the variable name (excepting the very first letter). Variable names
should be relevant and informative, such as temperature and not t.

- Line length: The lines should not go over about 72 characters. Essentially, when displayed on an 80-character wide screen (what we are using), the line should not wrap to the next line. You can have a println statement, for example, use multiple lines (as long as each string starts and ends on the same line). JCreator has a vertical grey line around the 70th column, so you can use that to gauge how long your lines are.

The following is a sample execution run of the WindChill program. The red text is the input that the user entered.

This program will compute the wind chill temperature What is the temperature in Fahrenheit? 19 What is the wind speed in mph? 11 You entered a ambient temperature of 19.0 degrees Fahrenheit and a wind speed of 11.0 mph The wind chill temperature is 7 degrees Fahrenheit The wind chill temperature is -14 degrees Celsius

Note that a temperature of -13 is also acceptable (depending on how you do your rounding, you may end up with either).

The following is the criteria that the graders will be looking at when the homework is graded. Note that these criteria will not be provided on the other homeworks, only on this first one. Also, the points for each of the following criteria have not yet been determined.

- Program header (includes name, e-mail ID, and purpose)
- Good commenting and use of whitespace
- Print out an appropriate legend
- Proper use of Scanner for the input stream
- Properly prompts user for temperature and wind velocity
- Input is echoed to the screen
- Properly computes the wind chill temperature in degrees Fahrenheit
- Properly converts the wind chill temperature to degrees Celsius
- Prints out the wind chill in Fahrenheit (in integer format)
- Prints out the wind chill in Celsius (in integer format)
- Variable declaration (good names, proper initialization, etc.)

If your program does not compile, you will receive 25 points off!

When you are finished, submit the WindChill.java file.