How to do it...

  1. Create a new class called LaunchSuttle. Then, add the following private variables to the class for engine thrust, the mass of the shuttle, the local gravitational acceleration, the constant values for the gravity of the Earth, Moon, and Mars (these are constants because they will never change), the universal gravitational constant, and an enumerator for the planet we are dealing with:
        public class LaunchShuttle 
{
private double _EngineThrust;
private double _TotalShuttleMass;
private double _LocalGravitationalAcceleration;

private const double EarthGravity = 9.81;
private const double MoonGravity = 1.63;
private const double MarsGravity = 3.75;
private double UniversalGravitationalConstant;

public enum Planet { Earth, Moon, Mars }
}
  1. To our class, we will add three overloaded constructors that are essential to perform the calculation of the TWR based on the known facts at the time of instantiation (we assume that we will always know the engine thrust capability and mass of the shuttle). We will pass the gravitational acceleration for the first constructor. This is useful if we know beforehand what that value will be. For example, the gravitational acceleration of the Earth is 9.81 m/s2.

The second constructor will use the Planet enumerator to calculate the TWR that uses the constant variable values.

The third constructor will use the radius and mass of the planet to calculate the gravitational acceleration, when those values are known, to return the TWR:

        public LaunchShuttle(double engineThrust, 
double totalShuttleMass, double gravitationalAcceleration)
{
_EngineThrust = engineThrust;
_TotalShuttleMass = totalShuttleMass;
_LocalGravitationalAcceleration = gravitationalAcceleration;

}

public LaunchShuttle(double engineThrust,
double totalShuttleMass, Planet planet)
{
_EngineThrust = engineThrust;
_TotalShuttleMass = totalShuttleMass;
SetGraviationalAcceleration(planet);

}

public LaunchShuttle(double engineThrust, double
totalShuttleMass, double planetMass, double planetRadius)
{
_EngineThrust = engineThrust;
_TotalShuttleMass = totalShuttleMass;
SetUniversalGravitationalConstant();
_LocalGravitationalAcceleration = Math.Round(
CalculateGravitationalAcceleration (
planetRadius, planetMass), 2);
}
  1. In order to use the second overloaded constructor that passes the Planet enumerator as a parameter to the class, we need to create another method that has been scoped as private to calculate the gravitational acceleration. We also need to set the _LocalGravitationalAcceleration variable to the specific constant that matches the enumerator value. This method is something that the user of the class does not need to see in order to use the class. It is, therefore, scoped as private in order to hide that functionality from the user:
        private void SetGraviationalAcceleration(Planet planet) 
{
switch (planet)
{
case Planet.Earth:
_LocalGravitationalAcceleration = EarthGravity;
break;
case Planet.Moon:
_LocalGravitationalAcceleration = MoonGravity;
break;
case Planet.Mars:
_LocalGravitationalAcceleration = MarsGravity;
break;
default:
break;
}
}
  1. Of the following methods, only one is defined as public and will, therefore, be visible to the user of the class. Create the private methods to set the universal gravitational constant and to calculate the TWR and the gravitational acceleration. These are all scoped as private, because the developer does not need to know what these methods do in order to use the class:
        private void SetUniversalGravitationalConstant() 
{
UniversalGravitationalConstant = 6.6726 * Math.Pow(10, -11);
}

private double CalculateThrustToWeightRatio()
{
// TWR = Ft/m.g > 1
return _EngineThrust / (_TotalShuttleMass *
_LocalGravitationalAcceleration);
}

private double CalculateGravitationalAcceleration(
double radius, double mass)
{
return (UniversalGravitationalConstant * mass) /
Math.Pow(radius, 2);
}

public double TWR()
{
return Math.Round(CalculateThrustToWeightRatio(), 2);
}
  1. Finally, in your console application, create the following variables with their known values:
        double thrust = 220; // kN 
double shuttleMass = 16.12; // t
double gravitationalAccelerationEarth = 9.81;
double earthMass = 5.9742 * Math.Pow(10, 24);
double earthRadius = 6378100;
double thrustToWeightRatio = 0;
  1. Create a new instance of the LaunchShuttle class and pass it the values needed to calculate the TWR:
        LaunchShuttle NasaShuttle1 = new LaunchShuttle(thrust, 
shuttleMass, gravitationalAccelerationEarth);
thrustToWeightRatio = NasaShuttle1.TWR();
Console.WriteLine(thrustToWeightRatio);
  1. When you use the dot operator on the NasaShuttle1 variable, you will notice that the IntelliSense only shows the TWR method. The class exposes nothing of the inner workings of how it gets to the calculated TWR value. The only thing that the developer knows is that the LaunchShuttle class will consistently return the correct TWR value, given the same input parameters:
  1. To test this, create two more instances of the LaunchShuttle class and call a different constructor each time:
        LaunchShuttle NasaShuttle2 = new LaunchShuttle(thrust, 
shuttleMass, LaunchShuttle.Planet.Earth);
thrustToWeightRatio = NasaShuttle2.TWR();
Console.WriteLine(thrustToWeightRatio);

LaunchShuttle NasaShuttle3 = new LaunchShuttle(
thrust, shuttleMass, earthMass, earthRadius);
thrustToWeightRatio = NasaShuttle3.TWR();
Console.WriteLine(thrustToWeightRatio);

Console.Read();
  1. If you run your console application, you will see that the same value is returned for the TWR. The value indicates that a shuttle weighing 16.12 tons with a rocket that puts out 220 kilonewtons of thrust will be able to lift off the surface of the Earth (if only just):
..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
3.137.41.205