Problem regarding the exception handling

Assignment Help Basic Computer Science
Reference no: EM13829431


Exception Handling

First, create three exception classes named NumberHighException, NumberLowException, and NumberNegativeException. Both NumberHighException and NumberLowException should be directly subclassed from the Exception class, but NumberNegativeException should be subclassed from NumberLowException. You can use the BadDataException class that was defined in this module as the model for your exception classes.

Next create a class called Verify that will be used to validate that a number is within a specified range. It should have one constructor that has two int parameters. The first parameter is the minimum number in the range, and the second parameter is the maximum number in the range.

In addition to the constructor, the Verify class should have one method that is named validate. The validate method should have a single parameter of data type int. The parameter contains the number that is being validated. If the value of the parameter is less than zero, the method should throw a NumberNegativeException. If the value is less than the minimum value of the range, it should throw a NumberLowException. If the value is greater than the maximum value of the range, it should throw a NumberHighException. If the value is within the specified range, no exception should be thrown.

Once all of these classes are created, create the driver class called Program5. The driver class should instantiate a Verify object with a range of 10 to 100. It should then do the following:

  • Prompt the user to input a number within the specified range.
  • Use a Scanner to read the user input as an int. You can ensure that an int was entered because the nextInt method throws an InputMismatchException if any non-digits are entered.
  • Call the validate method to validate that the number is within the range.
  • Print an appropriate error message if the value is not within the range, or print the value if it is within the range.

You may use any Java IDE you choose to develop your source code, compile and link your code, and execute your program (jGRASP is recommended). Or you may use the Windows Command Prompt.


This question is from Computer Science and it explains about writing a program in Java upon Exception handling which comprises negative number exception, high number exception, low number exception, input mismatch exception, etc.

Reference no: EM13829431

Specify the values for the resistors and capacitor

Specify the values for the resistors and capacitor for a first-order Butterworth lowpass op-amp filter with a dc gain of unity, a corner frequency of 12 kHz, and a dc input

The average number of bookings for each type of room

Guest (guestNO, guestName, guestAddress)Question:  How do I write an SQL Query (mysql) that would give me  "the average number of bookings for each type of room?"

Description of the procedural steps

Describe the steps you took to use each function. Explain when each function would be useful. Submit a copy of original document and amended document you created together wi

Difference between an full clone and a linked clone

Please complete the review questions below. Write in complete sentences and be as detailed as possible. Explain the difference between an full clone and a linked clone List th

Write a program that reads from the external file

write a program that reads from the external file input.txt, counts the letters in every word , replaces the word by that number and then writes the numbers to an external f

Type of fuel should you mix

Suppose a car can run on ethanol and gas and you have a 15 gallons tank to fill. You can buy fuel that is either 30 percent ethanol or 80 percent ethanol. How much of each t

What is the eirp in the direction of maximum antenna gain

A transmitter has an output power of 50 W. It is connected to its antenna by a feedline that is 25 meters long and properly matched. The loss in the feedline is 5 dB/100 m.

Relationship of the corporate strategy to the it alignment

What is the relationship of the corporate strategy to the IT alignment of that strategy? Should the corporate strategy determine the IT alignment, or should the strategy sup


Write a Review

Free Assignment Quote

Assured A++ Grade

Get guaranteed satisfaction & time on delivery in every assignment order you paid with us! We ensure premium quality solution document along with free turntin report!

All rights reserved! Copyrights ©2019-2020 ExpertsMind IT Educational Pvt Ltd