Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Need some help on the following problem in java. I have to modify the code I written so far(below) to do the following three things:

Need some help on the following problem in java. I have to modify the code I written so far(below) to do the following three things:

a). Write a method called diagnostics that occasionally throws any one of the exceptions you have created depending on the values generated by a random-number generator.

b). Write a method called display that calls diagnostics and provides exception handlers to display a message when an exception occurs. Otherwise, if an exception does not occur, method display should print out "Diagnostic test completed--no problem found."

c). Suppose that the display method contains three catch clauses with parameter types: FootBrakeException, BrakeException, and Exception. Explain which orders of the catch blocks would prevent the execution of an exception handler.

//code

public class AutoExceptions { class NoStartException extends Exception { public NoStartException() { this("No Start Exception"); } public NoStartException(String message) { super(message); } class BadIgnitionException extends NoStartException{ public BadIgnitionException() { this("Bad Ignition Exception"); } public BadIgnitionException(String message) { super(message); }} class DeadBatteryException extends NoStartException{ public DeadBatteryException() { this("Dead Battery Exception"); } public DeadBatteryException(String message) { super(message); } } } class LightsException extends Exception { public LightsException() { this("Lights Exception"); } public LightsException(String message) { super(message); } class HeadLightException extends LightsException{ public HeadLightException() { this("Head Light Exception"); } public HeadLightException(String message) { super(message); }} class BrakeLightException extends LightsException{ public BrakeLightException() { this("Brake Light Exception"); } public BrakeLightException(String message) { super(message); } } class TailLightException extends LightsException{ public TailLightException() { this("Tail Light Exception"); } public TailLightException(String message) { super(message); } } } class BrakeException extends Exception { public BrakeException() { this("Brake Exception"); } public BrakeException(String message) { super(message); } class FootBrakeException extends BrakeException{ public FootBrakeException() { this("Foot Brake Exception"); } public FootBrakeException(String message) { super(message); }} class ParkingBrakeException extends BrakeException{ public ParkingBrakeException() { this("Parking Brake Exception"); } public ParkingBrakeException(String message) { super(message); } } } }

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Students also viewed these Databases questions