Question

As every resident of Alaska knows, the real enemy in terms of the weather is not...

As every resident of Alaska knows, the real enemy in terms of the weather is not the near-zero temperatures, but the wind-chill factor. Meteorologists in Alaska and in many other states give both the temperature and the wind-chill factor. So important is the wind-chill factor that claim air at -40 Fahrenheit is less likely to cause frostbite than air just below freezing that is blowing at gale force. Basically, two factors determine the wind-chill factor: the velocity of wind and the temperature.

a. Design an interactive program that accepts from the user a temperature between -20F and 15F and a wind velocity between 5 mph and 30 mph, both in multiples of five. The program should look up the wind-chill factor in a positional organized table and display it. Draw the flowchart or write the pseudocode for this program. Use the following table of wind-chill factors:

Temperature

In Fahrenheit

Wind Velocity in Miles per Hour

5

10

15

20

25

30

-20

-26

-46

-58

-67

-74

-79

-15

-21

-40

-51

-60

-66

-71

-10

-15

-34

-45

-53

-59

-64

-5

-10

-27

-38

-46

-51

-56

0

-5

-22

-31

-39

-44

-49

5

0

-15

-25

-31

-36

-41

10

7

-9

-18

-24

-29

-33

15

12

-3

-11

-17

-22

-25

b. Create code in Java for the same problem. Demonstrate your Java program at run time by capturing runtime screen shots.

c. Use the following sample data to test your program:

Temperature (F)

Wind Velocity (mph)

-15

10

5

30

-5

40

-40

25

15

10

0 0
Add a comment Improve this question Transcribed image text
Answer #1

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

PSEUDOCODE

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

1. Define constant 1D integer array TEMP_F with 8 values from -20 to 15, in multiples of 5.

2. Define constant 1D integer array WIND_VEL_MPH with 6 values from 5 to 30, in multiples of 5.

3. Populate 8X6 integer array WIND_CHILL_FACTOR based on values provided.

4. In validateRange method with 3 arguments value, lowerRange, upperRange:

4.1 return True: if value >= lowerRange && value <= upperRange

4.2 return false otherwise

5. In isMultipleOf method with 2 arguments value, multipleOf:

5.1 return true if value % multipleOf is equal to 0.

5.2 return false otherwise.

6. In getIndex method with 2 arguments value ,theArr:

6.1 For index 0 to last index of theArr, check if value is the same as the value in that index

6.2 if value matched break out of for loop

6.3 return the index if value is found, otherwise return -1

7. In main method:

7.1 Read temp from user

7.2 Read windVelocity from user.

7.3 SET validationError as empty string

7.3 IF validateRange(temp,-20,15) is not TRUE , concatenate error message to validationError

7.4 IF isMultipleOf(temp,5) is not TRUE, concatenate error message to validationError

7.5 IF validateRange(windVelocity,5,30) is not TRUE , concatenate error message to validationError

7.6 IF  isMultipleOf(windVelocity,5) is not TRUE, concatenate error message to validationError

7.7 IF validationError is NOT Empty: Print Validation error message and terminate the program

7.8 Get indexOfTemp , by calling getIndex(temp,TEMP_F)

7.9 Get indexOfWindVelocity , by calling getIndex(windVelocity,WIND_VEL_MPH)

7.10 Get windChillFactor by referencing WIND_CHILL_FACTOR[indexOfTemp][indexOfWindVelocity]

7.11 Print windChillFactor

8. End of Program

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

JAVA PROGRAM

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

import java.util.Scanner;

//class: WindChillFactor
public class WindChillFactor {
  
   //static constants: TEMP_F, WIND_VEL_MPH, WIND_CHILL_FACTOR
  
   //temperature in Farenheit from -20 to 15 (in multiple of 5)
   private static final int[] TEMP_F = {-20,-15,-10,-5,0,5,10,15};
   //wind velocity in mph from 5 to 30 (in multiple of 5)
   private static final int[] WIND_VEL_MPH ={5,10,15,20,25,30};
   //wind chill factor in 8X6 array, with 8 temperatures and 6 wind velocities
   private static int[][] WIND_CHILL_FACTOR = {{-26,-46,-58,-67,-74,-79},
                                               {-21,-40,-51,-60,-66,-71},
                                               {-15,-34,-45,-53,-59,-64},
                                               {-10,-27,-38,-46,-51,-56},
                                               {-5,-22,-31,-39,-44,-49},
                                               {0,-15,-25,-31,-36,-41},
                                               {7,-9,-18,-24,-29,-33},
                                               {12,-3,-11,-17,-22,-25}};
  
   //main method
   public static void main(String[] args){
       //scanner to read input
       Scanner input = new Scanner(System.in);
      
       System.out.println("Enter temperature between -20F and 15F, in multiple of 5: ");
       int temp = input.nextInt();//read temp
       System.out.println("Enter wind velocity between 5 mph and 30 mph, in multiple of 5: ");
       int windVelocity = input.nextInt();//read wind velocity
      
       //the String validation error will hold
       //any validation error message for inputs
       String validationError = "";
      
       //validate temp
       //check if temp is between -20 and 15 mph
       if(!validateRange(temp,-20,15))
           validationError += "\n- Temperature "+temp+" is not between -20F and 15F.";
       //check if wind temp is multiple of 5
       if(!isMultipleOf(temp,5))
           validationError += "\n- Temperature "+temp+" is not multiple of 5.";
      
       //validate windVelocity
       //check if windVelocity is between 5 and 30 mph
       if(!validateRange(windVelocity,5,30))
           validationError += "\n- Wind Velocity "+windVelocity+" is not between 5mph and 30mph.";
       //check if wind velocity is multiple of 5
       if(!isMultipleOf(temp,5))
           validationError += "\n- Wind Velocity "+windVelocity+" is not multiple of 5.";
      
       //if validationError is not empty
       if(!validationError.isEmpty()){
           //print validation error message and return
           System.out.println("Validation Error:"+validationError);
           return;
       }
      
       //get index of temp from TEMP_F array
       int indexOfTemp = getIndex(temp,TEMP_F);
       //get index of windVelocity from WIND_VEL_MPH array
       int indexOfWindVelocity = getIndex(windVelocity,WIND_VEL_MPH);
      
       //based on the above 2 indexes, calculate windChillFactor
       //by referencing WIND_CHILL_FACTOR 2D array
       int windChillFactor = WIND_CHILL_FACTOR[indexOfTemp][indexOfWindVelocity];
      
       //print windChillFactor
       System.out.println("Wind Chill Factor at temperature = "+ temp + "F and Wind Velocity = "+
                   windVelocity+"mph is: "+ windChillFactor);
      
   }
  
   /**
   * Validates if value is within lowerRange and upperRange, both inclusive
   * @param value
   * @param lowerRange
   * @param upperRange
   * @return
   */
   private static boolean validateRange(int value,final int lowerRange,final int upperRange){
       return (value >= lowerRange && value <= upperRange);
   }
  
   /**
   * Checks if value is multiple of the given multipleOf
   * @param value
   * @param multipleOf
   * @return
   */
   private static boolean isMultipleOf(int value,final int multipleOf){
       return (value%multipleOf == 0);
   }
  
   /**
   * gets the index of given value
   * from the int array theArr
   * @param value
   * @param theArr
   * @return
   */
   private static int getIndex(int value, final int[] theArr){
       int index = -1;
       for(int i = 0; i < theArr.length; i++){
           if(value == theArr[i]){//if value is matched
               index = i;//set index with i
               break;
           }
       }
       return index;//return
   }
          
}

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

OUTPUT

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

RUN1

RUN2

RUN3

RUN4

RUN5

RUN6

Add a comment
Know the answer?
Add Answer to:
As every resident of Alaska knows, the real enemy in terms of the weather is not...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • Wind Chill 50 45 40 35 30 Wind Speed (km/h) 25 20 15 10 5 0...

    Wind Chill 50 45 40 35 30 Wind Speed (km/h) 25 20 15 10 5 0 in -10 -15 -20 35 40 -45 -50 Air Temperature (°C) Task: The wind chill index measures the sensation of cold on the human skin. In October 2001, Environment Canada introduced the wind chill index above. Each curve represents the combination of air temperature and wind speed that would produce the given wind chill value. For example, a temperature of -25°C and wind speed...

  • Need to use Python string formatting to align wind-chill values in equal-sized columns Using your knowledge...

    Need to use Python string formatting to align wind-chill values in equal-sized columns Using your knowledge of loops and other Python features covered so far, write a program that prints a table of windchill values, where: Rows represent wind speed for O to 50 in 5 mph increments Columns represent temperatures from -20 to +60 in 10-degree increments Your program should include a function that returns windchill for a given combination of wind speed & temperature, using this formula from...

  • Lesson If you have been outside on a cold windy day, you have experien emperature that...

    Lesson If you have been outside on a cold windy day, you have experien emperature that our bodies feel when the wind blows on our skin on a com wind chill, the temperature seems to our bod dangerous. Meteorologists predict the temp outside. For example, people need to know the displays wind chills for various windsds when the outside temperature is 15 ve experienced wind chill Windchill is the our skin on a cold day. When we experience to our...

  • study guide help its three pages 2. The following table given the temperature T in degrees...

    study guide help its three pages 2. The following table given the temperature T in degrees Fahrenheit for a certain after t minutes of cooling in a room. cup of coffee 1 T =minutes 0 10 20 30 40 50 = temperature 115 95 85 77 72 72 a) Write in functional notation the temperature of the cup of coffee after 30 minutes. b) Find the average rate of change of the temperature of the cup of coffee during the...

  • Пт, v where w is the win ch index, Tís he adual temperature, and y s the wind speed. A numerical ...

    for select part, options are: (Increase, Decrease) Пт, v where w is the win ch index, Tís he adual temperature, and y s the wind speed. A numerical is given in this In this example we considered the function l table. (a) What is the value of f-15, 70)? What is its meaning? f(f-15, 70) which means that if the temperature is -15°C and the wind speed is 70 km/h, then the air would feel equivalent to approximately oC without...

  • In this assignment you will be implementing a weather forecaster. It involves writing 3 different classes...

    In this assignment you will be implementing a weather forecaster. It involves writing 3 different classes plus a driver program. It is recommended that you write one class at a time and then write a driver (tester) program to ensure that it works before putting everything together. Alternately, you can use the Interactions tab of JGRASP to test some of the early classes. This is discussed in the next few pages. The Season Class The first, shortest, and easiest class...

  • (use filename system: lastname_tempdata_firstinitial.m) 1. Gilat Chapter 6 Chapter7 #6. Use a single M-file and use...

    (use filename system: lastname_tempdata_firstinitial.m) 1. Gilat Chapter 6 Chapter7 #6. Use a single M-file and use mnemonic variable names of 3 characters or more for the variables to complete the problem. This is a comparison problem. If, selection, statements are not required but may be used. Loops are not required but may be used. Do not add any user defined M-files for this problem. Use fprintf statements to show the answer to each scenario: a), b), c), d), e) Investigate...

  • I know how to do number one just not number 2. Please answer number 2 only...

    I know how to do number one just not number 2. Please answer number 2 only Write a java program that will print out following pattern. Use nested for loop. 2. Add a method to the above program that generates takes two numbers as parameters and prints out all the numbers from number 1 to number 2 separated by using a while loop. (Do not print the last ,'). For example: Calling method1(9,51) should print: 9, 10, 11, 12, 13,...

  • Programming Exercise 8.3 | Instructions Write a GUI-based program that allows the user to convert temperature...

    Programming Exercise 8.3 | Instructions Write a GUI-based program that allows the user to convert temperature values between degrees Fahrenheit and degrees Celsius. The interface should have labeled entry fields for these two values. breezypythongui.py temperatureconvert... + 1 2 File: temperatureconverter.py 3 Project 8.3 4 Temperature conversion between Fahrenheit and Celsius. 5 Illustrates the use of numeric data fields. 6 • These components should be arranged in a grid where the labels occupy the first row and the corresponding fields...

  • Project 1 Due Date Problem Knight's Tour: The Knights Tour is a mathematical problem involving a...

    Project 1 Due Date Problem Knight's Tour: The Knights Tour is a mathematical problem involving a knight on a chessboard. The knight is placed on the empty board and, moving acording to the rules of chess, must visit each square once. 06-JUN-2018 There are several billion solutions to the problem, of which about 122,000,000 have the knight finishing on the same square on which it begins. When this occurs the tour is said to be closed. Your assignment is to...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT