Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.util.Scanner;
- public class Program5 {
- public static void main(String[] args) {
- // The driver class should instantiate a Verify object with a range of 10 to 100.
- Verify verify = new Verify(10, 100);
- //It should then do the following:
- //Prompt the user to input a number within the specified range.
- System.out.print("Input a number between 10-100 inclusive: ");
- // Use a Scanner to read the user input as an int.
- Scanner input = new Scanner(System.in);
- int num = Integer.parseInt(input.nextLine());
- try {
- //Call the validate method to validate that the number is within the range.
- Verify.validate(num);
- //print the value if it is within the range.
- System.out.println("Number entered: " + num);
- } catch (NumberNegativeException ex) {
- //Print an appropriate error message if the value is not within the range,
- System.out.println(ex.getMessage());
- } catch (NumberLowException ex) {
- //Print an appropriate error message if the value is not within the range,
- System.out.println(ex.getMessage());
- } catch (NumberHighException ex) {
- //Print an appropriate error message if the value is not within the range,
- System.out.println(ex.getMessage());
- } catch (NumberFormatException ex ) {
- System.out.println("You entered bad data." );
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement