Created
January 19, 2019 03:17
-
-
Save ilhamarrouf/4f2b64bc73a2fd3a2806a44f7769a8f6 to your computer and use it in GitHub Desktop.
Example Calculator
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import java.util.Scanner; | |
public class Calculator { | |
double x; | |
double y; | |
double result; | |
int Operation; | |
public static void main(String[] args) { | |
Scanner input = new Scanner (System.in); | |
Calculator a = new Calculator(); | |
double result, Operation, x, y; | |
System.out.println("Pilih Operation \n============="); | |
System.out.println("1.Tambah\n2.Kurang\n3.Bagi\n4.Kali"); | |
System.out.println("Masukkan Pilihan Anda : "); | |
a.Operation=input.nextInt(); | |
System.out.println("Masukkan Bilangan 1 : "); | |
a.x = input.nextInt(); | |
System.out.println("Maukkan Bilangan 2 : "); | |
a.y = input.nextInt(); | |
a.Operation(); | |
} | |
public void addition() { | |
result = x + y; | |
} | |
public void subtraction() { | |
result = x - y; | |
} | |
public void division(){ | |
result = x / y; | |
} | |
public void multiplication() { | |
result = x * y; | |
} | |
int Operation() { | |
switch(Operation) { | |
case(1): | |
addition(); | |
System.out.println("Hasil = "+result); | |
break; | |
case(2): | |
subtraction(); | |
System.out.println("Hasil ="+result); | |
break; | |
case(3): | |
division(); | |
System.out.println("Hasil = "+result); | |
break; | |
case(4): | |
multiplication(); | |
System.out.println("Hasil = " +result); | |
break; | |
} | |
return Operation; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment