Olá, escrevi um pequeno programa em que se tem uma calculadora simples com as quatro operações aritméticas. Mas preciso saber se este programa tem qualidade de software boa ( e quando digo isto, se ele tem acessibilidade, código limpo, etc).
Meu código ;
public static void main(String[] args) {
//Initializing the variables because otherwise they can give compile-time error
int num1 = 0;
int num2 = 0;
int res = 0;
String op;
try {
num1 = Integer.parseInt(JOptionPane.showInputDialog("Type a number "));
num2 = Integer.parseInt(JOptionPane.showInputDialog("Type another number : "));
op = JOptionPane.showInputDialog(
"[+] - Addition" +
"\n[-] - Subtraction" +
"\n[*] - Multiplication" +
"\n[/] - Division");
switch(op) {
case "+" :
res = num1+num2;
break;
case "-":
res = num1-num2;
break;
case "*" :
res = num1*num2;
break;
case "/" :
res = num1/num2;
break;
default : JOptionPane.showMessageDialog(null, "Error. You typed something wrong!","Error",JOptionPane.WARNING_MESSAGE);
}
}
catch(Exception er) {
JOptionPane.showMessageDialog(null,"Something is wrong!" + "\nLog of the error : " + er,"Error",JOptionPane.WARNING_MESSAGE); //Show the error log
System.exit(1); //Some error that I know could happen, happened, returning the parameter as that went bad.
}
JOptionPane.showMessageDialog(null, "Result : " + res);
}
}