#Calculator program

6 messages · Page 1 of 1 (latest)

torn geyser
#

public void actionPerformed(ActionEvent e) {
String s = e.getActionCommand();
String num1="";
String num2="";
String op="";
double tot=0.0;
if(s.charAt(0)>='0'&&s.charAt(0)<='9'||s.charAt(0)=='.')
{
if(op=="")
num1=num1+s;
else
num2=num2+s;
}
else
op=op+s;
if (op.equals("+"))
tot = (Double.parseDouble(num1) + Double.parseDouble(num2));
else if (op.equals("-"))
tot = (Double.parseDouble(num1) - Double.parseDouble(num2));
else if (op.equals("/"))
tot = (Double.parseDouble(num1) / Double.parseDouble(num2));
else
tot = (Double.parseDouble(num1) * Double.parseDouble(num2));

    tf.setText(num1+op+num2+"="+tot);
    //System.out.println(s.charAt(0)+1);
   }
   public static void main(String[] args)
   {
       Frame obj=new Frame();
       obj.calculator();
}

}

elfin orchidBOT
#

This post has been reserved for your question.

Hey @torn geyser! Please use /close or the Close Post button above when you're finished. Please remember to follow the help guidelines. This post will be automatically closed after 300 minutes of inactivity.

TIP: Narrow down your issue to simple and precise questions to maximize the chance that others will reply in here.

torn geyser
#

Please correct this

radiant needle
#

What do you mean, correct? Is it incorrect?

safe pawn
#

What is the problem?