Question Create a UsedCarException class thatextends Exception; its constructor receives a value for avehicle identification number (VIN) that is passed to the parentconstructor so it can be used in a getMessage() call.Create a UsedCar class with fields for VIN, make, year,mileage, and price. The UsedCar constructor throwsa UsedCarException when the VIN is not four digits; whenthe make is not Ford, Honda, Toyota, Chrysler, orOther; when the year is not between 1997 and2017 inclusive; or either the mileage or price isnegative.Write an application that establishes an array of at leastseven UsedCar objects and handles any Exceptions.Display a list of only the UsedCar objects that wereconstructed successfully. ThrowUsedCarException.javapublic class ThrowUsedCarException { public static void main(String[] args) { // Write your code here }} UsedCar.java import java.util.*;public class UsedCar { String vin; String make; int year; int mileage; int price; public final static String DEFAULT_VIN = "999"; final int VIN_NUM_LENGTH = 4; final int LOW_YEAR = 1997; final int HIGH_YEAR = 2017; final String[] MAKES = {"Ford", "Honda", "Toyota", "Chrysler", "Other"}; public UsedCar(String num, String carMake, int carYear, int miles, int pr) throws UsedCarException { } public UsedCar() { } public String getVin() { } public String toString() { return "VIN " + vin + " Make: " + make + "\n Year: " + year + " " + mileage + " miles $" + price; }} UsedCarException.java public class UsedCarException extends Exception { public UsedCarException(String s) { }}

TEYV6B The Asker · Computer Science

Create a UsedCarException class that extends Exception; its constructor receives a value for a vehicle identification number (VIN) that is passed to the parent constructor so it can be used in a getMessage() call. Create a UsedCar class with fields for VIN, make, year, mileage, and price. The UsedCar constructor throws a UsedCarException when the VIN is not four digits; when the make is not Ford, Honda, Toyota, Chrysler, or Other; when the year is not between 1997 and 2017 inclusive; or either the mileage or price is negative.

Write an application that establishes an array of at least seven UsedCar objects and handles any Exceptions. Display a list of only the UsedCar objects that were constructed successfully.

ThrowUsedCarException.java

public class ThrowUsedCarException {

public static void main(String[] args) {

// Write your code here

}

}

UsedCar.java

import java.util.*;

public class UsedCar {

String vin;

String make;

int year;

int mileage;

int price;

public final static String DEFAULT_VIN = "999";

final int VIN_NUM_LENGTH = 4;

final int LOW_YEAR = 1997;

final int HIGH_YEAR = 2017;

final String[] MAKES = {"Ford", "Honda", "Toyota", "Chrysler", "Other"};

public UsedCar(String num, String carMake,

int carYear, int miles, int pr) throws UsedCarException {

}

public UsedCar() {

}

public String getVin() {

}

public String toString() {

return "VIN " + vin + " Make: " + make +

"\n Year: " + year + " " + mileage + " miles $" +

price;

}

}

UsedCarException.java

public class UsedCarException extends Exception {

public UsedCarException(String s) {

}

}

More
Community Answer
ISPZMI

//Java Code public class UsedCarException extends Exception {     public UsedCarException(String vin) {         super(vin);     } }   //=============================================== public class UsedCar {     String vin;     String make;     int year;     int mileage;     int price;     public final static String DEFAULT_VIN = "9999";     final int VIN_NUM_LENGTH = 4;     final int LOW_YEAR = 1997;     final int HIGH_YEAR = 2017;     final String[] MAKES = {"Ford", "Honda", "Toyota", "Chrysler", "Other"};     public UsedCar(String vin, String carMake,int carYear, int miles, int pr) throws UsedCarException {         if(vin.length()!=VIN_NUM_LENGTH)             throw new UsedCarException(vin+ " is not four digits.");         else if(!(carMake.equalsIgnoreCase("Ford")||                 carMake.equalsIgnoreCase("Honda")||                 carMake.equalsIgnoreCase("Toyota")||                 carMake.equalsIgnoreCase("Chrysler")||                 carMake.equalsIgnoreCase("Other")))         {             throw new UsedCarException(carMake+" is not valid make....");         }         else if (carYear<LOW_YEAR || carYear>HIGH_YEAR)         {             throw new UsedCarException(carYear+ " must be between "+LOW_YEAR+" and "+HIGH_YEAR);         }         else if(pr<0)         {             throw new UsedCarException(pr+" must be a positive value.");         }         else         {             this.vin = vin;             this.year = carYear;             this.make = carMake;             this.mileage = miles;             this.price = pr;         }     }     public UsedCar() {         vin =DEFAULT_VIN;         year =LOW_YEAR;         make ="";         mileage =0;         price =0;     }     public String getVin() {         return vin;     }     public String toString() {         return "VIN " + vin + "  Make: " + make +                 "\n   Year: " + year + "  " + mileage + " miles   $" +                price;     } }   //==================================================== public class ThrowUsedCarException {     public static void main(String[] args) throws UsedCarException {         /**          *  array of at least seven UsedCar objects          */   &#1 ... See the full answer