Beispiel #1
0
            public void RunExercise()
            {
                Plane    x = new Plane(10, 12001.50);
                JetPlane y = new JetPlane(10, 12001.55, 20);

                x.Print();
                y.Print();
            }
Beispiel #2
0
        /// <summary>
        /// Tryin to uderstand the Stratergy Pattern
        ///
        /// </summary>
        /// <param name="args"></param>
        static void Main(string[] args)
        {
            // We have some airbourne machinery and have derived 3 classes from it
            // Helicopter, Jet Plane and a TurboProp Plane.
            // The base class AirborneMachinery is abstract as we never want to create it, because its not and never will be a real thing
            // Each item of airbourne machinery must eventually be installed with an engine.

            JetPlane       myJetPlane       = new JetPlane();
            TurboPropPlane myTurboPropPlane = new TurboPropPlane();
            Helicoptor     myHelicopter     = new Helicoptor();

            // It would be possible to add the engine in the constuctor, but that would make it more diffuicult
            // for different Aircraft of the same type (Jet,Tubo,Helicopter) to have different engine models
            // we would have to create a new class for each engine model.
            // by setting it as a method, we get an extra layer of abstraction.
            // we could create M2,M3 models of each engine and as we build the plane adde them here.

            myJetPlane.SetEngine(new JetPlaneEngineEngineM1());
            myTurboPropPlane.SetEngine(new TurboPropEngineM1());
            myHelicopter.SetEngine(new HelicopterTurbineEngineM1());

            // because the are all the same base class, they can all be added to a common list

            List <AirborneMachinery> myFlyingMachines = new List <AirborneMachinery>();

            myFlyingMachines.Add(myJetPlane);
            myFlyingMachines.Add(myTurboPropPlane);
            myFlyingMachines.Add(myHelicopter);

            // and we can use the baseclass to start the engines
            foreach (AirborneMachinery AM in myFlyingMachines)
            {
                AM.StartEngine();
            }

            Console.WriteLine("Changing engine in my Jet Plane");
            myJetPlane.SetEngine(new JetPlaneEngineEngineM2());
            myJetPlane.StartEngine();
        }
Beispiel #3
0
        //start method main:
        static void Main(string[] args)
        {
            student student = new student();

            Console.WriteLine("hello world");

            Console.WriteLine("hello niklas");

            var a = 5;
            var b = 6;

            Swap(ref a, ref b);

            Console.WriteLine($"we swap this function a = {a} and b = {b}");


            // fast way to add values because of constructors.
            Car ford = new Car("ford", 1992, "red");
            Car audi = new Car("audi", 2000, "blue");

            audi.Model = "ford";

            Console.WriteLine("the color of ford is: " + ford.color);
            Console.WriteLine("the model of audi is " + audi.Model);

            course math = new course("Matematik", 10);

            Console.WriteLine("the ects of " + math.courseName + " and the ects is: " + math.courseECTS);

            // We define the class "course" property here and print it.
            math.getRandomString = "hej med jer !";
            Console.WriteLine(math.getRandomString);

            Console.WriteLine(audi.Model + " and " + audi.brand);

            //Polymorpism:
            //hi
            Animal myAnimal = new Animal();
            Animal myPig    = new pig();

            //This showcases that the pig class also can use animal methods


            myAnimal.animalSound();
            myPig.animalSound();


            //Usage of our abstract and jetplane classes
            JetPlane myJet = new JetPlane();

            myJet.MotorStart();
            myJet.StopMotor();
            myJet.Wing();

            //Usage of Enums
            EnumClass myvar = EnumClass.Low;

            Console.WriteLine(myvar);

            //write to text
            string writeText = "hello World";

            for (int i = 0; i < writeText.Length; i++)
            {
                System.IO.File.WriteAllText(@"C:\Users\45535\Desktop\RAWDATA\C#\training_1\training_1\CMS.UI.Models\Data\Text1.txt", writeText);
                string readLine =
                    File.ReadAllText(
                        @"C:\Users\45535\Desktop\RAWDATA\C#\training_1\training_1\CMS.UI.Models\Data\Text1.txt");
                Console.WriteLine(readLine);
            }
            //try catch with exception
            try
            {
                int[] myNumbers = { 1, 2, 3 };
                Console.WriteLine(myNumbers[2]);
            }
            catch (Exception e)
            {
                Console.WriteLine("Something went wrong.");
            }
            //Adding numbers
            int x   = 5;
            int y   = 6;
            int sum = x + y;

            Console.WriteLine(sum); // Print the sum of x + y
        }