Calculator.java 4.7 KB

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