ali11 -1

ok i replace my swich statment.

[CODE] impo
import java.awt.;
import java.awt.event.
;
import javax.swing.*;

public class Ahsan extends JFrame{
Stack s = new Stack();

private JFrame f;
private JPanel p1,p2;
private static final int ADD = 1;
private static final int SUBTRACT = 2; // declare class constants
private static final int MULTIPLY = 3;
private static final int DIVISION = 4;

private int resultValue=0;
private String previousOp = "=";
private JTextField jtfMain;
private JButton dot,zero,one,two,three,four,five,six,seven,eight,nine,minus,plus,multiply,divide,equal;
String value;

        private dotButtonHandler dotHandler;
        private zeroButtonHandler zeroHandler;
        private oneButtonHandler oneHandler;
        private twoButtonHandler twoHandler;
        private threeButtonHandler threeHandler;
        private fourButtonHandler fourHandler;
        private fiveButtonHandler fiveHandler;
        private sixButtonHandler sixHandler;
        private sevenButtonHandler sevenHandler;
        private eightButtonHandler eightHandler;
        private nineButtonHandler nineHandler;
        private minusButtonHandler minusHandler;
        private plusButtonHandler plusHandler;
        private multiplyButtonHandler multiplyHandler;
        private divideButtonHandler divideHandler;
        private equalButtonHandler equalHandler;

char ch;
Stack cStack=new Stack();
public Ahsan() {

    setSize(400,190);
    setTitle("Reverse Polish Notation Calculator");
    setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    setLayout(new BorderLayout());

    jtfMain = new JTextField("");

    seven = new JButton("7");
    sevenHandler=new sevenButtonHandler();
    seven.addActionListener(sevenHandler);

    eight = new JButton("8");
    eightHandler=new eightButtonHandler();
    eight.addActionListener(eightHandler);

    nine=new JButton("9");
            nineHandler=new nineButtonHandler();
    nine.addActionListener(nineHandler);

    zero=new JButton("0");
    zeroHandler=new zeroButtonHandler();
    zero.addActionListener(zeroHandler);

    one=new JButton("1");
    oneHandler=new oneButtonHandler();
    one.addActionListener(oneHandler);

    two=new JButton("2");
    twoHandler=new twoButtonHandler();
    two.addActionListener(twoHandler);

    three=new JButton("3");
    threeHandler=new threeButtonHandler();
    three.addActionListener(threeHandler);

    four=new JButton("4");
            fourHandler=new fourButtonHandler();
    four.addActionListener(fourHandler);

    five=new JButton("5");
            fiveHandler=new fiveButtonHandler();
    five.addActionListener(fiveHandler);

    six=new JButton("6");
            sixHandler=new sixButtonHandler();
    six.addActionListener(sixHandler);

    minus=new JButton("-");
            minusHandler=new minusButtonHandler();
    minus.addActionListener(minusHandler);

    plus=new JButton("+");
            plusHandler=new plusButtonHandler();
    plus.addActionListener(plusHandler);

    multiply=new JButton("X");

            multiplyHandler=new multiplyButtonHandler();
    multiply.addActionListener(multiplyHandler);

    divide=new JButton("/");
            divideHandler=new divideButtonHandler();
    divide.addActionListener(divideHandler);

    equal= new JButton("=");
                equalHandler = new equalButtonHandler();
                equal.addActionListener(equalHandler);

                dot=new JButton(".");

                                dotHandler=new dotButtonHandler();
    dot.addActionListener(dotHandler);

    p1 = new JPanel();
    p1.setLayout(new GridLayout(1,1));

    p2 = new JPanel();
    p2.setLayout(new GridLayout(5,5));

    p1.add(jtfMain);

    p2.add(divide);
    p2.add(seven);
    p2.add(eight);
    p2.add(nine); ...

ali11 -1

[QUOTE=NormR1;1683508]What do you want the switch statement to do? What case statement do you want executed?
What code decides which case statement should be executed? IE Where is operation given a value?

Why do you have more than one variable named operation?[/QUOTE]
I am using equal button.like if someone put 5 +3= it shows 8 and addition case will be executed..

ali11 -1

[QUOTE=NormR1;1683508]What do you want the switch statement to do? What case statement do you want executed?
What code decides which case statement should be executed? IE Where is operation given a value?

Why do you have more than one variable named operation?[/QUOTE]

I want to use switch statement to perform add,subtract,multiply,division.

ali11 -1

[QUOTE=sirlink99;1682783]try removing the this in the switch statement.[/QUOTE]
so what do you want me to put instead of this in the switch statement.

ali11 -1

so what can i put instead of this in the swith statement

ali11 -1 Light Poster

can somebody help me with switch statement.

[CODE] import java.util.Stack;
import java.awt.;
import java.awt.event.
;
import javax.swing.;
import java.math.
;
import java.util.Vector;

public class Ahsan extends JFrame{
Stack s = new Stack();

private JFrame f;
private JPanel p1,p2;
private final int ADD = 1;
private final int SUBTRACT = 2; // declare class constants
private final int MULTIPLY = 3;

private int operation;
private JTextField jtfMain;
private JButton dot,zero,one,two,three,four,five,six,seven,eight,nine,minus,plus,multiply,divide,equal;
String value,A;

        private dotButtonHandler dotHandler;
        private zeroButtonHandler zeroHandler;
        private oneButtonHandler oneHandler;
        private twoButtonHandler twoHandler;
        private threeButtonHandler threeHandler;
        private fourButtonHandler fourHandler;
        private fiveButtonHandler fiveHandler;
        private sixButtonHandler sixHandler;
        private sevenButtonHandler sevenHandler;
        private eightButtonHandler eightHandler;
        private nineButtonHandler nineHandler;
        private minusButtonHandler minusHandler;
        private plusButtonHandler plusHandler;
        private multiplyButtonHandler multiplyHandler;
        private divideButtonHandler divideHandler;
        private equalButtonHandler equalHandler;

char ch;
Stack cStack=new Stack();
public Ahsan() {

    setSize(400,190);
    setTitle("Calculator");
    setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    setLayout(new BorderLayout());

    jtfMain = new JTextField("");

    seven = new JButton("7");
    sevenHandler=new sevenButtonHandler();
    seven.addActionListener(sevenHandler);

    eight = new JButton("8");
    eightHandler=new eightButtonHandler();
    eight.addActionListener(eightHandler);

    nine=new JButton("9");
            nineHandler=new nineButtonHandler();
    nine.addActionListener(nineHandler);

    zero=new JButton("0");
    zeroHandler=new zeroButtonHandler();
    zero.addActionListener(zeroHandler);

    one=new JButton("1");
    oneHandler=new oneButtonHandler();
    one.addActionListener(oneHandler);

    two=new JButton("2");
    twoHandler=new twoButtonHandler();
    two.addActionListener(twoHandler);

    three=new JButton("3");
    threeHandler=new threeButtonHandler();
    three.addActionListener(threeHandler);

    four=new JButton("4");
            fourHandler=new fourButtonHandler();
    four.addActionListener(fourHandler);

    five=new JButton("5");
            fiveHandler=new fiveButtonHandler();
    five.addActionListener(fiveHandler);

    six=new JButton("6");
            sixHandler=new sixButtonHandler();
    six.addActionListener(sixHandler);

    minus=new JButton("-");
            minusHandler=new minusButtonHandler();
    minus.addActionListener(minusHandler);

    plus=new JButton("+");
            plusHandler=new plusButtonHandler();
    plus.addActionListener(plusHandler);

    multiply=new JButton("X");

            multiplyHandler=new multiplyButtonHandler();
    multiply.addActionListener(multiplyHandler);

    divide=new JButton("/");
            divideHandler=new divideButtonHandler();
    divide.addActionListener(divideHandler);

    equal= new JButton("=");
                equalHandler = new equalButtonHandler();
                equal.addActionListener(equalHandler);

                dot=new JButton(".");

                                dotHandler=new dotButtonHandler();
    dot.addActionListener(dotHandler);

    p1 = new JPanel();
    p1.setLayout(new GridLayout(1,1));

    p2 = new JPanel();
    p2.setLayout(new GridLayout(5,5));

    p1.add(jtfMain);

    p2.add(divide);
    p2.add(seven);
    p2.add(eight);
    p2.add(nine);
    p2.add(multiply);

    p2.add(four);
    p2.add(five);
    p2.add(six);
    p2.add(minus);

    p2.add(one);
    p2.add(two);
    p2.add(three);
    p2.add(plus);

    p2.add(zero);
    p2.add(dot);
    p2.add(equal); ...

ali11 -1 Light Poster

I have no idea what wrong my cods when I press = button of my calculator nothing happens.
[CODE]import java.util.Stack;
import java.util.Stack;
import java.awt.;
import java.awt.event.
;
import javax.swing.;
import java.math.
;
import java.util.Vector;

public class Ahsan extends JFrame{
Stack s = new Stack();

private JFrame f;
private JPanel p1,p2;
private JTextField jtfMain;
private JButton jbtnOn, jbtnMRC, jbtnMminus, jbtnMadd, jbtnDivide, jbtnOff, jbtnSeven, jbtnEight, jbtnNine, jbtnMultiply,
jbtnSqrt, jbtnFour, jbtnFive, jbtnSix, jbtnMinus, jbtnSq, jbtnOne, jbtnTwo, jbtnThree, jbtnPlus, jbtn1x, jbtnZero, jbtnDecimal,
jbtnEqual, jbtnEnter;

char ch;
Stack cStack=new Stack();
public Ahsan() {

setSize(400,190);
setTitle("Reverse Polish Notation Calculator");
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
setLayout(new BorderLayout());

jtfMain = new JTextField("");

jbtnOn = new JButton("ON/AC");
jbtnMRC = new JButton("MRC");
jbtnMminus = new JButton("M-");
jbtnMadd = new JButton("M+");
jbtnDivide = new JButton("/");
jbtnOff = new JButton("OFF");
jbtnSeven = new JButton("7");
jbtnEight = new JButton("8");
jbtnNine = new JButton("9");
jbtnMultiply = new JButton("X");
jbtnSqrt = new JButton("SQRT");
jbtnFour = new JButton("4");
jbtnFive = new JButton("5");
jbtnSix = new JButton("6");
jbtnMinus = new JButton("-");
jbtnSq = new JButton("SQ");
jbtnOne = new JButton("1");
jbtnTwo = new JButton("2");
jbtnThree = new JButton("3");
jbtnPlus = new JButton("+");
jbtn1x = new JButton("1/x");
jbtnZero = new JButton("0");
jbtnDecimal = new JButton(".");
jbtnEqual = new JButton("=");
jbtnEnter = new JButton("ENTER");

p1 = new JPanel();
p1.setLayout(new GridLayout(1,1));

p2 = new JPanel();
p2.setLayout(new GridLayout(5,5));

p1.add(jtfMain);

p2.add(jbtnOn);
p2.add(jbtnMRC);
p2.add(jbtnMadd);
p2.add(jbtnMminus);
p2.add(jbtnDivide);
p2.add(jbtnSeven);
p2.add(jbtnEight);
p2.add(jbtnNine);
p2.add(jbtnMultiply);
p2.add(jbtnSqrt);
p2.add(jbtnFour);
p2.add(jbtnFive);
p2.add(jbtnSix);
p2.add(jbtnMinus);
p2.add(jbtnSq);
p2.add(jbtnOne);
p2.add(jbtnTwo);
p2.add(jbtnThree);
p2.add(jbtnPlus);
p2.add(jbtn1x);
p2.add(jbtnZero);
p2.add(jbtnDecimal);
p2.add(jbtnEqual);
p2.add(jbtnEnter);
p2.add(jbtnOff);

ButtonHandler buttonHandler=new ButtonHandler();
jbtnOn.addActionListener(new ButtonHandler());
jbtnMRC.addActionListener(new ButtonHandler());
jbtnMminus.addActionListener(new ButtonHandler());
jbtnDivide.addActionListener(new ButtonHandler());
jbtnOff.addActionListener(new ButtonHandler());
jbtnSeven.addActionListener(new ...

ali11 -1

I don't think I am done yet. I don't know how to write pop method.and also I am not sure if my push method is correct or not.

ali11 -1 Light Poster

I need help in creating a RPN calculator! I'm currently stuck in making a stack. here is my codes so for.This is my first time I am using stack.

[code]
import java.util.Stack;
import java.awt.;
import java.awt.event.
;
import javax.swing.;
import java.math.
;

public class JavaCalculator extends JFrame{
Stack s = new Stack();

private JFrame f;
private JPanel p1,p2;
private JTextField jtfMain;
private JButton jbtnOn, jbtnMRC, jbtnMminus, jbtnMadd, jbtnDivide, jbtnOff, jbtnSeven, jbtnEight, jbtnNine, jbtnMultiply,
jbtnSqrt, jbtnFour, jbtnFive, jbtnSix, jbtnMinus, jbtnSq, jbtnOne, jbtnTwo, jbtnThree, jbtnPlus, jbtn1x, jbtnZero, jbtnDecimal,
jbtnEqual, jbtnEnter;

public JavaCalculator() {

    setSize(400,190);
    setTitle("Reverse Polish Notation Calculator");
    setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    setLayout(new BorderLayout());

    jtfMain = new JTextField("");

    jbtnOn = new JButton("ON/AC");
    jbtnMRC = new JButton("MRC");
    jbtnMminus = new JButton("M-");
    jbtnMadd = new JButton("M+");
    jbtnDivide = new JButton("/");
    jbtnOff = new JButton("OFF");
    jbtnSeven = new JButton("7");
    jbtnEight = new JButton("8");
    jbtnNine = new JButton("9");
    jbtnMultiply = new JButton("X");
    jbtnSqrt = new JButton("SQRT");
    jbtnFour = new JButton("4");
    jbtnFive = new JButton("5");
    jbtnSix = new JButton("6");
    jbtnMinus = new JButton("-");
    jbtnSq = new JButton("SQ");
    jbtnOne = new JButton("1");
    jbtnTwo = new JButton("2");
    jbtnThree = new JButton("3");
    jbtnPlus = new JButton("+");
    jbtn1x = new JButton("1/x");
    jbtnZero = new JButton("0");
    jbtnDecimal = new JButton(".");
    jbtnEqual = new JButton("=");
    jbtnEnter = new JButton("ENTER");

    p1 = new JPanel();
    p1.setLayout(new GridLayout(1,1));

    p2 = new JPanel();
    p2.setLayout(new GridLayout(5,5));

    p1.add(jtfMain);

    p2.add(jbtnOn);
    p2.add(jbtnMRC);
    p2.add(jbtnMadd);
    p2.add(jbtnMminus);
    p2.add(jbtnDivide);
    p2.add(jbtnSeven);
    p2.add(jbtnEight);
    p2.add(jbtnNine);
    p2.add(jbtnMultiply);
    p2.add(jbtnSqrt);
    p2.add(jbtnFour);
    p2.add(jbtnFive);
    p2.add(jbtnSix);
    p2.add(jbtnMinus);
    p2.add(jbtnSq);
    p2.add(jbtnOne);
    p2.add(jbtnTwo);
    p2.add(jbtnThree);
    p2.add(jbtnPlus);
    p2.add(jbtn1x);
    p2.add(jbtnZero);
    p2.add(jbtnDecimal);
    p2.add(jbtnEqual);
    p2.add(jbtnEnter);
    p2.add(jbtnOff);

    jbtnOn.addActionListener(new ButtonHandler());
    jbtnMRC.addActionListener(new ButtonHandler());
    jbtnMminus.addActionListener(new ButtonHandler());
    jbtnDivide.addActionListener(new ButtonHandler());
    jbtnOff.addActionListener(new ButtonHandler());
    jbtnSeven.addActionListener(new ...

ali11 -1 Light Poster

I need help in creating a RPN calculator! I'm currently stuck in making a stack. here is my codes so for.
[CODE]/**

  • /
    import java.awt.
    ;
    import java.awt.event.;
    import javax.swing.
    ;
    import java.math.*;

public class JavaCalculator extends JFrame{

private JFrame f;
private JPanel p1,p2;
private JTextField jtfMain;
private JButton jbtnOn, jbtnMRC, jbtnMminus, jbtnMadd, jbtnDivide, jbtnOff, jbtnSeven, jbtnEight, jbtnNine, jbtnMultiply,
jbtnSqrt, jbtnFour, jbtnFive, jbtnSix, jbtnMinus, jbtnSq, jbtnOne, jbtnTwo, jbtnThree, jbtnPlus, jbtn1x, jbtnZero, jbtnDecimal,
jbtnEqual, jbtnEnter;

public JavaCalculator() {

    setSize(400,190);
    setTitle("Reverse Polish Notation Calculator");
    setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    setLayout(new BorderLayout());

    jtfMain = new JTextField("");

    jbtnOn = new JButton("ON/AC");
    jbtnMRC = new JButton("MRC");
    jbtnMminus = new JButton("M-");
    jbtnMadd = new JButton("M+");
    jbtnDivide = new JButton("/");
    jbtnOff = new JButton("OFF");
    jbtnSeven = new JButton("7");
    jbtnEight = new JButton("8");
    jbtnNine = new JButton("9");
    jbtnMultiply = new JButton("X");
    jbtnSqrt = new JButton("SQRT");
    jbtnFour = new JButton("4");
    jbtnFive = new JButton("5");
    jbtnSix = new JButton("6");
    jbtnMinus = new JButton("-");
    jbtnSq = new JButton("SQ");
    jbtnOne = new JButton("1");
    jbtnTwo = new JButton("2");
    jbtnThree = new JButton("3");
    jbtnPlus = new JButton("+");
    jbtn1x = new JButton("1/x");
    jbtnZero = new JButton("0");
    jbtnDecimal = new JButton(".");
    jbtnEqual = new JButton("=");
    jbtnEnter = new JButton("ENTER");

    p1 = new JPanel();
    p1.setLayout(new GridLayout(1,1));

    p2 = new JPanel();
    p2.setLayout(new GridLayout(5,5));

    p1.add(jtfMain);

    p2.add(jbtnOn);
    p2.add(jbtnMRC);
    p2.add(jbtnMadd);
    p2.add(jbtnMminus);
    p2.add(jbtnDivide);
    p2.add(jbtnSeven);
    p2.add(jbtnEight);
    p2.add(jbtnNine);
    p2.add(jbtnMultiply);
    p2.add(jbtnSqrt);
    p2.add(jbtnFour);
    p2.add(jbtnFive);
    p2.add(jbtnSix);
    p2.add(jbtnMinus);
    p2.add(jbtnSq);
    p2.add(jbtnOne);
    p2.add(jbtnTwo);
    p2.add(jbtnThree);
    p2.add(jbtnPlus);
    p2.add(jbtn1x);
    p2.add(jbtnZero);
    p2.add(jbtnDecimal);
    p2.add(jbtnEqual);
    p2.add(jbtnEnter);
    p2.add(jbtnOff);

    jbtnOn.addActionListener(new ButtonHandler());
    jbtnMRC.addActionListener(new ButtonHandler());
    jbtnMminus.addActionListener(new ButtonHandler());
    jbtnDivide.addActionListener(new ButtonHandler());
    jbtnOff.addActionListener(new ButtonHandler());
    jbtnSeven.addActionListener(new ButtonHandler());
    jbtnEight.addActionListener(new ButtonHandler());
    jbtnNine.addActionListener(new ButtonHandler());
    jbtnMultiply.addActionListener(new ButtonHandler());
    jbtnSqrt.addActionListener(new ButtonHandler());
    jbtnFour.addActionListener(new ButtonHandler()); ...

ali11 -1 Light Poster

I did it without using GUI because i am not sure how to do in GUI.I need help to put these code in GUI.
[code]import java.util.Scanner;
import java.util.Stack;

/*
This calculator uses the reverse polish notation.
/
public class Calculator
{
public static void main(String[] args)
{
Scanner in = new Scanner(System.in);
Stack results = new Stack();
System.out.println("Enter one number or operator per line, Q to quit. ");
boolean done = false;
while (!done)
{
String input = in.nextLine();

// If the command is an operator, pop the arguments and push the result

if (input.equals("+"))
{
results.push(results.pop() + results.pop());
}
else if (input.equals("-"))
{

Integer arg2 = results.pop();
results.push(results.pop() - arg2);
}
else if (input.equals("") || input.equals("x"))
{
results.push(results.pop()
results.pop());
}
else if (input.equals("/"))
{
Integer arg2 = results.pop();
results.push(results.pop() / arg2);
}
else if (input.equals("Q") || input.equals("q"))
{
done = true;
}
else
{
// Not an operator—push the input value

results.push(Integer.parseInt(input));
}
System.out.println(results);
}
}
}[/code]