Question: 1. Create classes that will be used to compare the use of static and instance variables. a. Create a new package named vehicles. b. Create
1. Create classes that will be used to compare the use of static and instance variables.
a. Create a new package named vehicles.
b. Create and implement the following concrete class:
i. Create a class named Vehicle.
ii. Create your static variables as follows:
a. A public static String variable named MAKE with a value of Augur.
b. A public static int variable named numVehicles with an initial value of 0.
iii. Create your instance variables as follows:
a. A private String variable named ChassisNo.
b. A private String variable named model.
iv. Create a constructor that takes a single formal parameter of type String named model. The constructor should execute the following tasks:
a. Increment the value of the static variable numVehicles by one.
b. Set the value of the instance variable chassisNo equal to the concatenation of ch with the
value held by numVehicles.
c. Set the instance variable model equal to the value of the parameter model (hint: you will have
to use this here).
d. Have the constructor display a message that states Vehicle manufactured.
v. Implement two pairs of getter and setter methods that will allow you to get and set the values of the two instance variables.
c. Create and implement the following driver class:
i. Create a class named TestVehicle.
ii. Create a static main method that tests the following:
a. Using the value of the static variable MAKE create the following output message:
Manufacturer: Augur
b. Using the value of the static variable numVehicles create the following output message:
Number of vehicles manufactured:
iii. Run your program! You will see that the values that are identified as static are created at runtime and can therefore be accessed.
iv. In your main method use the chassisNo variable to create the following output message:
The chassis number is chassisNo.
v. Run your program! You will see that the program will not run. This is because we havent yet created an instance (object) of the Vehicle class.
vi. In your main method create a vehicle object named vehicle1 above the output statement for the chassis number.
vii. Update the chassis number output statement to use dot notation to identify which vehicles chassis we want to see (use vehicle1).
viii. Run your program! You will see that the program now shows both the static and the instance variables.
ix. Update the existing code to also show the model of the car.
x. Create a second vehicle (named vehicle2, use Edict as the parameter for the constructor) and display the instance variables of that object.
xi. Create a toString() method in the Vehicle class that will display the vehicles make, model and chassis
number to screen using a different line for each output statement.
xii. Display the contents of the vehicle in your main method by using the toString() method.
xiii. Add a final output method that will display the total number of cars manufactured.
The output of the program should look like this:
Manufacturer: Augur
Number of vehicles manufactured: 0
Vehicle manufactured
The vehicle is manufactured by: Augur
The model type is Vision
The chassis number is ch1
Vehicle manufactured
The vehicle is manufactured by: Augur
The model type is Edict
The chassis number is ch2
Number of vehicles manufactured: 2
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
