-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathMiniKalkulator.java
86 lines (81 loc) · 2.42 KB
/
MiniKalkulator.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
import java.util.Scanner;
public class MiniKalkulator
{
public static void main(String [] args)
{
pilihan();
}
public static void pilihan()
{
Scanner scanner = new Scanner(System.in);
Aritmatika arit = new Aritmatika();
PersegiPanjang pp = new PersegiPanjang();
int pil;
String lanjut;
double angka1, angka2;
angka1=0;
angka2=0;
System.out.println("Mini Calculator");
System.out.println("1. Penjumlahan");
System.out.println("2. Pengurangan");
System.out.println("3. Perkalian");
System.out.println("4. Pembagian");
System.out.println("5. Persegi Panjang");
System.out.println("6. Persegi");
System.out.println("7. Segitiga");
System.out.print("Masukkan Pilihan Anda: ");
pil = scanner.nextInt();
switch (pil)
{
case 1: case 2: case 3: case 4:
System.out.println("-----------------------");
System.out.print("Masukkan Angka 1: ");
angka1 = scanner.nextDouble();
System.out.print("Masukkan Angka 2: ");
angka2 = scanner.nextDouble();
break;
case 5:
System.out.println("-----------------------");
System.out.print("Panjang : ");
angka1 = scanner.nextDouble();
System.out.print("Lebar : ");
angka2 = scanner.nextDouble();
break;
default:
System.out.println("Anda memasukkan pilihan yang salah.");
}
switch (pil)
{
case 1:
System.out.println("----------------------- (+) ");
System.out.println(" " + arit.tambah(angka1, angka2));
break;
case 2:
System.out.println("----------------------- (-) ");
System.out.println(" " + arit.kurang(angka1, angka2));
break;
case 3:
System.out.println("----------------------- (x) ");
System.out.println(" " + arit.kali(angka1, angka2));
break;
case 4:
System.out.println("----------------------- (/) ");
System.out.println(" " + arit.bagi(angka1, angka2));
break;
case 5:
System.out.println("Luas : " + pp.luas(angka1, angka2));
System.out.println("Keliling: " + pp.keliling(angka1, angka2));
break;
default:
System.out.println("Anda memasukkan pilihan yang salah");
}
System.out.println("");
System.out.println("-----------------------");
System.out.print("Apakah Anda ingin melanjutkan lagi (y/t) ?");
lanjut = scanner.next();
if(lanjut.equals("y"))
{
pilihan();
}
}
}