<html><head><meta name="color-scheme" content="light dark"></head><body><pre style="word-wrap: break-word; white-space: pre-wrap;">

import javax.swing.*;

public class Calculator {
   public static void main(String[] args) {

      String tmp1; double v1 = 0; // 1st user-entered value
      String tmp2; double v2 = 0; // 2nd user-entered value
      String op; char opChar = ' '; // desired operation
      double result = 0; // answer

      // get user input
      tmp1 = JOptionPane.showInputDialog("Enter 1st value:");
      tmp2 = JOptionPane.showInputDialog("Enter 2nd value:");
      op = JOptionPane.showInputDialog("Enter operation:");

      // convert input to numbers
      try {
         v1 = Double.parseDouble(tmp1);
         v2 = Double.parseDouble(tmp2);
         opChar = op.charAt(0);
      } catch (Exception exc) {
         JOptionPane.showMessageDialog(null, "Illegal input!");
         System.exit(0);
      }

      // perform operation
      switch (opChar) {
      case '+': result = v1 + v2; break;
      case '-': result = v1 - v2; break;
      case '*': result = v1 * v2; break;
      case '/': result = v1 / v2; break;
      default:
         JOptionPane.showMessageDialog(null, "Unknown operator!");
         System.exit(0);
      }

      // Output result:
      JOptionPane.showMessageDialog(null, "Result: " + result);
   }
}
</pre></body></html>