import javax.swing.JOptionPane;
public class ProjectCalculator {
public static void main (String[] args)
{
double firstnum, secondnum, ans;
char operator;
String firstnumStr, secondnumStr;
String operatorStr;
String ansStr;
String msg = "Semi Finals Project for Programming 2";
javax.swing.JOptionPane.showMessageDialog( null, msg );
String msg1 = "Simple Calculator using the switch statement";
javax.swing.JOptionPane.showMessageDialog( null, msg1 );
firstnumStr=
JOptionPane.showInputDialog("Enter the First Number");
firstnum = Double.parseDouble(firstnumStr);
secondnumStr=
JOptionPane.showInputDialog("Enter the Second number");
secondnum = Double.parseDouble(secondnumStr);
operatorStr=
JOptionPane.showInputDialog("Enter the operator to be use");
operator = (char) Double.parseDouble(operatorStr);
if (operator == '+' ) {
System.out.print("You have choosen Addition \n");
ans=firstnum + secondnum;
System.out.print("The sum is = " + ans );
}
else if(operator == '-') {
System.out.print("You have choosen Subtraction \n");
ans=firstnum-secondnum;
System.out.print("The difference is = " + ans );
}
else if(operator == '/'){
System.out.print("You have choosen Division \n");
ans=firstnum/secondnum;
System.out.print("The quotient is = " + ans );
}
else if(operator == '*'){
System.out.print("You have choosen Multiplication \n");
ans=firstnum*secondnum;
System.out.print("The product is = " + ans );
}
else
return;
ansStr = "First Number:" + firstnum + " \n" +
"Second Number:" + secondnum + " \n +" +
"Operator: " + operator + "\n" +
"Solution: " + ans + " \n +";
}
}
Hello guys can you please help me i just cant run this program it says (bellow) I dont know what to change. THank you in advance.
Exception in thread "main" java.lang.NumberFormatException: For input string: "+"
at sun.misc.FloatingDecimal.readJavaFormatString(Unkn own Source)
at sun.misc.FloatingDecimal.parseDouble(Unknown Source)
at java.lang.Double.parseDouble(Unknown Source)
at ProjectCalculator.main(ProjectCalculator.java:30)