Thursday, June 14, 2018

WAP IN JAVA TO MAKE A SIMPLE CALCULATOR USING GUI


import javax.swing.JOptionPane;
public class Second
{
    public static void main(String args[])
    {
        String a,b,op,n;
        int num1,num2,option,i=0;
        while(i!=-99){
        op=JOptionPane.showInputDialog("1 for Addition\n2 for Subtraction\n3 for Multiplication\n4 for Division\nEnter your choice");
        a=JOptionPane.showInputDialog("Enter the first number");
        b=JOptionPane.showInputDialog("Enter the second number");
        num1=Integer.parseInt(a);
        num2=Integer.parseInt(b);
        option=Integer.parseInt(op);
        //while(i!=-99)
       // {
            switch(option)
            {
                case 1:
                    JOptionPane.showMessageDialog(null,"The reslt is "+(num1+num2),"Result",JOptionPane.PLAIN_MESSAGE);
                    break;
                case 2:
                    JOptionPane.showMessageDialog(null,"The reslt is "+(num1-num2),"Result",JOptionPane.PLAIN_MESSAGE);
                    break;
                case 3:
                    JOptionPane.showMessageDialog(null,"The reslt is "+(num1*num2),"Result",JOptionPane.PLAIN_MESSAGE);
                    break;
                case 4:
                    JOptionPane.showMessageDialog(null,"The reslt is "+(num1/num2),"Result",JOptionPane.PLAIN_MESSAGE);
                    break;
                default:
                    JOptionPane.showMessageDialog(null,"only 1 to 4 :)","WARNING!!",JOptionPane.WARNING_MESSAGE);
         
            }
            n=JOptionPane.showInputDialog("Enter (-99) to quite!!");
            i=Integer.parseInt(n);
        }
        System.exit(0);
    }
}
                                                                     OUTPUT







No comments:

Post a Comment