2.1 Write the definition of a class the represents a Car. Include the definition of these properties: VIN Number, GasLevel, Mileage, and MPG (Miles Per Gallon). Make sure to choose proper data types based on how these properties are used. For example, VIN number, even though a number, but does not need to be defined as Integer.
2.2 Having done the code for the above question, write the code for a Drive method, which accepts a value that represents the number of miles driven. Drive will update the Mileage property, and reduce the GasLevel to be driven based on whether there is enough gas in the tank. If the miles passed require more gas that what is in the tank, drive the car till the tank is empty, and adjust the mileage only by what the actual miles driven were.
2.3 Write another method, PumpGas, which accepts a value that represents the number of gallons pumped. This method updates the GasLevel by adding the value of the argument received to the current GasLevel. What should the data type of the argument be?
2.4 Now design a form and write code for the buttons to create a new car, drive it, and pump goes into it. Values for miles driven and gas gallons may be obtained from the end user via textboxes or Inputboxes. Below is a suggested GUi for the form.
3.1 The car class created in the previous chapter used the GasLevel and MPG properties. Those properties must be changed to ReadOnly. Update the property definitions, and add two constructors for the car class. One that accepts the initial GasLevel and MPG values and another that accepts those in addition to the mileage.
3.2 Adjust the GUI to the car class above, so that you can now kill a car when needed.
3.3 Also adjust the form code so that before a car is driven or pumped with gas, code checks that a car 'has been created'.
3.4 If you hit the create car button, an object of type car will be instantiated. If you hit the button one more time, another object of type car will be created. What will happen to the first created car?
4.1 Using the car code class of chapter 3 exercise, add code that declares and raises an event named LowGas. This event is raised when the gas level reaches 5 or lower.
4.2 On the form side, add code so that when the LowGas event is raised, the event is handled by asking the user to pump gas using static event handling.
4.3 To practice dynamic event handling, implement the handling of the LowGas event using dynamic event handling. Ensure that you remove the handler property.