Advertisement
Guest User

Untitled

a guest
Apr 26th, 2015
180
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.50 KB | None | 0 0
  1. import java.util.Scanner;
  2.  
  3. public class Program5 {
  4.  
  5. public static void main(String[] args) {
  6. // The driver class should instantiate a Verify object with a range of 10 to 100.
  7. Verify verify = new Verify(10, 100);
  8. //It should then do the following:
  9. //Prompt the user to input a number within the specified range.
  10. System.out.print("Input a number between 10-100 inclusive: ");
  11. // Use a Scanner to read the user input as an int.
  12. Scanner input = new Scanner(System.in);
  13. int num = Integer.parseInt(input.nextLine());
  14. try {
  15. //Call the validate method to validate that the number is within the range.
  16. Verify.validate(num);
  17. //print the value if it is within the range.
  18. System.out.println("Number entered: " + num);
  19. } catch (NumberNegativeException ex) {
  20. //Print an appropriate error message if the value is not within the range,
  21. System.out.println(ex.getMessage());
  22. } catch (NumberLowException ex) {
  23. //Print an appropriate error message if the value is not within the range,
  24. System.out.println(ex.getMessage());
  25. } catch (NumberHighException ex) {
  26. //Print an appropriate error message if the value is not within the range,
  27. System.out.println(ex.getMessage());
  28. } catch (NumberFormatException ex ) {
  29. System.out.println("You entered bad data." );
  30. }
  31. }
  32. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement