Java basic help...how to assign a +/-/* and / to a char variable?

MpX730

n00b
Joined
Jul 22, 2006
Messages
5
Hi,

I am a freshman in college and I'm not looking to take the easy way out but I just need a command or some line to complete my homework. I need to make a program that will allow a user to add/subtract/multiply/divide two floating point values through JOptionPane Input dialogs. I know how to do everything except how to take in a + - / or * that the user inputs. So when the input dialog comes up to enter in the character/operation, I don't know how to assign it to a char variable etc. Please help! thanks!
 
For input from the command line, I would look into classes derived from InputStream. If you are using GUI programming, most objects have member functions to grabs their "contents".

I would suggest looking here:
http://java.sun.com/j2se/1.5.0/docs/api/
in particular:
http://java.sun.com/j2se/1.5.0/docs/api/javax/swing/JComponent.html

but it dependends what GUI components you use and I don't have much experience with that.

For example, if you had a JSlider component, you'd be able to get the value by calling the getValue() funciton of the component.
 
thanks for the help but I couldn't find it. Basically I'm having an Input Dialog pop up to the user to enter either + - * /. The problem I'm havinng is that I cannot store that value. I plan on taking that value as a string and converting it to a char so that I can use it in a switch statement.
 
I am confused. I couldn't find an InputDialog class or anything similar. Can you post the source code or at least the parts that are relevant this this?
 
u need to

import javax.swing.JOptionPane;

then to have an input dialog box come up you write:

String = JOptionPane.showInputDialog( "What the user will read" );
 
The JOptionPane.showInputDialog() methods all return Strings or Objects. One would assume that this return is your input. So... what is it returning? Is anything being assigned to your String?

As a last resort, you might find it in the inputValue variable, but there must be a better way than that...
 
Back
Top