Java Programming (MindTap Course List)
Java Programming (MindTap Course List)
9th Edition
ISBN: 9781337397070
Author: Joyce Farrell
Publisher: Cengage Learning
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…
Write a program to create a class” Fan “to represents features of a fan as follows:  “Fan “should contain following details fanType, manufacturer, model, isOn.  Use constructor to initialize data members of the Fan class.  Create function on() and off() to switch on and off the fan respectively.  Create a function speedup() is to increase the speed of the fan by 1 if speed of the Fan greater than 5 it should throw a custom exception.  Create another function speeddown() is to decrease the speed of the fan by 1 if speed of the Fan less than 0 it should throw a custom exception.  Make a menu driven program.
Modify the attached code: Create a new class called CalculatorWithMod. This class should be a sub class of the base class Calculator. This class should also have an additional method for calculating the modulo. The modulo method should only be seen at the sub class, and not the base class! Include exception handling for instances when dividing by 0 or calculating the modulo with 0. You would need to use throw, try, and catch. The modulo (or "modulus" or "mod") is the remainder after dividing one number by another.Example: 20 mod 3 equals 2Because 20/3 = 6 with a remainder of 2 Refer also to the attached sample outputs:
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