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

Given the following class: public class Vehicle { protected String manufacturer;

ID: 3910307 • Letter: G

Question

Given the following class:

public class Vehicle
{
protected String manufacturer; // vehicle manufacturer
protected int year; // model year
protected char fuelType; // G = gas, E = electric, D = diesel, W = wind, U = unknown
protected String VIN; // an String to hold the 17 characters of the vehicle's VIN number.

... // no-arg constructor defined, as are all get/set methods.

}

Write me:

An overloaded constructor (takes the four data members as parameters): assume that a custom exception class called InvalidVINException exists. Your constructor will test to ensure that the first character of the VIN is a digit, if not through an exception. Will also test to ensure that the VIN is exactly 17 characters in length, if not through an exception. Both exceptions must have a custom message.

a copy constructor, and

an equals method.

a toString method

please i need the answer in java language

Explanation / Answer

import java.util.Objects; public class Vehicle { protected String manufacturer; // vehicle manufacturer protected int year; // model year protected char fuelType; // G = gas, E = electric, D = diesel, W = wind, U = unknown protected String VIN; // an String to hold the 17 characters of the vehicle's VIN number. public Vehicle(String manufacturer, int year, char fuelType, String VIN) throws InvalidVINException { if(!Character.isDigit(VIN.charAt(0))) { throw new InvalidVINException("First VIN character is not a digit"); } else if(VIN.length() != 17) { throw new InvalidVINException("VIN is not of length 17"); } this.manufacturer = manufacturer; this.year = year; this.fuelType = fuelType; this.VIN = VIN; } public Vehicle(Vehicle vehicle) { this.manufacturer = vehicle.manufacturer; this.year = vehicle.year; this.fuelType = vehicle.fuelType; this.VIN = vehicle.VIN; } @Override public boolean equals(Object o) { if (this == o) return true; if (o == null || getClass() != o.getClass()) return false; Vehicle vehicle = (Vehicle) o; return year == vehicle.year && fuelType == vehicle.fuelType && manufacturer.equals(vehicle.manufacturer) && VIN.equals(vehicle.VIN); } @Override public String toString() { return "Vehicle{" + "manufacturer='" + manufacturer + ''' + ", year=" + year + ", fuelType=" + fuelType + ", VIN='" + VIN + ''' + '}'; } }

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote