calculator
in Java
. I'm quite new to programming so I'm trying to get used to it. if
statements, otherwise the code that follows will be free standing and will always execute:.equals
for Strings
, compares Object
references:equals(..)
not with ;
after the conditions was an empty statement so the conditon had no effect at all.switch
.operation
has length 1 and than make a switch for the char
[switch (operation.charAt(0))
]case
instead of if
dunno if this eliminates the error, but its cleaner i think.. switch (operation){case +: System.out.println('your answer is' + (num1 + num2));break;case -: System.out.println('your answer is' - (num1 - num2));break; ...
JTextField
does not have an append
method, it only has a setText
method.JTextArea
instead...List
each time the user clicks the '+' button and clearing the text field for the next value. When they press the '=' button, you should simply iterate over this list and put the result into the textfield and clear the list...actionPerformed
method for the '=' button, but it's contents would look something like...