EBK JAVA PROGRAMMING
EBK JAVA PROGRAMMING
8th Edition
ISBN: 9781305480537
Author: FARRELL
Publisher: CENGAGE LEARNING - CONSIGNMENT
bartleby

Concept explainers

Question
Book Icon
Chapter 12, Problem 7PE
Program Plan Intro

Display list

Program plan:

Filename: “UsedCarException.java”

  • Define “UsedCarException” class which extends from “Exception” class
    • Define the constructor
      • Call the super method.

Filename: “UsedCar.java”

  • Define the “UsedCar” class
    • Declare the required variables and set the values
    • Define the default constructor
      • Set the values
    • Define the parameterized constructor
      • Set the values
      • Check “num” length is not equal to “VIN_NUM_LENGTH”
        • Set the value
          • Iterate “x” until it reaches “num” length
            • Check “num” is not a digit
              • Set the value
          • Iterate “x” until it reaches “MALES” length
            • Check “carMake” is not equal to “MAKES [x]”
              • Set the value
          • Check “isGoodMake” is false
            • Set the value
          • Check “carYear” is less than “LOW_YEAR” or greater than “HIGH_YEAR or “miles” less than 0 or “pr” less than 0
            • Set the value
          • Check “isBad” is true
            • Throw an exception
          • Set the values
    • Define the “getVin” method
      • Set the values
    • Define the “toString” method
      • Return the values.

Filename: “ThrowUsedCarException.java”

  • Define the class “ThrowUsedCarException”
    • Define the “main” method
      • Create an object for “UsedCar” class
      • Declare the variables and set the required values to the variables
      • Iterate “for” loop until it reaches length of the “UsedCar”
        • Set the values to the object
      • Iterate “for” loop until it reaches length of the “UsedCar”
        • In “try” block, set the values
        • In “catch” block, display the course and error
      • Display the course values

Blurred answer
Students have asked these similar questions
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…
Create a CourseException class that extends Exception and whose constructor receives a String that holds a college course’s department (for example, CIS), a course number (for example, 101), and a number of credits (for example, 3). Save the file as CourseException.java. Create a Course class with the same fields and whose constructor requires values for each field. Upon construction, throw a CourseException if the department does not consist of three letters, if the course number does not consist of three digits between 100 and 499 inclusive, or if the credits are less than 0.5 or more than 6. Save the class as Course.java. Write an application that establishes an array of at least six Course objects with valid and invalid values. Display an appropriate message when a Course object is created successfully and when one is not. Save the file as ThrowCourseException.java.
Create a CourseException class that extends Exception and whose constructor receives a String that holds a college course’s department (for example, CIS), a course number (for example, 101), and a number of credits (for example, 3). Save the file as CourseException.java. Create a Course class with the same fields and whose constructor requires values for each field. Upon construction, throw a CourseException if the department does not consist of three letters, if the course number does not consist of three digits between 100 and 499 inclusive, or if the credits are less than 0.5 or more than 6. Save the class as Course.java. Write an application that establishes an array of at least six Course objects with valid and invalid values. Display an appropriate message when a Course object is created successfully and when one is not. Save the file as ThrowCourseException.java.  Modify the CourseException class to extend RuntimeException class and identify the differences.
Knowledge Booster
Background pattern image
Computer Science
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
SEE MORE QUESTIONS
Recommended textbooks for you
Text book image
EBK JAVA PROGRAMMING
Computer Science
ISBN:9781337671385
Author:FARRELL
Publisher:CENGAGE LEARNING - CONSIGNMENT
Text book image
Microsoft Visual C#
Computer Science
ISBN:9781337102100
Author:Joyce, Farrell.
Publisher:Cengage Learning,
Text book image
C++ Programming: From Problem Analysis to Program...
Computer Science
ISBN:9781337102087
Author:D. S. Malik
Publisher:Cengage Learning