Java Calculator JoptionPane
import java.util.Scanner;
import javax.swing.JOptionPane;
public class Calculator
{
public static void main(String [] args)
{
Scanner norbel = new Scanner(System.in);
int answer;
String FNumber = JOptionPane.showInputDialog("Enter first Integer: ");
int fnum = Integer.parseInt(FNumber);
fnum = norbel.nextInt();
String operator = JOptionPane.showInputDialog("Operation:\n 1.Addition\n 2.Subtraction\n 3.Multiplication\n 4.Division\n");
Integer opt = Integer.parseInt(operator);
if(opt == 1)
{
String opt1 = JOptionPane.showInputDialog("Enter second Integer: ");
int snum = Integer.parseInt(opt1);
snum = norbel.nextInt();
answer = fnum + snum;
String ans = "Answer" +answer+ "!";
JOptionPane.showMessageDialog(null,answer);
if(opt == 2)
{
String opt2 = JOptionPane.showInputDialog("Enter second Integer: ");
int snum = Integer.parseInt(opt2);
snum = norbel.nextInt();
answer = fnum - snum;
String ans = "Answer" +answer+ "!";
JOptionPane.showMessageDialog(null,ans);
}
if(opt == 3)
{
String opt3 = JOptionPane.showInputDialog("Enter second Integer: ");
int snum = Integer.parseInt(opt3);
snum = norbel.nextInt();
answer = fnum * snum;
String ans = "Answer" +answer+ "!";
JOptionPane.showMessageDialog(null,ans);
}
if(opt == 4)
{
String opt4 = JOptionPane.showInputDialog("Enter second Integer: ");
int snum = Integer.parseInt(opt4);
snum = norbel.nextInt();
answer = fnum / snum;
String ans = "Answer" +answer+ "!";
JOptionPane.showMessageDialog(null,ans);
}
else
{
String error = "Error";
JOptionPane.showMessageDialog(null, error);
}
}
}
Cielo Lucas