brilliant_moves

WindChillTable.java

Mar 25th, 2015
722
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 5 1.22 KB | None | 0 0
  1. public class WindChillTable {
  2.  
  3.     public static void drawHorizontalLine() {
  4.         for (int i=0; i<49; i++) {
  5.             System.out.print("-");
  6.         } // for
  7.         System.out.println(); // new line
  8.     } // drawHorizontalLine()
  9.  
  10.     public static int getWindChill(int t, int ws) {
  11.         double wc;
  12.         wc = 91.4 - (0.474677 - 0.020425 * ws + 0.303107 * Math.sqrt(ws)) * (91.4 - t);
  13.         return (int) wc;
  14.     } // getWindChill()
  15.  
  16.     public static void main(String[] args) {
  17.         System.out.println ("Temperature (degrees F)");
  18.         drawHorizontalLine();
  19.         System.out.print("      "); // 6 spaces for alignment
  20.         for (int temp=50; temp>=-50; temp-=10) {
  21.             System.out.printf("%4d",temp);
  22.         } // for
  23.         System.out.println(); // new line
  24.         drawHorizontalLine();
  25.         System.out.println("WS Equivalent Temperature (degrees F)");
  26.         System.out.println("MPH (Equivalent in cooling power on exposed flesh under calm conditions)");
  27.         drawHorizontalLine();
  28.  
  29.         for (int windSpeed=5; windSpeed<=50; windSpeed+=5) {
  30.             System.out.printf("%3d | ",windSpeed);
  31.             for (int temp=50; temp>=-50; temp-=10) {
  32.                 System.out.printf("%4d", getWindChill(temp, windSpeed));
  33.             } // for t
  34.             System.out.println(); // new line
  35.         } // for windSpeed
  36.     } // main()
  37.  
  38. } // class WindChillTable
Advertisement
Add Comment
Please, Sign In to add comment