Quote:you mean class for every method(+-*/) ? why?
This is what he means:
Code
public int add(int a, int b) { return a + b; }If you have a gui, there isn't a need for Switch/case just create buttonhandlers for each button, inside those handlers do the method. (add(1, 2), etc.)
Code
public class Calculator extends JFrame {
public Calculator() {
setTitle("Calculator");
//... blah blah blah
addButton.addEventListener(new AddButtonHandler());
}
public static void main(String[] args) {
new Calculator();
}
private class AddButtonHandler implements ActionListener {
public void actionPerformed(ActionEvent e) {
textField.setText(Integer.toString(add(number1, number2)));
}
}
}Was bored, you could do something like that..
Maybe add the number to a stack (on the textField) which has a list of operations?
