Answer to Question #194028 in Java | JSP | JSF for Bill

Question #194028

 A garden watering valve can measure the volume of water coming out of a hose. A user fixed the valve to allow only 0.015 gallon of water. Create a Java exception class named “UnmatchedVolumeException” which will pass the following messages to a numerical controller.


Table:

Condition: volume > 0.015 ------- Message: Excessive volume.

Condition: volume < 0.015 ------- Message: Insufficient volume.


In the “main” method, take an input of volume. Write a proper Java exception handling code to throw an appropriate exception message. Make sure the output looks similar to the following. [Note: Be sure to use input and output dialog boxes]. Please have the input box ask "Enter the volume:" and have the output box give an output of "Excessive volume."



1
Expert's answer
2021-05-16T17:34:03-0400
public class UnmatchedVolumeException extends RuntimeException{
    public UnmatchedVolumeException(String message){
        super(message);
    }
}

import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);
        System.out.print("Enter the volume: ");
        double volume = in.nextDouble();
        if (volume > 0.015) {
            throw new UnmatchedVolumeException("Excessive volume.");
        } else if (volume < 0.015) {
            throw new UnmatchedVolumeException("Insufficient volume.");
        }
    }
}

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be the first!

Leave a comment

LATEST TUTORIALS
New on Blog
APPROVED BY CLIENTS