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 }
private void btnAddSUV_Click(object sender, EventArgs e) { int mileage, year, passengers; decimal price; SUV anSUV = new SUV(); anSUV.Make = txtMake.Text; if (int.TryParse(txtMileage.Text, out mileage)) { anSUV.Mileage = mileage; } else { MessageBox.Show("mileage must be a number"); txtMileage.Clear(); txtMileage.Focus(); } if (int.TryParse(txtPassengers.Text, out passengers)) { anSUV.Passengers = passengers; } else { MessageBox.Show("passengers must be a number"); txtPassengers.Clear(); txtPassengers.Focus(); } if (int.TryParse(txtYear.Text, out year)) { anSUV.ModelYear = year; } else { MessageBox.Show("year must be a number"); txtYear.Clear(); txtYear.Focus(); } if (decimal.TryParse(txtPrice.Text, out price)) { anSUV.Price = price; } else { MessageBox.Show("Price must be a number"); txtPrice.Clear(); txtPrice.Focus(); } Main.suvs.Add(anSUV); txtPassengers.Clear(); txtMake.Clear(); txtMileage.Clear(); txtPrice.Clear(); txtYear.Clear(); }
private void btnAddSUV_Click(object sender, EventArgs e) { int mileage, year, passengers; decimal price; SUV anSUV = new SUV(); anSUV.Make = txtMake.Text; if (int.TryParse(txtMileage.Text, out mileage)) anSUV.Mileage = mileage; else { MessageBox.Show("mileage must be a number"); txtMileage.Clear(); txtMileage.Focus(); } if (int.TryParse(txtPassengers.Text, out passengers)) anSUV.Passengers = passengers; else { MessageBox.Show("passengers must be a number"); txtPassengers.Clear(); txtPassengers.Focus(); } if (int.TryParse(txtYear.Text, out year)) anSUV.ModelYear = year; else { MessageBox.Show("year must be a number"); txtYear.Clear(); txtYear.Focus(); } if (decimal.TryParse(txtPrice.Text, out price)) anSUV.Price = price; else { MessageBox.Show("Price must be a number"); txtPrice.Clear(); txtPrice.Focus(); } Main.suvs.Add(anSUV); txtPassengers.Clear(); txtMake.Clear(); txtMileage.Clear(); txtPrice.Clear(); txtYear.Clear(); }