EBK JAVA PROGRAMMING
EBK JAVA PROGRAMMING
9th Edition
ISBN: 9781337671385
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
Java question Write a Thermostat class such that a user of the Thermostat class can create an objectof Thermostat and set it to the desired temperature within a pre-specified range. If theuser tries set the temperature outside this range it should throw a TemperatureTooHighor TemperatureTooLow exception. Use inheritance to create an exception superclassTemperatureOutofRange and subclasses TemperatureTooHigh andTemperatureTooLow.Sample Tester code:Thermostat t = new Thermostat(0, 100);t. setTemp(50); // Should be OK.t.setTemp(150); // Should throw TemperatureTooHigh exception.t.setTemp(-50); // Should throw TemperatureToolLow exception.Write a Tester class to demonstrate throwing and catching of exceptions. Show that thecatch specifying the superclass catches the subclass exceptions. The order of exceptionhandlers is important. If you try to catch a superclass exception type before a subclasstype, the compiler would generate errors. Also show the re-throwing of exceptions.
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…
Develop an exception class named InvalidMonthException that extends the Exception class.   Instances of the class will be thrown based on the following conditions: The value for a month number is not between 1 and 12 The value for a month name is not January, February, March, … December Develop a class named Month.  The class should define an integer field named monthNumber that holds the number of a month.  For example, January would be 1, February would be 2, and so forth.  In addition, provide the following methods: A no-argument constructor that sets the monthNumberto 1. An overloaded constructor that accepts the number of the month as an argument.  The constructor should set the monthNumberfield to the parameter value if the parameter contains the value 1 – 12.  Otherwise, throw an InvalidMonthException exception back to the caller.  The exception should note that the month number was incorrect. An overloaded constructor that accepts a string containing the name of the month,…
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