Results 1 to 5 of 5
Thread: Help with scanner method
- 01-26-2013, 05:42 PM #1
Member
- Join Date
- Jan 2013
- Posts
- 10
- Rep Power
- 0
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)); } }
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"); } }
-
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.
- 01-26-2013, 07:20 PM #3
Member
- Join Date
- Jan 2013
- Location
- Texas
- Posts
- 45
- Rep Power
- 0
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
- 01-28-2013, 12:23 AM #4
Member
- Join Date
- Jan 2013
- Posts
- 10
- Rep Power
- 0
-
Re: Help with scanner method
I think that Scanner is about as easy as they come.
Similar Threads
-
cannot find symbol: method Scanner(java.io.InputStream)
By shandog1079 in forum New To JavaReplies: 2Last Post: 03-25-2011, 05:47 AM -
Problem Of Scanner Object with its method nextLine()
By Cluster Storm in forum AWT / SwingReplies: 12Last Post: 06-17-2010, 06:40 PM -
Problem with while loop and the scanner method
By hhh80p in forum New To JavaReplies: 2Last Post: 02-28-2010, 12:47 PM -
[SOLVED] Simple Scanner Method - Plus Sign throwing me off...
By Josh.Hoekstra in forum New To JavaReplies: 2Last Post: 06-02-2008, 11:24 PM -
Using the scanner method
By silvia in forum Advanced JavaReplies: 1Last Post: 08-07-2007, 06:50 AM
Bookmarks