Omar_Natour

Natour, O. 9/25/15 Csc-111-D01 Hw4

Sep 25th, 2015
145
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 2.45 KB | None | 0 0
  1. /*
  2.  * Omar Natour
  3.  * 9/25/2015
  4.  * CSC-111-D01
  5.  * Problem: Hw4
  6.  * Calculate temperature, dewpoint, or relative humidity.
  7.  */
  8.  
  9. import java.util.Scanner;
  10. import java.lang.Math;
  11.  
  12. public class WeatherCalc {
  13.     public static void main(String[] args) {
  14.         Scanner input = new Scanner(System.in);
  15.  
  16.         String ans;
  17.  
  18.         double temp;
  19.         double dew;
  20.         double relh;
  21.  
  22.         System.out.print("Would you like to calculate Temperature,"
  23.                 + " Dewpoint, or Relative Humidity? Enter your choice here:");
  24.         ans = input.nextLine();
  25.  
  26.         if (ans.equals("Temperature")) {
  27.             System.out.println("You have selected to calculate Temperature.");
  28.             System.out.print("Enter Dewpoint in fahrenheit:");
  29.             dew = input.nextDouble();
  30.             System.out.print("Enter Relative Humidity:");
  31.             relh = input.nextDouble();
  32.  
  33.             // calculation
  34.             dew = (dew - 32) / 1.8;
  35.             temp = 243.04 * (((17.625 * dew) / (243.04 + dew)) - Math.log((relh / 100)))
  36.                     / (17.625 + Math.log((relh / 100)) - ((17.625 * dew) / (243.04 + dew)));
  37.             temp = temp * 1.8 + 32;
  38.  
  39.             temp = Math.round(temp * 10.0) / 10.0;
  40.  
  41.             System.out.println("The temperature is " + temp + "\u00B0F.");
  42.  
  43.         } else if (ans.equals("Dewpoint")) {
  44.             System.out.println("You have selected to calculate Dewpoint.");
  45.             System.out.print("Enter Temperature in fahrenheit:");
  46.             temp = input.nextDouble();
  47.             System.out.print("Enter Relative Humidity:");
  48.             relh = input.nextDouble();
  49.  
  50.             // calculation
  51.             temp = (temp - 32) / 1.8;
  52.             dew = 243.04 * (Math.log((relh / 100)) + ((17.625 * temp) / (243.04 + temp)))
  53.                     / (17.625 - Math.log((relh / 100)) - ((17.625 * temp) / (243.04 + temp)));
  54.             dew = dew * 1.8 + 32;
  55.  
  56.             dew = Math.round(dew * 10.0) / 10.0;
  57.  
  58.             System.out.println("The Dewpoint is " + dew + "\u00b0F.");
  59.  
  60.         } else if (ans.equals("Relative Humidity")) {
  61.  
  62.             System.out.println("You have selected to calculate Relative Humidity.");
  63.             System.out.print("Enter Temperature in fahrenheit:");
  64.             temp = input.nextDouble();
  65.             System.out.print("Enter Dewpoint in fahrenheit:");
  66.             dew = input.nextDouble();
  67.  
  68.             // calculation
  69.             temp = (temp - 32) / 1.8;
  70.             dew = (dew - 32) / 1.8;
  71.  
  72.             relh = 100 * (Math.exp(((17.625 * dew) / (243.04 + dew))) / Math.exp(((17.625 * temp) / (243.04 + temp))));
  73.             relh = Math.round(relh * 10.0) / 10.0;
  74.  
  75.             System.out.println("The Relative Humidity is " + relh + "%.");
  76.  
  77.         } else
  78.             System.out.print("You have entered an invalid string.");
  79.  
  80.     }
  81.  
  82. }
Advertisement
Add Comment
Please, Sign In to add comment