This week's book giveaway is in the OCAJP 8 forum. We're giving away four copies of OCA Java SE 8 Programmer I Study Guide and have Edward Finegan & Robert Liguori on-line! See this thread for details.
I'm confused by your question. Are you asking how to determine if a user inputs the letter "A" from the keyboard?
As to your calculator question, you would have to read the value "X = 3 -2" as a string then search through that string to determine 1) what numbers are being used and 2) what operation is being performed, then 3) store the result of that operation in some sort of structure(i.e. an array or list).
Hope this helps,
"If the facts don't fit the theory, get new facts" --Albert Einstein
Joined: Feb 24, 2011
I want to make a keyboard in use. So is there a way to make it interact with the package? Like in order to make a program activate (password), you must type in your keyboard certain values for it to work right. What I wanted to do was use this to create a calculator with a keyboard.
Step 1. Program says (e.g) : put in values
Step 2. I type (keyboard) values: (3) - (2)
Step 3. Program works then outputs: (1)
Will this be a very difficult task for a beginner of 2 months of lessons?
If you want to read keyboard input from the console, first you'll have to get hold of the console's input stream, which you can get by System.in (same to how you'd use System.out to get the output stream of the console), and then you can call read() method on it to read from the screen.
Alternatively you can wrap this InputStream in a BufferedReader via InputStreamReader or in a Scanner for reading directly as String, rather than reading into a byte array.
You can find many examples over the net.
I don't think the actual program will be difficult, the hard part will be understanding how to accomplish this. Whatever you enter from the keyboard will be considered text and thus String input.
So a general way to accomplish this would be:
1) find a way to SCAN the user's input and store it inside a String variable.
2) Use operations in the String class to extract the information you need from the String. (i.e. the numbers and the operator)
3) Output the value of the calculation
I'm not going to go into coding detail, because that is up to you good luck.
hope this helps,
Joined: Feb 24, 2011
Does anyone have any tips on accomplishing the keyboard class? Package? Is there an import on keyboard I could learn about in the JDK . At this point I don't even know what I am saying,but it should be easy once I find info on keyboard.
At this point I don't even know what I am saying,but it should be easy once I find info on keyboard.
Obviously, you don't seem to know what you're saying But everyone has to start. However, I don't think that poking around like that will help you. I'd like to suggest you to get your hands on a good book and start from the start.
If you insist on getting straight to the keyboard thing, check this tutorial on IO. Especially "Scanning" and "I/O from the command line". The Scanner class API also has some examples on how to get data from the standard input.