Calculator.java 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198
  1. public class Calculator {
  2. // Luchtdruk in hPa
  3. // Malek&Tom
  4. public static double luchtdruk(short mval)
  5. {
  6. double luchtdruk = (mval / 1000f) * 33.86389;
  7. return luchtdruk;
  8. }
  9. // Temperatuur in graden Celcius
  10. // Malek&Tom
  11. public static double temperatuur(short mval)
  12. {
  13. double temperatuur = (((double)mval / 10) -32) / 1.8;
  14. return temperatuur;
  15. }
  16. // Relatieve luchtvochtigheid in %
  17. // Malek&Tom
  18. public static double luchtVochtigheid(short mval)
  19. {
  20. double luchtvochtigheid = mval;
  21. return luchtvochtigheid;
  22. }
  23. // Windsnelheid in m/s
  24. // Janco&Tim
  25. public static double windSnelheid(short mval)
  26. {
  27. double windSpeed = mval * 0.44704;
  28. return windSpeed;
  29. }
  30. // Windrichting in noord, oost, zuid en west.
  31. // Kenneth&Daniël
  32. public static String windRichting(short mval)
  33. {
  34. String direction = "Error";
  35. if(mval < 12)
  36. {
  37. direction = "N";
  38. }
  39. else if(mval < 34)
  40. {
  41. direction = "NNO";
  42. }
  43. else if(mval < 57)
  44. {
  45. direction = "NO";
  46. }
  47. else if(mval < 79)
  48. {
  49. direction = "ONO";
  50. }
  51. else if(mval < 102)
  52. {
  53. direction = "O";
  54. }
  55. else if(mval < 124)
  56. {
  57. direction = "OZO";
  58. }
  59. else if(mval < 147)
  60. {
  61. direction = "ZO";
  62. }
  63. else if(mval < 169)
  64. {
  65. direction = "ZZO";
  66. }
  67. else if(mval < 192)
  68. {
  69. direction = "Z";
  70. }
  71. else if(mval < 214)
  72. {
  73. direction = "ZZW";
  74. }
  75. else if(mval < 237)
  76. {
  77. direction = "ZW";
  78. }
  79. else if(mval < 259)
  80. {
  81. direction = "WZW";
  82. }
  83. else if(mval < 282)
  84. {
  85. direction = "W";
  86. }
  87. else if(mval < 304)
  88. {
  89. direction = "WNW";
  90. }
  91. else if(mval < 327)
  92. {
  93. direction = "NW";
  94. }
  95. else if(mval < 349)
  96. {
  97. direction = "NNW";
  98. }
  99. else if(mval < 360)
  100. {
  101. direction = "N";
  102. }
  103. return direction;
  104. }
  105. // Regenmeter in mm
  106. // Kenneth&Daniël
  107. public static double regenmeter(short mval)
  108. {
  109. double rainAmount = (double)mval*0.2;
  110. return rainAmount;
  111. }
  112. // uvIndex in index
  113. // Kenneth&Daniël
  114. public static double uvIndex(short mval)
  115. {
  116. double index = (double) mval/10;
  117. return index;
  118. }
  119. // BatterySpanning in Volt
  120. // Janco&Tim
  121. public static double batterySpanning(short mval){
  122. double voltage = (((double)mval * 300)/512)/100;
  123. return voltage;
  124. }
  125. // sunRise en Sunset in tijdformaat hh:mm
  126. // Janco&Tim
  127. public static String sunRise(short mval){
  128. return sun(mval);
  129. }
  130. public static String sunSet(short mval){
  131. return sun(mval);
  132. }
  133. private static String sun(short sunRaw){
  134. String tijd = "";
  135. for(int i = 0; i <= 3; i++){
  136. tijd = sunRaw % 10 + tijd;
  137. sunRaw /= 10;
  138. if(i == 1){
  139. tijd = ":" + tijd;
  140. }
  141. }
  142. return tijd;
  143. }
  144. public static double solarRad(short mval){
  145. double zonSterkte = mval;
  146. return zonSterkte;
  147. }
  148. //windchill in graden Celcius
  149. //Janco en Keneth
  150. public static double windChill(short grdnFh, short mph)
  151. {
  152. double gradenFahrenheit = grdnFh;
  153. double mijlPerUur = mph;
  154. double windChill2 = (35.74 + (0.6215*gradenFahrenheit) - 35.75*Math.pow(mijlPerUur, 0.16) + 0.4275*gradenFahrenheit*Math.pow(mijlPerUur, 0.16));
  155. short windChill = (short) windChill2;
  156. return temperatuur(windChill);
  157. }
  158. //Heatindex in celcius
  159. //Tom met Malek
  160. public static double heatIndex(double RH, double T)
  161. {
  162. double HI = -42.379 + 2.04901523*T + 10.14333127*RH - .22475541*T*RH - .00683783*T*T - .05481717*RH*RH + .00122874*T*T*RH + .00085282*T*RH*RH - .00000199*T*T*RH*RH;
  163. double heatindex = Calculator.temperatuur( (short) (HI*10) );
  164. return heatindex;
  165. }
  166. //Dauwpunt in Celcius
  167. //Daniel en Tim
  168. public static double dewPoint(double omgevingsTemp, short luchtVochtigheid)
  169. {
  170. double hm = luchtVochtigheid/100f;
  171. double dauwpunt = Math.pow( hm, (1/8f)) * (112 + 0.9*omgevingsTemp) + (0.1*omgevingsTemp) - 112;
  172. return dauwpunt;
  173. }
  174. public static double cloudHeight(double temp, short luchtVochtigheid ){
  175. double wolkhoogte = 125 * (temp-dewPoint(temp, luchtVochtigheid));
  176. return wolkhoogte;
  177. }
  178. }