I have a calculator that I've been working on for school.
It's not going to have a typical calculator GUI though.
I have a beta version where I use input boxes in order to take the input.
I was actually wondering if there was a way to make a function to close it and then reopen it sort of like a loop.
import javax.swing.JOptionPane;
public class JOptionPaneCalc {
public static void main(String [] args){
char o = ' ';
String input = " ";
double num1 = 0;
double num2 = 0;
double result = 0;
while (true){
input = JOptionPane.showInputDialog("What is your operand? ");
o = input.charAt(0);
if (o == '/') {
result = num1 / num2;
break;
} else if (o == '*') {
result = num1 * num2;
break;
} else if (o == '+') {
result = num1 + num2;
break;
} else if (o == '-') {
result = num1 - num2;
break;
}else if (o == 'q'){
System.exit(0);
}
}
input = JOptionPane.showInputDialog("What is your first number? ");
num1 = Double.parseDouble(input);
input = JOptionPane.showInputDialog("What is your second number? ");
num2 = Double.parseDouble(input);
if (o == '/') {
result = num1 / num2;
} else if (o == '*') {
result = num1 * num2;
} else if (o == '+') {
result = num1 + num2;
} else if (o == '-') {
result = num1 - num2;
}else if (o == 'q'){
System.exit(0);
}
JOptionPane.showMessageDialog(null ,"Your answer is : " + result);
}
}
This is what I have, hopefully you can help me