Results 1 to 5 of 5
Like Tree1Likes
  • 1 Post By Fubarable

Thread: Help with scanner method

  1. #1
    kormath is offline Member
    Join Date
    Jan 2013
    Posts
    10
    Rep Power
    0

    Default Help with scanner method

    To start off, I'm trying to write a simple java program to catch the keyboard input and display a result for a school assignment. I know, I say school and everyone thinks I want them to write the program for me. Not the case here, I have the program written, but i'm getting an error I don't know how to fix.

    I'm using NetBeans IDE 7.2.1 creating a java project to calculate the annual commission of a salesman.

    I tried using some examples from the college text, the lines I wrote read:

    //Scanner used to catch keyboard input
    Scanner keyboard = new Scanner(System.in);

    When i did that NetBeans made another class called scanner.java and when I test the program i get this error:
    run:
    What are the total sales?
    Exception in thread "main" java.lang.UnsupportedOperationException: Not yet implemented
    at comp.Scanner.nextDouble(Scanner.java:19)
    at comp.comp.main(comp.java:27)
    Java Result: 1
    BUILD SUCCESSFUL (total time: 0 seconds)

    Scanner.java line 19 reads - throw new UnsupportedOperationException("Not yet implemented"); and I don't know why that was created.
    comp.java line 27 reads - sales = keybaord.nextDouble ();

    Here is the comp.java program:

    Java Code:
    /*
     * To change this template, choose Tools | Templates
     * and open the template in the editor.
     */
    package comp;
    
    /**
     *
     * @author Tracy
     */
    public class comp {
    
        /**
         * @param args the command line arguments
         */
        public static void main(String[] args) {
            // TODO code application logic here
    
       double sales; //To hold the sales numbers
       double salary = 60000;
       double commission = 0.025;
       
       //Scanner object catches keyboard input
       Scanner keyboard = new Scanner(System.in);
       
       //Get the sales numbers
       System.out.println("What are the total sales? ");
       sales = keyboard.nextDouble ();
       
       //Equation for the annual commission is 60k + .025 x S (where S = Sales).
       double result = salary + (commission * sales);
       
       //Display shown for annual commission
       System.out.println("The annual commision for the salesman is " + Double.toString(result)); 
            }
    }
    And the scanner.java that NetBeans created:
    Java Code:
    /*
     * To change this template, choose Tools | Templates
     * and open the template in the editor.
     */
    package comp;
    
    import java.io.InputStream;
    
    /**
     *
     * @author Tracy
     */
    class Scanner {
    
        public Scanner(InputStream in) {
        }
    
        double nextDouble() {
            throw new UnsupportedOperationException("Not yet implemented");
        }
        
    }
    Any help would be appreciated.

  2. #2
    Fubarable's Avatar
    Fubarable is offline Moderator
    Join Date
    Jun 2008
    Posts
    19,315
    Blog Entries
    1
    Rep Power
    26

    Default Re: Help with scanner method

    NetBeans only made the Scanner class when you told it to. It in fact told you that it could not find Scanner because you didn't provide an import statement to the core Java class, java.util.Scanner. Since it could not tell what class you meant, it suggested creating a new class called Scanner, but that's the wrong way to go about solving this. Delete that class and all traces of it, and instead add the critical import to your original program so that you can use the core class.
    wfsteadman likes this.

  3. #3
    wfsteadman is offline Member
    Join Date
    Jan 2013
    Location
    Texas
    Posts
    45
    Rep Power
    0

    Default Re: Help with scanner method

    I agree with Fubarable. In the examples you looked at, look near the top of the code and you might see some of the imports he speaks of. Remember you are using a Class that was created by Java already so you have to get it into the application you are building, hence the import.

    Happy Coding
    Wally

  4. #4
    kormath is offline Member
    Join Date
    Jan 2013
    Posts
    10
    Rep Power
    0

    Default Re: Help with scanner method

    Quote Originally Posted by wfsteadman View Post
    I agree with Fubarable. In the examples you looked at, look near the top of the code and you might see some of the imports he speaks of. Remember you are using a Class that was created by Java already so you have to get it into the application you are building, hence the import.

    Happy Coding
    Wally
    Thanks guys, I'll go back to the books and see if i can find more references to this scanner class.

    Is there an easier way to capture the keyboard input and use it in the equation to produce the desired results?

  5. #5
    Fubarable's Avatar
    Fubarable is offline Moderator
    Join Date
    Jun 2008
    Posts
    19,315
    Blog Entries
    1
    Rep Power
    26

Similar Threads

  1. cannot find symbol: method Scanner(java.io.InputStream)
    By shandog1079 in forum New To Java
    Replies: 2
    Last Post: 03-25-2011, 05:47 AM
  2. Problem Of Scanner Object with its method nextLine()
    By Cluster Storm in forum AWT / Swing
    Replies: 12
    Last Post: 06-17-2010, 06:40 PM
  3. Problem with while loop and the scanner method
    By hhh80p in forum New To Java
    Replies: 2
    Last Post: 02-28-2010, 12:47 PM
  4. Replies: 2
    Last Post: 06-02-2008, 11:24 PM
  5. Using the scanner method
    By silvia in forum Advanced Java
    Replies: 1
    Last Post: 08-07-2007, 06:50 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •