Calculator
Calculator
Calculator
/**
*
* @author ACER
*/
import javax.swing.*;
import java.awt.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
public ScientificCalculator() {
setTitle("Scientific Calculator");
setSize(400, 400);
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
String[] buttonLabels = {
"sin", "cos", "x^2",
"7", "8", "9",
"4", "5", "6",
"1", "2", "3",
"0", "+", "-",
"*", "/", "="
};
if (expression.isEmpty()) {
throw new ArithmeticException("Empty expression");
}
switch (operator) {
case "+":
result += operand;
break;
case "-":
result -= operand;
break;
case "*":
result *= operand;
break;
case "/":
if (operand == 0) {
throw new ArithmeticException("Division by zero");
}
result /= operand;
break;
}
}
return result;
}
/**
* This method is called from within the constructor to initialize the form.
* WARNING: Do NOT modify this code. The content of this method is always
* regenerated by the Form Editor.
*/
@SuppressWarnings("unchecked")
// <editor-fold defaultstate="collapsed" desc="Generated Code">
private void initComponents() {
setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
pack();
}// </editor-fold>
/**
* @param args the command line arguments
*/