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

            // 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();

            // 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.ReadLine();
        }
Beispiel #2
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 #3
0
        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();
            }

            Car myCar2;

            myCar2         = new Car();
            myCar2.petName = "Fred";

            // 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();

            // 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);

            MakeSomeBikes();

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

            // Chamando constructor Default Motorcycle
            Motorcycle mc = new Motorcycle();

            mc.PopAWheely();

            // Chamando constructor Default
            // Chuck 10 MPH
            Car chuck = new Car();

            chuck.PrintState();

            // Mary 0 MPH
            Car mary = new Car("Mary");

            mary.PrintState();

            // Daisy 75 MPH
            Car daisy = new Car("Daisy", 75);

            daisy.PrintState();

            Console.WriteLine("\n");

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

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

            // Aumenta a velocidade de car algumas vezes e imprime o novo estado
            for (int i = 0; i <= 10; i++)
            {
                myCar.SpeedUp(5);
                myCar.PrintState();
            }

            Console.WriteLine("\n");

            Motorcycle c = new Motorcycle(5);

            c.setDriverName("Tiny");
            c.PopAWheely();
            Console.WriteLine("Rider name is {0}", c.name);// Imprime nome vazio

            Console.WriteLine("\n");
            MakeSomeBikes();

            Console.ReadLine();
        }
Beispiel #5
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)
        {
            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)
        {
            Console.WriteLine("*******FUN WITH CLASS TYPES********\n");

            // 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);
            Console.WriteLine();
            // Prints an empty name value!

            //instantiating the motorcycle
            Motorcycle mc = new Motorcycle();

            mc.PopAWheely();

            //invoking the default constructor
            Car chuck = new Car();

            chuck.PrintState();

            //make a car called Mary going 0 km/h.
            Car mary = new Car("Mary");

            mary.PrintState();

            //make a car called Daisy going 75km/.
            Car daisy = new Car("Daisy", 75);

            daisy.PrintState();

            //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 new state out

            for (int i = 0; i <= 10; i++)
            {
                mycar.SpeedUp(5);
                mycar.PrintState();
            }
            Encapsulation : constructors :
            Console.ReadLine();
        }
Beispiel #8
0
        private 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();
            }

            Console.WriteLine("\n***** Fun with Class Types *****");

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

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

            //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);

            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);

            Console.ReadLine();
        }
        static void Main(string[] args)
        {
            Console.WriteLine("***** FUN WITH CLASS TYPES *****\n");

            Motorcycle mc = new Motorcycle();

            mc.PopAWheely();

            //Размещаем в памяти и конфигурируем объект Car
            Car myCar = new Car();

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

            //Увеличим скорость автомобиля в несколько раз и выведем новое состояние.
            for (int i = 0; i <= 10; i++)
            {
                myCar.SpeedUp(5);
                myCar.PrintState();
            }

            Console.WriteLine();

            //Создаем объект Car по имени Chuck со скоростью 10 миль в час (специальный стандартный конструктор)
            Car chack = new Car();

            chack.PrintState();

            //Создаем объект Car по имени Mary со скоростью 0 миль в час (специальный конструктор)
            Car mary = new Car("Mary");

            mary.PrintState();

            //Создаем объект Car по имени Daisy со скоростью 75 миль в час (специальный конструктор)
            Car daisy = new Car("Daisy", 75);

            daisy.PrintState();

            //Создаем объект Motorcycle с мотоциклистом по имени Tiny
            Motorcycle c = new Motorcycle(5);

            c.SetDriverName("Tiny");
            c.PopAWheely();
            Console.WriteLine($"Rider name is {c.driverName}");

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

            // Car constructors
            Car myCar = new Car();
            Car chuck = new Car();
            Car mary  = new Car("Mary");
            Car daisy = new Car("Daisy", 75);

            // Motorcycle constructors
            Motorcycle mc = new Motorcycle();
            Motorcycle c  = new Motorcycle(5);
            Motorcycle m1 = new Motorcycle();
            Motorcycle m2 = new Motorcycle(name: "Tiny");
            Motorcycle m3 = new Motorcycle(7);

            // Change myCar fields.
            myCar.petName   = "Henry";
            myCar.currSpeed = 10;

            // Set c's driver name.
            c.SetDriverName("Tiny");

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

            // Print states for Chuck, Mary, and Daisy.
            chuck.PrintState();
            mary.PrintState();
            daisy.PrintState();

            // mc and c pop a wheely.
            mc.PopAWheely();
            c.PopAWheely();
            Console.WriteLine("The rider of c is {0}", c.driverName);
            Console.WriteLine("Name = {0}, Intensity = {1}", m1.driverName, m1.driverIntensity);
            Console.WriteLine("Name = {0}, Intensity = {1}", m2.driverName, m2.driverIntensity);
            Console.WriteLine("Name = {0}, Intensity = {1}", m3.driverName, m3.driverIntensity);

            Console.ReadLine();
        }
Beispiel #11
0
        static void FunWithClassTypes()
        {
            Console.WriteLine("***** Fun with Class Types *****\n");

            //  创建一个叫Chuck的Car,速度为10MPH
            Car chuck = new Car();

            chuck.PrintState();
            Console.WriteLine();

            //  创建一个叫Mary的Car,速度为0MPH
            Car mary = new Car("Mary");

            mary.PrintState();
            Console.WriteLine();

            //  创建一个叫Daisy的Car,速度为75MPH
            Car daisy = new Car("Daisy", 75);

            daisy.PrintState();

            //  分配和设置Car对象
            Car myCar = new Car();

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

            //  将Car加速几次,然后就输出新的状态
            for (int i = 0; i < 10; i++)
            {
                myCar.SpeedUp(5);
                myCar.PrintState();
            }
            Console.WriteLine();

            Console.WriteLine("***** Fun with class Types *****\n");

            //创建Motorcycle
            Motorcycle c = new Motorcycle(5);

            c.SetDriveName("Tiny");
            c.PopAWheely();
            Console.WriteLine("Rider name is {0}", c.driverName);
            Console.WriteLine();
        }
        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 #13
0
        static void Main(string[] args)
        {
            Console.WriteLine("**** Fun with class types ****");
            Car myCar = new Car();

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

            Car chuckCar = new Car();

            chuckCar.PrintState();
            Console.WriteLine();

            Car mary = new Car("Mary");

            mary.PrintState();
            Console.WriteLine();

            Car dasy = new Car("Dasy", 75);

            dasy.PrintState();
            Console.WriteLine();

            Motorcycle mc = new Motorcycle();

            mc.PopAWheely();
            Console.WriteLine();

            Motorcycle c = new Motorcycle(5);

            c.SetDriverName("Tiny");
            c.PopAWheely();
            Console.WriteLine("Driver name is {0}", c.driverName);
            Console.WriteLine();

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

            //Вызов стандартного конструктора
            // Car chuck = new Car();
            //Печать состояния
            //chuck.PrintState();
            //Разместить в память и сконфигурировать объект Car.

            //Создается объект Car по имени Mary, со скоростью 0 миль в час.
            //Car mary = new Car("Mary");
            //mary.PrintState();

            //Создается объект Car по имени Daisy, со скоростью 75 миль в час.
            //Car daisy = new Car("Daisy", 75);
            //daisy.PrintState();

            //Создается объект Motorcycle с мотоциклистом по имени Tiny
            // Motorcycle c = new Motorcycle(5);
            //c.SetDriverName("Tiny");
            //c.PopAWheely();
            //Console.WriteLine("Rider name is {0}", c.name);


            //Увеличить скорость автомобиля в несколько раз и вывести новое состояние
            //for (int i = 0; i <= 10; i++)
            //{
            //    myCar.SpeedUp(5);
            //    myCar.PrintState();
            //}


            // Создать обьект Motorctycle.
            Motorcycle c = new Motorcycle(5);

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

            Console.ReadLine();
        }
Beispiel #15
0
        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.currentSpeed = 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();
            }
            // default constructor
            myCar = new Car();
            myCar.PrintState();

            // Try starting with a chosen name but default speed.
            myCar = new Car("Kirby");
            myCar.PrintState();

            // Chose all starting parameters
            myCar = new Car("Stringy", 22);
            myCar.PrintState();

            Motorcycle mc = new Motorcycle(5);

            mc.SetDriversName("Tiny");
            mc.PopAWheely();
            mc = new Motorcycle("Namey booooi!");
            mc.PopAWheely();

            Console.WriteLine();
            MakeSomeSportsCars();

            Console.ReadLine();
        }
Beispiel #16
0
        static void Main(string[] args)
        {
            Console.WriteLine("***** Fun with Class Types *****\n");
            // Создать объект Car по имени Chuck co скоростью 10 миль в час.
            Car chuck = new Car();

            chuck.PrintState();
            // Создать объект Car по имени Mary co скоростью 0 миль в час.
            Car тагу = new Car("Mary");

            тагу.PrintState();
            // Создать объект Car по имени Daisy со скоростью 75 миль в час.
            Car daisy = new Car("Daisy", 75);

            daisy.PrintState();
            // Разместить в памяти и сконфигурировать объект Саг.
            Car myCar = new Car();

            myCar.petName   = "Henry";
            myCar.currSpeed = 10;
            // Увеличить скорость автомобиля в несколько раз и вывести новое состояние,
            for (int i = 0; i <= 10; i++)
            {
                myCar.Speedup(5);
                myCar.PrintState();
            }

            Motorcycle me = new Motorcycle();

            me.PopAWheely();

            Motorcycle c = new Motorcycle(5);

            c.SetDriverName("Tiny");
            c.PopAWheely();
            Console.WriteLine("Rider name is {0}", c.name); // Выводит пустое значение name!

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

            Console.WriteLine("-- Motorcycles --");

            // Make a Motorcycle with a rider named Tiny
            Motorcycle myMotorCycle = new Motorcycle(5);

            Console.WriteLine(myMotorCycle); // blank name

            myMotorCycle.SetDriverName("Harley");

            Console.WriteLine($"motorcycle name now set, {myMotorCycle}");
            Console.WriteLine("PopAWheely()");
            myMotorCycle.PopAWheely();

            Console.WriteLine("MakeSomeBikes()");
            MakeSomeBikes();

            Console.WriteLine();
            Console.WriteLine("-- Car Example --");

            // Allocate and configure a Car object.
            Car myCar = new Car();

            myCar.carName      = "BMW i3";
            myCar.currentSpeed = 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.ReadLine();
        }
Beispiel #18
0
        static void Main(string[] args)
        {
            Console.WriteLine("=> Fun with Class Types");

            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();

            Motorcycle mc = new Motorcycle(1);

            mc.PopAWheely();
        }
        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();
            }
        }
Beispiel #20
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();
        }