• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Tim Cooke
  • Devaka Cooray
  • Ron McLeod
  • Jeanne Boyarsky
Sheriffs:
  • Liutauras Vilda
  • paul wheaton
  • Junilu Lacar
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Piet Souris
  • Carey Brown
  • Tim Holloway
Bartenders:
  • Martijn Verburg
  • Frits Walraven
  • Himai Minh

outside inputs (keyboard)

 
Greenhorn
Posts: 26
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Is this a beginner lesson, on keyboard inputs? ( the key pressed will output a code, e.g. press letter "A" would output number 1 if coded to output 1.)

Also, how do I use operators to create a value to be used for another object without printing out the value yet? e.g [ X = (3-2 = ??) ] then X would be used later on.

hope this is clear. I hope to make sort of a calculator project with keyboard.
 
Ranch Hand
Posts: 492
Firefox Browser VI Editor Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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,
Hunter
 
Tim Hoang
Greenhorn
Posts: 26
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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?


was that clear? Thank You for responding

 
Ranch Hand
Posts: 276
Netbeans IDE Chrome Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
 
Hunter McMillen
Ranch Hand
Posts: 492
Firefox Browser VI Editor Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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,
Hunter
 
Tim Hoang
Greenhorn
Posts: 26
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
 
Sheriff
Posts: 14691
16
Eclipse IDE VI Editor Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

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.
 
Marshal
Posts: 76862
366
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
And avoid the read() method. It is awkward to use.
 
Rototillers convert rich soil into dirt. Please note that this tiny ad is not a rototiller:
the value of filler advertising in 2021
https://coderanch.com/t/730886/filler-advertising
reply
    Bookmark Topic Watch Topic
  • New Topic