Beispiel #1
0
        static void Main(string[] args)
        {
            Console.WriteLine("***** Fun with Class Types *****\n");

            Car myCar = new Car();
            myCar.petName = "Henry";
            myCar.currSpeed = 10;

            for (int i = 0; i <= 10; i++)
            {
                myCar.SpeedUp(5);
                myCar.PrintState();
            }

            Car chuck = new Car();
            chuck.PrintState();

            Car mary = new Car("Mary");
            mary.PrintState();

            Car daisy = new Car("Daysy", 75);
            daisy.PrintState();

            Motorcycle mc = new Motorcycle();
            mc.PopAWheely();

            Motorcycle c = new Motorcycle(5);
            c.SetDriverName("Tiny");
            c.PopAWheely();
            Console.WriteLine("Rider name is {0}", c.driverName);

            Console.ReadLine();
        }
Beispiel #2
0
        static void MakeSomeBikes()
        {
            Motorcycle m1 = new Motorcycle();
            Console.WriteLine("Name = {0}, Intensity = {1}",
                m1.driverName, m1.driverIntensity);

            Motorcycle m2 = new Motorcycle(name: "Tiny");
            Console.WriteLine("Name = {0}, Intensity = {1}", m2.driverName, m2.driverIntensity);

            Motorcycle m3 = new Motorcycle(7);
            Console.WriteLine("Name={0}, Intensity = {1}", m3.driverName, m3.driverIntensity);
        }
Beispiel #3
0
        static void Main( string[] args )
        {
            Console.WriteLine("***** Fun with Class Types *****\n");

            #region Make some motorcycles
            Motorcycle mc = new Motorcycle();
            mc.PopAWheely();
            Console.WriteLine();

            // Make a Motorcycle with a rider named Tiny?
            Motorcycle c = new Motorcycle(5);
            c.SetDriverName("Tiny");
            c.PopAWheely();
            Console.WriteLine("Rider name is {0}", c.driverName); // Prints an empty name value!
            Console.WriteLine();
            #endregion

            #region Make some cars!
            // Make a Car called Chuck going 10 MPH.
            Car chuck = new Car();
            chuck.PrintState();

            // Make a Car called Mary going 0 MPH.
            Car mary = new Car("Mary");
            mary.PrintState();

            // Make a Car called Daisy going 75 MPH.
            Car daisy = new Car("Daisy", 75);
            daisy.PrintState();

            Console.WriteLine();

            // Allocate and configure a Car object.
            Car myCar = new Car();
            myCar.petName = "Henry";
            myCar.currSpeed = 10;

            // Speed up the car a few times and print out the
            // new state.
            for (int i = 0; i <= 10; i++)
            {
                myCar.SpeedUp(5);
                myCar.PrintState();
            }
            Console.WriteLine();
            #endregion

            MakeSomeBikes();

            Console.ReadLine();
        }
        static void Main(string[] args)
        {
            //Car myCar; would cause use of unassigned local variable error
            Car myCar = new Car();
            myCar.PrintState();


            myCar.petName = "Henry";
            myCar.currSpeed = 10;
            for (int i = 0; i<= 10; i++)
            {
                myCar.SpeedUp(5);
                myCar.PrintState();
            }

            Console.WriteLine();
            Car mary = new Car(pn: "Mary");  //nmaed param
            mary.PrintState();

            Car daisy = new Car("Daisy", 25);
            daisy.PrintState();

            Console.WriteLine();

            Motorcycle c = new Motorcycle();
            c.SetDriverName("AAA");
            Console.WriteLine("Rider name is {0}", c.name);
            Console.WriteLine("Rider name is null: {0}", c.name == null);

            Console.WriteLine();
            Console.WriteLine("=> Constructor flow");
            Motorcycle cc = new Motorcycle(5);
            Console.WriteLine();

            Console.WriteLine("=> Optional params instead of constructor chaining");

            Motorcycle1 m1 = new Motorcycle1();
            Motorcycle1 m2 = new Motorcycle1(name: "Tiny");
            Motorcycle1 m3 = new Motorcycle1(7);
            Motorcycle1 m4 = new Motorcycle1(7, "Tiny2");

            Console.WriteLine("Name = {0}, Intensity = {1}", m1.name, m1.driverIntensity);
            Console.WriteLine("Name = {0}, Intensity = {1}", m2.name, m2.driverIntensity);
            Console.WriteLine("Name = {0}, Intensity = {1}", m3.name, m3.driverIntensity);
            Console.WriteLine("Name = {0}, Intensity = {1}", m4.name, m4.driverIntensity);

            Console.ReadLine();
        }
        static void Main(string[] args)
        {
            Console.WriteLine("***** Fun with Class Types *****\n");

            // Allocate and configure a Car object.
            Car myCar = new Car();
            myCar.petName = "Henry";
            myCar.currSpeed = 10;

            // Speed up the car a few times and print out the new state.
            for (int i = 0; i <= 10; i++)
            {
                myCar.SpeedUp(5);
                myCar.PrintState();
            }

            // Invoking the default constructor.
            Car chuck = new Car();

            // Prints "Chuck is going 10 MPH."
            chuck.PrintState();

            // Make a Car called Mary going 0 MPH.
            Car mary = new Car("Mary");
            mary.PrintState();

            // Make a Car called Daisy going 75 MPH.
            Car daisy = new Car("Daisy", 75);
            daisy.PrintState();

            Motorcycle mc = new Motorcycle();
            mc.PopAWheely();

            Motorcycle c = new Motorcycle(5);
            c.SetDriverName("Tiny");
            c.PopAWheely();
            Console.WriteLine("Rider name is {0}", c.driverName);

            OptMotorcyle omc = new OptMotorcyle(name:"Kevin");
            Console.WriteLine("Opt Rider Name is {0}", omc.driverName);

            Console.ReadKey();
        }
Beispiel #6
0
        static void Main(string[] args)
        {
            Console.WriteLine("***** Fun with Class Types *****\n");

            //Aloque e configure um objeto Car.
            Car myCar = new Car();

            myCar.petName = "Henry";
            myCar.currSpeed = 10;

            //Aumente a velocidade de car algumas vezes e imprima o novo estado.

            for (int i = 0; i <= 10; i++)
            {
                myCar.SpeedUp(5);
                myCar.PrintState();
            }

            Console.WriteLine();

            Car chuck = new Car();

            chuck.PrintState();

            Console.WriteLine();

            //Cria um carro chamado chuck indo a 10MPH
            Car nchuck = new Car();

            nchuck.PrintState();

            Console.WriteLine();

            //Cria um carro chamado Marry indo a 10MPH
            Car mary = new Car("Marry");

            mary.PrintState();

            Console.WriteLine();

            //Cria um carro chamado Daisy indo a 75MPH
            Car daisy = new Car("Daisy", 75);

            daisy.PrintState();

            Console.WriteLine();

            Motorcycle mc = new Motorcycle();

            mc.PopAWheely();

            Console.WriteLine("############FUN WITH CTOR##############");

            Motorcycle c = new Motorcycle(5);

            c.SetDriverName("Tiny");
            c.PopAWheely();

            Console.WriteLine("Rider name is{0}", c.driverName);

            Console.WriteLine("############FUN WITH MC2##############");

            Motorcycle2 m1 = new Motorcycle2();
            Console.WriteLine("Name= {0}, Intensity = {1}", m1.driverName, m1.driverIntensity);

            Motorcycle2 m2 = new Motorcycle2(name: "Tiny");
            Console.WriteLine("Name = {0}, Intensity = {1}", m2.driverName, m2.driverIntensity);

            Motorcycle2 m3 = new Motorcycle2(7);
            Console.WriteLine("Name = {0}, Intensity = {1}", m3.driverName, m3.driverIntensity);

            Console.ReadLine();
        }
        private void button_Click(object sender, RoutedEventArgs e)
        {
            var m1 = new MotorcycleAlt();
            Console.WriteLine(@"Name {0} , Intersity {1}", m1.driverName, m1.driverIntensity);

            var m2 = new MotorcycleAlt(name: "Boss");
            Console.WriteLine(@"Name {0} , Intersity {1}", m2.driverName, m2.driverIntensity);
            var m3 = new MotorcycleAlt(7);
            Console.WriteLine(@"Name {0} , Intersity {1}", m3.driverName, m3.driverIntensity);

            var c = new Motorcycle(5);
            c.SetDriverName("Tiny");
            c.PopAWheely();
            Console.WriteLine(@"Rider name is {0} ", c.driverName);
            var cuck = new Car();
            cuck.PrintState();
            Console.WriteLine(@"--------------------------------------");
            Car mary = new Car("Mary");
            mary.PrintState();
            var myCar = new Car("Henry", 10);
            for (int i = 0; i <= 10; i++)
            {
                myCar.SpeedUp(5);
                myCar.PrintState();
            }
        }