Beispiel #1
0
        private void btnAddCar_Click(object sender, EventArgs e)
        {
            int year, mileage, doors;
            decimal price;
            string make = txtMake.Text;
               /* Car aCar = new Car();
            aCar.Make = txtMake.Text;
            if (int.TryParse(txtYear.Text, out year))
                aCar.ModelYear = year;
            else
            {
                MessageBox.Show("Year must be an integer");
                txtYear.Clear();
                txtYear.Focus();

            }
            if (int.TryParse(txtMileage.Text, out mileage))
                aCar.Mileage = mileage;
            else
            {
                MessageBox.Show("Mileage must be an integer");
                txtMileage.Clear();
                txtMileage.Focus();

            }
            if( int.TryParse(txtDoors.Text, out doors))
                aCar.Doors = doors;
            else
            {
                MessageBox.Show("Doors must be an integer");
                txtDoors.Clear();
                txtDoors.Focus();

            }
            if (decimal.TryParse(txtPrice.Text, out price))
                aCar.Price = price;
            else
            {

                MessageBox.Show("Price must be a decimal");
                txtPrice.Clear();
                txtPrice.Focus();

            }
            Main.cars.Add(aCar);*/

            doors = int.Parse(txtDoors.Text);
            year = int.Parse(txtYear.Text);
            mileage = int.Parse(txtMileage.Text);
            price = decimal.Parse(txtPrice.Text);
            make = txtMake.Text;
            Car someCar = new Car(make, year, mileage, price, doors);
            Main.cars.Add(someCar);

            txtDoors.Clear();
            txtMake.Clear();
            txtMileage.Clear();
            txtPrice.Clear();
            txtYear.Clear();
        }
Beispiel #2
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();
        }
Beispiel #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();
        }
Beispiel #5
0
 private void btnStartCar_Click(object sender, EventArgs e)
 {
     Car myCar = new Car();
     myCar.StartEngine();
 }
Beispiel #6
0
 static void Main(string[] args)
 {
     var car = new Car("43321");
 }