Java Programming (MindTap Course List)
9th Edition
ISBN: 9781337397070
Author: Joyce Farrell
Publisher: Cengage Learning
expand_more
expand_more
format_list_bulleted
Concept explainers
Question
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.
- Define the constructor
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
- Check “num” is not a digit
- Iterate “x” until it reaches “MALES” length
-
- Check “carMake” is not equal to “MAKES [x]”
- Set the value
- Check “carMake” is not equal to “MAKES [x]”
- 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
- Set the value
- 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
- Define the “main” method
Expert Solution & Answer
Want to see the full answer?
Check out a sample textbook solutionStudents 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:
Chapter 12 Solutions
Java Programming (MindTap Course List)
Knowledge Booster
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
- Write a class named StockPrices . The class constructor should accept an array of stock prices as its argument. The class should have a member function that returns the average of the stock prices. If any stock price in the array is negative or greater than 5000, the class should throw an exception. Demonstrate the class in a program.arrow_forwardCreate a flowchart and modify the code. INSTRUCTION: 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 CODE TO COPY: #include <iostream> using namespace std; class Calculator{public:Calculator(){printf("Welcome to my Calculator\n"); } int addition(int a, int b);int subtraction(int a, int b);int multiplication(int a, int b);float division(int a, int b);}; int Calculator::addition(int a, int b){return (a+b);} int Calculator::subtraction(int a, int b){return (a-b);} int…arrow_forwardProgramming Problem 3 – CycleFileInput Revisit the Cycle class in Module 3. Modify your application such that the properties will be read from a text file called “Cycle.txt”. Directions Examine your application for the class called Cycle. Add an appropriate throws statement in the main method. Create a reference to a File class with the appropriate name of a text file (Cycle.txt). Note: Cycle.txt was created in the previous assignment, CycleFileOutput. In your code, check that the text file does exist. Input the values from the file to memory. Close the file.arrow_forward
- ArgumentException is an existing class that derives from Exception; you use it when one or more of a method’s arguments do not fall within an expected range. Write the application SwimmingWaterTemperature containing a variable that can hold a temperature expressed in degrees Fahrenheit. Within the class, create a method that accepts a parameter for a water temperature and returns true or false, indicating whether the water temperature is between 70 and 85 degrees and thus comfortable for swimming. If the temperature is not between 32 and 212 (the freezing and boiling points of water), it is invalid, and the method should throw an ArgumentException. In the Main() method, continuously prompt the user for data temperature, pass it to the method, and then display the following messages indicating whether the temperature is comfortable, not comfortable, or invalid: X degrees is comfortable for swimming. X degrees is not comfortable for swimming. Value does not fall within the expected…arrow_forwardJava Problem:Create a Class named Bishop. Make sure the class cannot be inherited. If there have already been 5 objects initiated for this class, trying to initiate the 6th object, the constructor will throw a user-defined exception BishopCreationLimitExceeded. This class has an instance method named printObjectNumber which will print the object creation sequence number for the object for which you are calling the method as follows: This Bishop Object number is 3. Here, 3 is the object creation sequence number that is the third call to new Bishop() in your code that initiated the object. The BishopCreationLimitExceeded class sets the exception message (using super call in the constructor) as follows: The maximum number of bishop objects can be 5. You can define instance variables in the Bishop class if you need them.arrow_forwardIn Java Attachedarrow_forward
- JAVA Problem – CycleFileInput Revisit the Cycle class . Modify your application such that the properties will be read from a text file called “Cycle.txt”. Directions Examine your application for the class called Cycle. Add an appropriate throws statement in the main method. Create a reference to a File class with the appropriate name of a text file (Cycle.txt). Note: Cycle.txt was created in the previous assignment, CycleFileOutput. In your code, check that the text file does exist. Input the values from the file to memory. Close the file. public class Cycle { // Declear integer instance variable private int numberOfWheels; private int weight; // Constructer declear class public Cycle(int numberOfWheels, int weight ) { this.numberOfWheels = numberOfWheels; this.weight = weight; } // String method for output public String toString() { String wheel = String.valueOf(this.numberOfWheels); String load = String.valueOf(this.weight); return("No of wheels in cycle = " +…arrow_forwardwrite a java programme: Vehicle class:First create an abstract Vehicle class that contains code common to all of the vehicles.1. Vehicle class has a color, IDnumber, and a model.2. Throw an exception named “InputNotCorrectException” if the IDnumber is negative.3. The accessor and mutator methods for all three data fields.4. Also include a void wheels() method which is declared abstract. Runnable interface:1.Deaclare an abstract method named HowToRun() which has a return type of void. Car class:Car class is a subclass of Vehicle which implements the Runnable interface.1. Write a class called Car which extends the Vehicle class and implements the Runnable interface.2. Override the equals method in the Object class. Two Car objects are equal if their models are thesame.3. In the Car class override the wheels() method to display “A car has four wheels”.4. A method named toString() that returns a string description for the car.5. Override the HowToRun() method to display “A car runs with…arrow_forwardDEBUG Exercise 1. // This file defines the Patient class used by// a doctor's office. The Patient class has two// overloaded constructors -- a default constructor,// and one that requires an ID number and full name.// A demonstration program declares two Patient objects.class Patient Declarations private string idNum private string lastName private string firstName private Patient() idNum = "0000" lastName = "XXXX" firstName = "XXXX" return public Patient(num id, string last, string first) this.id = id lastName = last firstName = first return public string display() output "Patient #", idNum, lastName, firstName returnendClass start Declarations Patient patient1 Patient patient2("234", "Lee", "Lydia") patient1.display() patient2.display()stop DEBUG Exercise 2arrow_forward
- in python languagearrow_forwardCreate a class SocialEvent with 3 attributes: Event title,date, for simplicity, we won’t restrict the date to a specific format andnumber of attendees..The class should contain a constructor (__init__ method), accessor and mutator methods (getters and setters), and a __str__ method.In the same file, write a main function that prompts the user to input 3 events. The function outputs the events sorted by number of attendees.arrow_forwardCreate a class MyTime which has the datamembers as follows: 1. hour: integer (1 to 12)2. minute: integer (0 to 59)3. second: integer (0 to 59)4. pm: bool variable. True means PM time and false means AM time. Implement a default constructor, a parameterized constructor and a copy constructor. Write set and get functions for all the four members of the class. Overload these operators: 1. Extraction operator >> : Prompt the user for hours, minutes, seconds and for am/pm and initialize the structure. Left operand istream object and right operand MyTime2. Assignment = : Assign the right object to the left object. Both operands are of type MyTime.3. Insertion << : Print the time in the format HH:MM SS PM. Left operand of type ostream and right operand of type MyTime. this in c++.arrow_forward
arrow_back_ios
SEE MORE QUESTIONS
arrow_forward_ios
Recommended textbooks for you
- EBK JAVA PROGRAMMINGComputer ScienceISBN:9781337671385Author:FARRELLPublisher:CENGAGE LEARNING - CONSIGNMENTMicrosoft Visual C#Computer ScienceISBN:9781337102100Author:Joyce, Farrell.Publisher:Cengage Learning,C++ Programming: From Problem Analysis to Program...Computer ScienceISBN:9781337102087Author:D. S. MalikPublisher:Cengage Learning
EBK JAVA PROGRAMMING
Computer Science
ISBN:9781337671385
Author:FARRELL
Publisher:CENGAGE LEARNING - CONSIGNMENT
Microsoft Visual C#
Computer Science
ISBN:9781337102100
Author:Joyce, Farrell.
Publisher:Cengage Learning,
C++ Programming: From Problem Analysis to Program...
Computer Science
ISBN:9781337102087
Author:D. S. Malik
Publisher:Cengage Learning