Question: 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

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!