Simple Calculator ( Java )

import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
class Calculator
{
    static double hasil = 0.0;
    static void penjumlahan(double a)
    {
        hasil=hasil+a;
        JOptionPane.showMessageDialog(null,"the results "+hasil);
    }
    static void pengurangan(double a)
    {
        hasil=hasil-a;
        JOptionPane.showMessageDialog(null,"the results "+hasil);
    }
    static void perkalian(double a)
    {
        hasil=hasil*a;
        JOptionPane.showMessageDialog(null,"the results "+hasil);
    }
    static void pembagian(double a)
    {
        hasil=hasil/a;
        JOptionPane.showMessageDialog(null,"the results "+hasil);
    }
    static void modulus(double a)
    {
        hasil=hasil%a;
        JOptionPane.showMessageDialog(null,"the results "+hasil);
    }
    public static void utama()
    {
        String input = JOptionPane.showInputDialog("Simple Calculator\n===============\n1. Penjumlahan ( + )\n2. Pengurangan ( - )\n3. Perkalian ( x )\n4. Pembagian ( / )\n5. Modulus ( % )\nInput Selection : ");
        int inputan = Integer.parseInt(input);
        switch(inputan)
        {
            case 1:double input2 = Double.parseDouble(JOptionPane.showInputDialog("( + ) Input Value "));
                    penjumlahan(input2);break;
            case 2:input2 = Double.parseDouble(JOptionPane.showInputDialog("( - ) Input Value "));
                    pengurangan(input2);break;
            case 3:input2 = Double.parseDouble(JOptionPane.showInputDialog("( x ) Input Value "));
                    perkalian(input2);break;
            case 4:input2 = Double.parseDouble(JOptionPane.showInputDialog("( / ) Input Value "));
                    pembagian(input2);break;
            case 5:input2 = Double.parseDouble(JOptionPane.showInputDialog("( % ) Input Value "));
                    modulus(input2);break;
            default:JOptionPane.showMessageDialog(null,"Input is not available !!!!!");
        }

    }
    public static void main(String[] args)
    {
        for(int i=0;i<1;i--)
        {
            utama();
        }
    }

}
//use "Calculator.java" for file name

                                         output :

Previous
Next Post »