THINK FIRST·CODE LATER

← All labs

TripComputer: throwing and multi-catch

Problem

Write averageSpeed(double distance, double hours) that rejects a negative distance with an IllegalArgumentException and zero hours with an ArithmeticException, and a main that calls it three times, each call inside its own try with a multi-catch clause and a finally.

Write it here or in your IDE, then paste it. Compile and test it yourself before comparing. Your code stays in your browser — it is never sent to or stored on the server.