1   package org.wcb.e6b;
2   
3   
4   /**
5    * Created by IntelliJ IDEA.
6    * User: wbogaardt
7    * Date: Aug 23, 2005
8    * Time: 6:08:07 PM
9    * To change this template use File | Settings | File Templates.
10   */
11  
12  public class PressureAltitude extends AbstractE6B {
13  
14      private double altitude;
15      private double hg;
16      private long pAlt;
17      private static final double STANDARD_PRESSURE_MB = 1013.250556514;
18  
19      /**
20       * The current altitude setting.
21       * @return altitude in feet
22       */
23      public double getAltitude() {
24          return altitude;
25      }
26  
27      /**
28       * The current altitude current in feet.
29       * @param alt feet
30       */
31      public void setAltitude(double alt) {
32          this.altitude = alt;
33      }
34  
35      /**
36       * Pressure in hg value such as 29.92.
37       * @return  Pressure in hg
38       */
39      public double getHg() {
40          return hg;
41      }
42  
43      /**
44       * Set the inches of mercury which standard is 29.92.
45       * @param inchMercury mercury hg value
46       */
47      public void setHg(double inchMercury) {
48          this.hg = inchMercury;
49      }
50  
51      /**
52       * Calls and calculates the entered information.
53       * pressureAltitude is the result.
54       */
55      public void calculate() {
56          double altSet = E6bConverter.hgToMillibars(hg); //convert to millibars
57          double altpress;
58          altpress = (1 - Math.pow((altSet / STANDARD_PRESSURE_MB), 0.190284)) * 145366.45;
59          pAlt = roundSet(altitude + altpress);
60      }
61  
62      /**
63       * The pressure altitude in feet.
64       * @return the current pressure altitude result after calculate call.
65       */
66      public long presureAlitude() {
67          return pAlt;
68      }
69  
70      /**
71       * rounding the value out from a double.
72       * @param value rounded value.
73       * @return the value rounded to 10s
74       */
75      public long roundSet(double value) {
76          return Math.round(10 * value) / 10;
77      }
78  
79  }