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. Here is the code I have -  public class ThrowUsedCarException {     public static void main(String[] args) {         // Write your code here     } }     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() {         return vin;     }     public String toString() {         return "VIN " + vin + "  Make: " + make +                "\n   Year: " + year + "  " + mileage + " miles   $" +                price;     } }   public class UsedCarException extends Exception {     public UsedCarException(String s) {         //unsure if typed correctly           super("Wrong information entered");     } }

Database System Concepts
7th Edition
ISBN:9780078022159
Author:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Chapter1: Introduction
Section: Chapter Questions
Problem 1PE
icon
Related questions
Question

This is the question - 

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.

Here is the code I have - 

public class ThrowUsedCarException {
    public static void main(String[] args) {
        // Write your code here
    }
}
 
 
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() {
        return vin;
    }
    public String toString() {
        return "VIN " + vin + "  Make: " + make +
               "\n   Year: " + year + "  " + mileage + " miles   $" +
               price;
    }
}
 
public class UsedCarException extends Exception {
    public UsedCarException(String s) {
        //unsure if typed correctly 
         super("Wrong information entered");
    }
}
Expert Solution
trending now

Trending now

This is a popular solution!

steps

Step by step

Solved in 2 steps

Blurred answer
Knowledge Booster
Exception Handling Keywords
Learn more about
Need a deep-dive on the concept behind this application? Look no further. Learn more about this topic, computer-science and related others by exploring similar questions and additional content below.
Similar questions
Recommended textbooks for you
Database System Concepts
Database System Concepts
Computer Science
ISBN:
9780078022159
Author:
Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:
McGraw-Hill Education
Starting Out with Python (4th Edition)
Starting Out with Python (4th Edition)
Computer Science
ISBN:
9780134444321
Author:
Tony Gaddis
Publisher:
PEARSON
Digital Fundamentals (11th Edition)
Digital Fundamentals (11th Edition)
Computer Science
ISBN:
9780132737968
Author:
Thomas L. Floyd
Publisher:
PEARSON
C How to Program (8th Edition)
C How to Program (8th Edition)
Computer Science
ISBN:
9780133976892
Author:
Paul J. Deitel, Harvey Deitel
Publisher:
PEARSON
Database Systems: Design, Implementation, & Manag…
Database Systems: Design, Implementation, & Manag…
Computer Science
ISBN:
9781337627900
Author:
Carlos Coronel, Steven Morris
Publisher:
Cengage Learning
Programmable Logic Controllers
Programmable Logic Controllers
Computer Science
ISBN:
9780073373843
Author:
Frank D. Petruzella
Publisher:
McGraw-Hill Education