dcsimg
CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 4 of 4

Thread: Code compiles but unable to find error fouling calculation - Java Version 1.8.0_91

  1. #1
    Join Date
    Sep 2016
    Posts
    2

    Code compiles but unable to find error fouling calculation - Java Version 1.8.0_91

    I can't get the totalLift() or wingLoading() methods to calculate properly for some reason. I have no compiler errors and have retraced my logic to no avail. Any direction on getting those two items to function would be greatly appreciated. NOTE: I'm new to programming and I understand my deployment of XYZ may not be as elegant as what can be achieved, I'm primarily interested in the methods I mentioned.

    Please let me know if you have any questions. Developed on jGrasp 2.0.2_01

    Below is the subject code. TesterAttachment 34463 output attached.

    Code:
    import java.util.Scanner; 
     
    /** Wing Class to calculate the Dynamic Pressure, Total Lift generated, and Wing Loading capacity of a proposed aircraft. */
    public class Wing
     {
      
        Scanner keyboard = new Scanner ( System.in );
             
        /** Field(s) */
         private double span;
         private double chord;
         private double vCruise;
         private double vStall;
         private double cLiftMax;
         private double cLiftCruise;
         private double altitudeTO;
         private double altitudeCruise;
          
          
        /** Calculation Variables */
         private double wingArea = span * chord;
          
         private double takeoffDynamicPressureStandard;
         private double takeoffDynamicPressureHot;
         private double takeoffWingLoadingStandard;
         private double takeoffWingLoadingHot;
     
         private double cruisingDynamicPressureStandard;
         private double cruisingDynamicPressureHot;
         private double cruisingWingLoadingStandard;
         private double cruisingWingLoadingHot;
          
          
        /** Array holding Standard & Hot day air densities based on altitude */
         double[][] rho = 
                          {//Standard //Hot
                            { .00238 , .00226 }, //0 ft
                            { .00231 , .00220 }, //1k ft
                            { .00224 , .00214 }, //2k ft
                            { .00218 , .00208 }, //3k ft
                            { .00211 , .00202 }, //4k ft
                            { .00205 , .00196 }, //5k ft
                            { .00199 , .00191 }, //6k ft
                            { .00193 , .00185 }, //7k ft
                            { .00187 , .00180 }, //8k ft
                            { .00181 , .00175 }, //9k ft
                            { .00176 , .00107 }, //10k ft
                            { .00170 , .00165 }, //11k ft
                            { .00165 , .00160 }, //12k ft
                            { .00160 , .00155 }, //13k ft
                            { .00155 , .00150 }, //14k ft
                            { .00150 , .00146 }, //15k ft
                            { .00145 , .00141 }, //16k ft
                            { .00140 , .00137 }, //17k ft
                            { .00136 , .00133 }, //18k ft
                            { .00131 , .00129 }, //19k ft
                            { .00127 , .00125 }  //20k ft             
                           
                          };
     
       
        /** Constructor(s) */
         public Wing()   
          {
            System.out.print("Enter wing span of proposed aircraft (in feet) --> ");
            span = keyboard.nextDouble();  
             
            System.out.print("Enter chord of proposed aircraft (in feet) --> ");
            chord = keyboard.nextDouble();
            
            System.out.print("Enter anticipated cruising velocity of proposed aircraft (200 knots = 200) --> ");
            vCruise = keyboard.nextDouble();
            vCruise = vCruise * 1.689; //Converting knots to FPS
            
            System.out.print("Enter anticipated stall velocity of proposed aircraft (45 knots = 45) --> ");
            vStall = keyboard.nextDouble();
            vStall = vStall * 1.689; //Converting knots to FPS
            
            System.out.print("Enter maximum lift of proposed aircraft --> ");
            cLiftMax = keyboard.nextDouble();
            
            System.out.print("Enter cruising lift of proposed aircraft --> ");
            cLiftCruise = keyboard.nextDouble();
            
            System.out.print("Enter anticipated takeoff altitude of proposed aircraft (0-20,000 feet = 0-20 [increments of 1 per 1,000 feet ]) --> ");
            altitudeTO = keyboard.nextDouble();
            
            System.out.print("Enter anticipated cruising altitude of proposed aircraft (0-20,000 feet = 0-20 [increments of 1 per 1,000 feet ]) --> ");
            altitudeCruise = keyboard.nextDouble();
               
          }
           
         
        /** Accessor(s) */
         
          //Get Series of accessors
         public double getSpan()
          {
            return span;
          }
         public double getChord()
          {
            return chord;
          }
         public double get_vCruise()
          {
            return vCruise;
          }
         public double get_vStall()
          {
            return vStall;
          }
         public double get_cLiftMax()
          {
            return cLiftMax;
          }
         public double get_cLiftCruise()
          {
            return cLiftCruise;
          }
         public double getAltitudeTO()
          {
            return altitudeTO;
          }
         public double getAltitudeCruise()
          {
            return altitudeCruise;
          }
                
                
          //Display Series of accessors
         public void displayCurrentSpan()
          {
            System.out.print("Span is currently set to " + span + "\n" );
          }
         public void displayCurrentChord()
          {
            System.out.print("Chord is currently set to " + chord + "\n" );
          }
         public void displayCurrent_vCruise()
          {
            System.out.print("Crusing Velocity is currently set to " + vCruise + " FPS.\n" );
          }
         public void displayCurrent_vStall()
          {
            System.out.print("Stall Velocity is currently set to " + vStall + " FPS.\n" );
          }
         public void displayCurrent_cLiftMax()
          {
            System.out.print("Maximum lift is currently set to " + cLiftMax + "\n" );
          }
         public void displayCurrent_cLiftCruise()
          {
            System.out.print("Cruising lift is currently set to " + cLiftCruise + "\n" );
          }
         public void displayCurrentAltitudeTO()
          {
            System.out.print("Takeoff altitude is currently set to " + altitudeTO + "\n" );
          }
         public void displayCurrentAltitudeCruise()
          {
            System.out.print("Cruising altitude is currently set to " + altitudeCruise + "\n" );
          }
                  
              
        /** Mutator(s) */
      
         public void setSpan()
          {
            System.out.print("Enter the new Span of proposed aircraft (in feet) --> ");
            span = keyboard.nextDouble(); 
          }
         public void setChord()
          {
            System.out.print("Enter the new Chord of proposed aircraft (in feet) --> ");
            chord = keyboard.nextDouble();
          }
         public void set_vCruise()
          {
            System.out.print("Enter the new cruising velocity of proposed aircraft (200 knots = 200) --> ");
            vCruise = keyboard.nextDouble();
            vCruise = vCruise * 1.689; //Converting knots to FPS
          }
         public void set_vStall()
          {
            System.out.print("Enter the new stall velocity of proposed aircraft (45 knots = 45) --> ");
            vStall = keyboard.nextDouble();
            vStall = vStall * 1.689; //Converting knots to FPS
          }
         public void set_cLiftMax()
          {
            System.out.print("Enter the new maximum lift of proposed aircraft --> ");
            cLiftMax = keyboard.nextDouble();
          }
         public void set_cLiftCruise()
          {
            System.out.print("Enter the new cruising lift of proposed aircraft --> ");
            cLiftCruise = keyboard.nextDouble();
          }
         public void setAltitudeTO()
          {
            System.out.print("Enter the new anticipated takeoff altitude of proposed aircraft (0-20,000 feet = 0-20 [increments of 1 per 1,000 feet ]) --> ");
            altitudeTO = keyboard.nextDouble();
          }
         public void setAltitudeCruise()
          {
            System.out.print("Enter the new anticipated cruising altitude of proposed aircraft (0-20,000 feet = 0-20 [increments of 1 per 1,000 feet ]) --> ");
            altitudeCruise = keyboard.nextDouble();
          }
     
     
     
        /** Methods */
         public void dynamicPressure() //Calculates Dynamic Pressure based on user provided parameters.
          {
            System.out.print("\nWould you like the calculation performed for STANDARD DAY or HOT DAY? Answer = '1' for HOT or '0' for STANDARD ");
            int pressureTypeInput = keyboard.nextInt();
              
             if (pressureTypeInput == 0) //Dynamic Pressure for STANDARD DAY
              {
                int takeOffAltitudeCalculation = (int) altitudeTO; //Takeoff Altitude Calculation
                double takeoffDynamicPressure = .5 * rho[takeOffAltitudeCalculation][0] * Math.pow(vStall,2) ;
                System.out.print("\nThe Dynamic Pressure equates to " + takeoffDynamicPressure + " based on the following inputs:\nSpan " + span + "\nChord " + chord + "\nCruising Velocity " + vCruise + "FPS\nStall Velocity " + vStall + "FPS\nMaximum Lift " + cLiftMax + "\nCruising Lift " + cLiftCruise + "\nTakeoff Altitude " + altitudeTO + "k feet\nWith a temp of STANDARD DAY\n" );
                takeoffDynamicPressureStandard = takeoffDynamicPressure;
                 
                int cruisingAltitudeCalculation = (int) altitudeCruise; //Cruising Altitude Calculation
                double cruisingDynamicPressure = .5 * rho[cruisingAltitudeCalculation][0] * Math.pow(vCruise,2) ;
                System.out.print("\nThe Dynamic Pressure at your provided Cruising Altitude of " + altitudeCruise + "k feet based on those same parameters above, equates to a Dynamic Pressure of " + cruisingDynamicPressure + "\n" );
                cruisingDynamicPressureStandard = cruisingDynamicPressure;
                 
              }
               
             else if (pressureTypeInput == 1) //Dynamic Pressure for HOT DAY
              {
                int takeOffAltitudeCalculation = (int) altitudeTO; //Takeoff Altitude Calculation
                double takeoffDynamicPressure = .5 * rho[takeOffAltitudeCalculation][1] * Math.pow(vStall,2) ;
                System.out.print("\nThe Dynamic Pressure equates to " + takeoffDynamicPressure + " based on the following inputs:\nSpan " + span + "\nChord " + chord + "\nCruising Velocity " + vCruise + "FPS\nStall Velocity " + vStall + "FPS\nMaximum Lift " + cLiftMax + "\nCruising Lift " + cLiftCruise + "\nTakeoff Altitude " + altitudeTO + "k feet\nWith a temp of STANDARD DAY\n" );
                takeoffDynamicPressureHot = takeoffDynamicPressure;
                 
                int cruisingAltitudeCalculation = (int) altitudeCruise; //Cruising Altitude Calculation
                double cruisingDynamicPressure = .5 * rho[cruisingAltitudeCalculation][1] * Math.pow(vCruise,2) ;
                System.out.print("\nThe Dynamic Pressure at your provided Cruising Altitude of " + altitudeCruise + "k feet and with those same parameters above, equates to a Dynamic Pressure of " + cruisingDynamicPressure + "\n" );
                cruisingDynamicPressureHot = cruisingDynamicPressure;
                 
              }
              
             else if (pressureTypeInput > 1)
              
              {
                System.out.print( "Wrong input buddy." );
                System.out.print( "Want to give it another shot? '1' for Yes or '0' for No -->" );
                int userThinking = keyboard.nextInt();
                   
                  if (userThinking == 1)
                   {
                    dynamicPressure();
                   }
                  else if (userThinking == 0)
                   {
                    System.exit(0);
                   }
                         
              } 
           
          }
           
         public void totalLift() //Calculates lift based on user provided parameters.
          {
            double totalLiftStandardTO = wingArea * takeoffDynamicPressureStandard * cLiftMax;             //Standard Day, Takeoff
            double totalLiftStandardCruising = wingArea * cruisingDynamicPressureStandard * cLiftCruise;   //Standard Day, Cruising
            double totalLiftHotTO = wingArea * takeoffDynamicPressureHot * cLiftMax;                       //Hot Day, Takeoff
            double totalLiftHotCruising = wingArea * cruisingDynamicPressureHot * cLiftCruise;             //Hot Day, Cruising
             
            System.out.print("\nBased on the supplied inputs:\nSpan " + span + "\nChord " + chord + "\nCruising Velocity " + vCruise + "FPS\nStall Velocity " + vStall + "FPS\nMaximum Lift " + cLiftMax + "\nCruising Lift " + cLiftCruise + "\nTakeoff Altitude " + altitudeTO + "k feet\nCruising Altitude " + altitudeCruise + "k feet\nTotal achievable lift breaks down as follows:\n" + "Standard Day - Takeoff = " + totalLiftStandardTO + "\nStandard Day - Cruising = " + totalLiftStandardCruising + "\nHot Day - Takeoff = " + totalLiftHotTO + "\nHot Day - Cruising = " + totalLiftHotCruising );
             
            takeoffWingLoadingStandard = totalLiftStandardTO;
            takeoffWingLoadingHot = totalLiftHotTO;
            cruisingWingLoadingStandard = totalLiftStandardCruising;
            cruisingWingLoadingHot = totalLiftHotCruising;
     
     
     
          }
           
         public void wingLoading() //Calculates wing load based on user provided parameters.
          {
            double wingLoadingStandardTO = takeoffWingLoadingStandard / wingArea;       //Standard Day, Takeoff
            double wingLoadingHotTO = takeoffWingLoadingHot / wingArea;                 //Standard Day, Cruising
            double wingLoadingStandardCruise = cruisingWingLoadingStandard / wingArea;  //Hot Day, Takeoff
            double wingLoadingHotCruise = cruisingWingLoadingHot / wingArea;            //Hot Day, Cruising
             
            System.out.print("\nBased on the supplied inputs:\nSpan " + span + "\nChord " + chord + "\nCruising Velocity " + vCruise + "FPS\nStall Velocity " + vStall + "FPS\nMaximum Lift " + cLiftMax + "\nCruising Lift " + cLiftCruise + "\nTakeoff Altitude " + altitudeTO + "k feet\nCruising Altitude " + altitudeCruise + "k feet\nTotal achievable wing loading breaks down as follows:\n" + "Standard Day - Takeoff = " + wingLoadingStandardTO + "\nStandard Day - Cruising = " + wingLoadingStandardCruise + "\nHot Day - Takeoff = " + wingLoadingHotTO + "\nHot Day - Cruising = " + wingLoadingHotCruise );
     
          }
           
         
    }
     
    /** NO CODE FOLLOWS */
    CLASS TESTER CODE FOLLOWS:
    Code:
    /** Wing Class Tester*/
    public class WingTester
    {
       public static void main(String[] args)
       {
          /** Test instantiation */
          Wing myWingTest;
           
             myWingTest = new Wing();
                       
             myWingTest.dynamicPressure();             
         
             myWingTest.totalLift();
           
             myWingTest.wingLoading();
      
            
     
           
       }
           
    }
     
    /** NO CODE FOLLOWS */

  2. #2
    2kaud's Avatar
    2kaud is offline Super Moderator Power Poster
    Join Date
    Dec 2012
    Location
    England
    Posts
    6,924

    Re: Code compiles but unable to find error fouling calculation - Java Version 1.8.0_9

    to calculate properly for some reason.
    Can you be more specific? Also the attachment in post #1 is invalid and can't be opened.

    have retraced my logic to no avail
    What debugging of the code have you done! By debugging you should be able to find where the code is deviating from that expected.
    All advice is offered in good faith only. All my code is tested (unless stated explicitly otherwise) with the latest version of Microsoft Visual Studio (using the supported features of the latest standard) and is offered as examples only - not as production quality. I cannot offer advice regarding any other c/c++ compiler/IDE or incompatibilities with VS. You are ultimately responsible for the effects of your programs and the integrity of the machines they run on. Anything I post, code snippets, advice, etc is licensed as Public Domain https://creativecommons.org/publicdomain/zero/1.0/ and can be used without reference or acknowledgement. Also note that I only provide advice and guidance via the forums - and not via private messages!

    C++17 Compiler: Microsoft VS2019 (16.4.0)

  3. #3
    Join Date
    Sep 2016
    Posts
    2

    Re: Code compiles but unable to find error fouling calculation - Java Version 1.8.0_9

    Quote Originally Posted by 2kaud View Post
    Can you be more specific? Also the attachment in post #1 is invalid and can't be opened.



    What debugging of the code have you done! By debugging you should be able to find where the code is deviating from that expected.
    Hi 2kaud,

    I really appreciate you taking the time to reach out, especially at the hour you did. I was able to get some guidance on another java forum, I just tested the suggested solution for my problem successfully. The problem was I needed a stand alone method to calculate the area in a larger calculation.

    Details here in case anyone else is interested: https://coderanch.com/t/670205/java/...ormula#3131447

  4. #4
    2kaud's Avatar
    2kaud is offline Super Moderator Power Poster
    Join Date
    Dec 2012
    Location
    England
    Posts
    6,924

    Re: Code compiles but unable to find error fouling calculation - Java Version 1.8.0_9

    I've seen the other site and yes the issue is that wingArea isn't being set after the values have been entered - so wingArea is always incorrect. This is where debugging comes into its own as that would have shown the incorrect value for wingArea. However, there appears to be a simpler solution to the one proposed. Why not set wingArea after the values have been entered? - the rest of the code then doesn't need to be changed. Consider
    Code:
            System.out.print("Enter wing span of proposed aircraft (in feet) --> ");
            span = keyboard.nextDouble();  
             
            System.out.print("Enter chord of proposed aircraft (in feet) --> ");
            chord = keyboard.nextDouble();
    
            wingArea = span * chord;
    All advice is offered in good faith only. All my code is tested (unless stated explicitly otherwise) with the latest version of Microsoft Visual Studio (using the supported features of the latest standard) and is offered as examples only - not as production quality. I cannot offer advice regarding any other c/c++ compiler/IDE or incompatibilities with VS. You are ultimately responsible for the effects of your programs and the integrity of the machines they run on. Anything I post, code snippets, advice, etc is licensed as Public Domain https://creativecommons.org/publicdomain/zero/1.0/ and can be used without reference or acknowledgement. Also note that I only provide advice and guidance via the forums - and not via private messages!

    C++17 Compiler: Microsoft VS2019 (16.4.0)

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  


Windows Mobile Development Center


Click Here to Expand Forum to Full Width




On-Demand Webinars (sponsored)