示例#1
0
        private void btnAnyCar_Click(object sender, EventArgs e)
        {
            Automobile myAuto = new Automobile();
            Automobile myOtherAuto = new Car();
            Automobile myOtherAutoT = new Truck();
            Automobile myOtherAutoS = new SUV();

            myAuto.Price = 100M;
            myAuto.Mileage = 10;
            myAuto.StartEngine();

            myOtherAutoS.Make = "New SUV!";
            myOtherAutoS.Mileage = 12;
            myOtherAutoS.Price = 22000M;
            myOtherAutoS.StartEngine();
            myOtherAutoS.ShowInfo();

            myOtherAuto.StartEngine();
            myOtherAutoT.Price = 100000M;
            myOtherAutoT.Mileage = 10;
            myAuto.ShowInfo();
            myOtherAutoT.ShowInfo();

            //tryStartingAgain(myAuto);
            //tryStartingAgain(myOtherAuto);

            //Car coolCar = (Car) new Automobile();
            //MessageBox.Show("Test: " + myOtherAuto.Doors);
            //Cannot access
        }
        static void Main(string[] args)
        {
            Car myCar = new Car("Nissan", "Sentra", 2000, "Silver");
            Car otherCar = new Car();
            Truck myTruck = new Truck("Nissan", "Frontier", 2014, "Silver", 10000);

            myCar.PrintDetails();
            otherCar.PrintDetails();
            myTruck.PrintDetails();
            Console.ReadLine();
        }
示例#3
0
        private void btnAddTruck_Click(object sender, EventArgs e)
        {
            int mileage, year, wheeldrive;
            decimal price;
            Truck aTruck = new Truck();
            aTruck.Make = txtMake.Text;

            if (int.TryParse(txtMileage.Text, out mileage))
                aTruck.Mileage = mileage;
            else
            {
                MessageBox.Show("mileage must be a number");
                txtMileage.Clear();
                txtMileage.Focus();

            }

            if (int.TryParse(txtWheelDrive.Text, out wheeldrive) && wheeldrive == 2 || int.TryParse(txtWheelDrive.Text, out wheeldrive) && wheeldrive == 4)
                aTruck.WheelDrive = wheeldrive;
            else
            {
                MessageBox.Show("WheelDrive must be either 2 or 4");
                txtWheelDrive.Clear();
                txtWheelDrive.Focus();

            }
            if (int.TryParse(txtYear.Text, out year))
                aTruck.ModelYear = year;
            else
            {
                MessageBox.Show("year must be a number");
                txtYear.Clear();
                txtYear.Focus();

            }
            if (decimal.TryParse(txtPrice.Text, out price))
                aTruck.Price = price;
            else
            {
                MessageBox.Show("Price must be a number");
                txtPrice.Clear();
                txtPrice.Focus();

            }
            Main.trucks.Add(aTruck);
            txtWheelDrive.Clear();
            txtMake.Clear();
            txtMileage.Clear();
            txtPrice.Clear();
            txtYear.Clear();
        }
示例#4
0
        static void Main(string[] args)
        {
            Vehicle cleanVehicle = new Vehicle();
            cleanVehicle.Make = "VW";
            printVehicleDetails(cleanVehicle);
            Console.ReadLine();

            Vehicle myVehicle = new Vehicle("BMW", "850CSI", "Racing Green", 1991);
            printVehicleDetails(myVehicle);
            Console.ReadLine();

            Car myCar = new Car("Audi", "A8", "Blue metallic", 2003,4);
            printVehicleDetails(myCar);
            Console.ReadLine();

            Truck myTruck = new Truck("Mercedes", "Actros", "Power White", 2015, 40);
            printVehicleDetails(myTruck);
            Console.ReadLine();
        }