Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

JAVA 1. Create a class named Vehicle. A vehicle has a VIN number, which is compo

ID: 3712817 • Letter: J

Question

JAVA

1. Create a class named Vehicle. A vehicle has a VIN number, which is composed of digits and letters. a. Create a one argument Constructor that initializes the class variable Vin number. b. Create an accessor method for the Vin number. c. Create a toString method. The method header is String toString(). The toString method returns the VIN number. 2. Create a class MotorCycle. a. MotorCycle is a sub class of Vehicle. b. MotorCycle has class variables for i. Number of wheels ii. Weight. c. Create accessor and mutator methods for each class variable. d. Create any Constructors that you think are necessary. Use the super keyword in the MotorCycle constructor to call the Vehicle one argument constructor, passing the value of the VIN number. Consider creating a three argument MotorCycle constructor having inputs of VIN number, number of wheels and weight. e. Override the toString method. MotorCycles toString returns a String containing the VIN Number, number of wheels and weight. 3. Create a main method. a. Instantiate a MotorCycle, having VIN number 123NC, two wheels, and weight 1500.0 pounds. b. Call the MotorCycle toString method and display VIN number, number of wheels and weight.

Explanation / Answer

Hi here is the java program

// You can place these two classess in one file and execute

class Vehicle {

       // Class variable

       private String VINNumber;

      

       // Class one argument constructor

       public Vehicle(String VIN) {

              //Initialize class variable

              VINNumber = VIN;

       }

      

       //Accessor method for VIN number

       public String getVinNumber() {

              return VINNumber;

       }

      

       //toString method which returns VINNumber

       @Override

       public String toString() {

              return VINNumber;

       }

}

class MotorCycle extends Vehicle{

      

       // Class variables

       private int numberOfWheels;

       private double weight;

      

       //Accessor method for class variable numberOfWheels

       public int getNumberOfWheels() {

              return numberOfWheels;

       }

      

       //Accessor method for class variable weight

       public double getWeight() {

              return weight;

       }

      

       //Mutator method for numberOfWheels

       public void setNumberOfWheels(int wheels) {

              numberOfWheels = wheels;

       }

      

       // Mutator method for weight

       public void setWeight(double weight) {

              this.weight = weight;

       }

      

       //Necessary Constructor. It should call the super class constructor

       public MotorCycle(String VIN){

              // Calls the super class constructor

              // It is must as aruguments based super class constructor should be called in derived class

              super(VIN);

       }

      

       // 3 argument constructor

       public MotorCycle(String VIN, int wheels, double weight) {

              // set the class variables

              super(VIN);   //Calling super class constructor

              // Setting class variables

              numberOfWheels = wheels;

              this.weight = weight;

             

       }

      

       //overriding toString() method which returns

       // VIN number, No.of Wheels and weight.

       @Override

       public String toString() {

              //calling super class method

              return "VIN Number: " + super.getVinNumber()

                           + " No of Wheels: " + numberOfWheels

                           + " Weight: " + weight + " pounds";

       }

      

      

       // main method.

       public static void main(String[] args) {

              // Instantiate the MotorCycle Class

              MotorCycle mc = new MotorCycle("123NC", 2, 1500.0);

             

              // Calling Motor Cycle toString Method to display the vehicle info                      

              System.out.println(mc.toString());

       }

}

===============================================================

Output Generated:

VIN Number: 123NC
No of Wheels: 2
Weight: 1500.0 pounds