Welcome to the Java Programming Forums


The professional, friendly Java community. 21,500 members and growing!


The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


>> REGISTER NOW TO START POSTING


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 3 of 3

Thread: Java Error

  1. #1
    Junior Member
    Join Date
    Mar 2014
    Posts
    1
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Default Java Error

    Hi I am trying to complete this code for a class and I am very new to programming, so sorry if it is a silly question, but I think I have most of the code, just am I forgetting a semicolon or something? I can't get this to compile.

     
    import java.util.InputMismatchException;
    import java.util.Scanner;
     
     
    /*
    the driver class called Program5  
     */
    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:
     
            // Use a Scanner to read the user input as an int.
            Scanner input = new Scanner(System.in);
     
            int num = 0;
            boolean good = true;
            //You can ensure that an int was entered because the nextInt method
            //in the validate class throws an InputMismatchException if any non digits are entered.
            do {
                 good = true;
                try {
                    //Prompt the user to input a number within the specified range.
                    System.out.print("Input a number between 10-100 inclusive: ");
                    num = input.nextInt();
                } catch (InputMismatchException ex) {
                     input = new Scanner(System.in);
                    System.out.println("Please enter numeric integer value.");
                    good = false;
                }
            } while (!good);
     
            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());
            }
     
        }
    }


  2. #2
    Member
    Join Date
    Feb 2014
    Posts
    180
    Thanks
    0
    Thanked 48 Times in 45 Posts

    Default Re: Java Error

    It's missing the code for the following classes:
    • Verify
    • NumberNegativeException
    • NumberLowException
    • NumberHighException

    Btw, next time for a post similar to this where the code doesn't compile, please include the error output from running javac or from the IDE.

  3. The Following User Says Thank You to jashburn For This Useful Post:

    ITS123456 (March 19th, 2014)

  4. #3
    Super Moderator
    Join Date
    Jun 2013
    Location
    So. Maryland, USA
    Posts
    4,739
    My Mood
    Mellow
    Thanks
    172
    Thanked 622 Times in 609 Posts

    Default Re: Java Error

    Welcome to the forum! Thanks for taking the time to learn how to post code correctly. If you haven't already, please read this topic to learn other useful info for new members.

Similar Threads

  1. Replies: 1
    Last Post: January 17th, 2013, 06:04 AM
  2. Replies: 0
    Last Post: July 2nd, 2012, 09:11 PM
  3. Java error
    By Dsoto in forum What's Wrong With My Code?
    Replies: 3
    Last Post: November 18th, 2011, 02:25 AM
  4. Java Error cannot be applied to (java.lang.String), phone book entry program.
    By iceyferrara in forum What's Wrong With My Code?
    Replies: 5
    Last Post: September 23rd, 2011, 06:32 AM
  5. [SOLVED] Java run time error: 'java.lang.NullPointerException"
    By ChandanSharma in forum What's Wrong With My Code?
    Replies: 9
    Last Post: June 20th, 2011, 11:53 AM