Text Input Java Calculator Help
Very new programmer here... 4 days in now.
I know i was hoping for something that might work to sovle this problem, but it didnt. What I need to do is make it so the user can type in an expression (ie: "1 + 1", "2 - 1", "1 * 1", "2 / 1") and my program will recognize the expressions and perform the calculation... To my knowlege the part that makes no sence is the "if", "else if" statement part, but I did try! :)
Please Help!!
/**
*The CalculatorApp class reads the users input and calculates primitive
*arithmetic expressions.
*
*Author: Evan Cristofori
*Date: 02/21/07
*
*/
import java.io.*;
import java.util.*;
class CompoundCalculator {
public static void main(String[] args)
throws java.io.IOException {
String inputString;
String s1, s2, s3;
double num1, num2, num3, result;
InputStreamReader isr = new InputStreamReader(System.in);
BufferedReader br = new BufferedReader(isr);
System.out.println("What do you want to compute? ");
inputString = br.readLine();
StringTokenizer st = new StringTokenizer(inputString);
s1 = st.nextToken();
s2 = st.nextToken();
s3 = st.nextToken();
num1 = Double.parseDouble(s1);
num2 = Double.parseDouble(s2);
num3 = Double.parseDouble(s3);
if (num2 = "+")
result = num1 + num3;
else if (num2 = "-")
result = num1 - num3;
else if (num2 = "*")
result = num1 * num3;
else if (num2 = "/")
result = num1 / num3;
System.out.println("The result is: " + result);
}
}
The error I get is incompatible types @ line 33, 35 (listed twice), 37 (listed twice), and 39 (listed twice).
Thanks

