Tanpa memperpanjang Masalah,lanjut aja berikut codingnya:
import javax.swing.JOptionPane;
public class kalkulator
{
public static void main (String[]args)
{
String NAMA = "" ;
double PANJANG = 0.0 ;
double LEBAR = 0.0 ;
NAMA = JOptionPane.showInputDialog(null,"KAL\t = KALKULATOR\nDPP\t = DIAGONAL PERSEGI PANJANG\nLPP\t = LUAS PERSEGI PANJANG\nKPP\t = KELILING PERSEGI PANJANG\nPITA\t = RUMUS PYTAGORAS\nMasukan Kode (Harap Gunakan Hurup Kapital) \t\t: ", "Masukan Kode Program", JOptionPane.PLAIN_MESSAGE);
if("DPP".equals(NAMA))
{
PANJANG = Double.parseDouble(JOptionPane.showInputDialog(null,"Panjang","Dalam Satuan Centimeter",JOptionPane.PLAIN_MESSAGE));
LEBAR = Double.parseDouble(JOptionPane.showInputDialog(null,"Lebar","Dalam Satuan Centimeter", JOptionPane.PLAIN_MESSAGE));
JOptionPane.showMessageDialog(null," Diagonal Persegi Panjang Adalah " + Math.pow((PANJANG*PANJANG+(LEBAR*LEBAR)),0.5)+" Cm","Hasil", JOptionPane.PLAIN_MESSAGE);
}
else if("KAL".equals(NAMA))
{
{
String CODE = "" ;
CODE = JOptionPane.showInputDialog(null,"TAMBAH\t = PENJUMLAHAN\nKURANG\t = PENGURANGAN\nKALI\t = PERKALIAN\nBAGI\t = PEMBAGIAN\nAKAR\t = PENGAKARAN\nPANGKAT\t = PERPANGKATAN\nMasukan Kode (Harap Masukan Dengan Benar) \t\t: ", "Masukan Kode Operator Kalkulator", JOptionPane.PLAIN_MESSAGE);
if("KALI".equals(CODE))
{
PANJANG = Double.parseDouble(JOptionPane.showInputDialog(null,"Apabila berkoma Gunakan Tanda Titik","Masukan Angka",JOptionPane.PLAIN_MESSAGE));
LEBAR = Double.parseDouble(JOptionPane.showInputDialog(null,"Apabila berkoma Gunakan Tanda Titik","Masukan Angka", JOptionPane.PLAIN_MESSAGE));
JOptionPane.showMessageDialog(null," " + (PANJANG*LEBAR)+"","Hasil Kali", JOptionPane.PLAIN_MESSAGE);
}
if("TAMBAH".equals(CODE))
{
PANJANG = Double.parseDouble(JOptionPane.showInputDialog(null,"Apabila berkoma Gunakan Tanda Titik","Masukan Angka",JOptionPane.PLAIN_MESSAGE));
LEBAR = Double.parseDouble(JOptionPane.showInputDialog(null,"Apabila berkoma Gunakan Tanda Titik","Masukan Angka", JOptionPane.PLAIN_MESSAGE));
JOptionPane.showMessageDialog(null," " + (PANJANG+LEBAR)+"","Hasil Tambah", JOptionPane.PLAIN_MESSAGE);
}
if("KURANG".equals(CODE))
{
PANJANG = Double.parseDouble(JOptionPane.showInputDialog(null,"Apabila berkoma Gunakan Tanda Titik","Masukan Angka",JOptionPane.PLAIN_MESSAGE));
LEBAR = Double.parseDouble(JOptionPane.showInputDialog(null,"Apabila berkoma Gunakan Tanda Titik","Masukan Angka", JOptionPane.PLAIN_MESSAGE));
JOptionPane.showMessageDialog(null," " + (PANJANG-LEBAR)+"","Hasil Kurang", JOptionPane.PLAIN_MESSAGE);
}
if("BAGI".equals(CODE))
{
PANJANG = Double.parseDouble(JOptionPane.showInputDialog(null,"Apabila berkoma Gunakan Tanda Titik","Masukan Angka",JOptionPane.PLAIN_MESSAGE));
LEBAR = Double.parseDouble(JOptionPane.showInputDialog(null,"Apabila berkoma Gunakan Tanda Titik","Masukan Angka", JOptionPane.PLAIN_MESSAGE));
JOptionPane.showMessageDialog(null," " + (PANJANG/LEBAR)+"","Hasil Bagi", JOptionPane.PLAIN_MESSAGE);
}
if("AKAR".equals(CODE))
{
PANJANG = Double.parseDouble(JOptionPane.showInputDialog(null,"Apabila berkoma Gunakan Tanda Titik","Masukan Angka",JOptionPane.PLAIN_MESSAGE));
JOptionPane.showMessageDialog(null," " + + Math.pow(PANJANG,0.5)+"","Hasil Akar", JOptionPane.PLAIN_MESSAGE);
}
if("PANGKAT".equals(CODE))
{
PANJANG = Double.parseDouble(JOptionPane.showInputDialog(null,"Apabila berkoma Gunakan Tanda Titik","Maukan Angka",JOptionPane.PLAIN_MESSAGE));
LEBAR = Double.parseDouble(JOptionPane.showInputDialog(null,"Apabila berkoma Gunakan Tanda Titik","Masukan Angka", JOptionPane.PLAIN_MESSAGE));
JOptionPane.showMessageDialog(null," " + + Math.pow(PANJANG,LEBAR)+"","Hasil Pangkat", JOptionPane.PLAIN_MESSAGE);
}
}
}
else if("PITA".equals(NAMA))
{
{
String PIT = "" ;
double a = 0.0 ;
double b = 0.0 ;
double c = 0.0 ;
PIT = JOptionPane.showInputDialog(null,"A\t = Mencari Nilai A\nB\t = Mencari Nilai B\nC\t = Mencari Nilai C\nMasukan Kode (Harap Masukan Dengan Benar) \t\t: ", "Rumus c2 = a2 + b2", JOptionPane.PLAIN_MESSAGE);
if("C".equals(PIT))
{
a = Double.parseDouble(JOptionPane.showInputDialog(null,"Masukan Nilai A ","Dalam Satuan Centimeter",JOptionPane.PLAIN_MESSAGE));
b = Double.parseDouble(JOptionPane.showInputDialog(null,"Masukan Nilai B","Dalam Satuan Centimeter", JOptionPane.PLAIN_MESSAGE));
JOptionPane.showMessageDialog(null," Nilai C Adalah " + Math.pow((a*a+(b*b)),0.5) + " Cm","Hasil", JOptionPane.PLAIN_MESSAGE);
}
if("B".equals(PIT))
{
c = Double.parseDouble(JOptionPane.showInputDialog(null,"Masukan Nilai C ","Dalam Satuan Centimeter",JOptionPane.PLAIN_MESSAGE));
a = Double.parseDouble(JOptionPane.showInputDialog(null,"Masukan Nilai A ","Dalam Satuan Centimeter", JOptionPane.PLAIN_MESSAGE));
JOptionPane.showMessageDialog(null," Nilai B Adalah " + Math.pow((c*c-(a*a)),0.5) + " Cm","Hasil", JOptionPane.PLAIN_MESSAGE);
}
if("A".equals(PIT))
{
c = Double.parseDouble(JOptionPane.showInputDialog(null,"Masukan Nilai C ","Dalam Satuan Centimeter",JOptionPane.PLAIN_MESSAGE));
b = Double.parseDouble(JOptionPane.showInputDialog(null,"Masukan Nilai B ","Dalam Satuan Centimeter", JOptionPane.PLAIN_MESSAGE));
JOptionPane.showMessageDialog(null," Nilai B Adalah " + Math.pow((c*c-(b*b)),0.5) + " Cm","Hasil", JOptionPane.PLAIN_MESSAGE);
}
}
}
else if("LPP".equals(NAMA))
{
PANJANG = Double.parseDouble(JOptionPane.showInputDialog(null,"Panjang","Dalam Satuan Centimeter",JOptionPane.PLAIN_MESSAGE));
LEBAR = Double.parseDouble(JOptionPane.showInputDialog(null,"Lebar","Dalam Satuan Centimeter", JOptionPane.PLAIN_MESSAGE));
JOptionPane.showMessageDialog(null," Luas Persegi Panjang Adalah " + PANJANG * LEBAR+ " Cm Kuadrat","Hasil", JOptionPane.PLAIN_MESSAGE);
}
else if("KPP".equals(NAMA))
{
PANJANG = Double.parseDouble(JOptionPane.showInputDialog(null,"Panjang","Dalam Satuan Centimeter",JOptionPane.PLAIN_MESSAGE));
LEBAR = Double.parseDouble(JOptionPane.showInputDialog(null,"Lebar","Dalam Satuan Centimeter", JOptionPane.PLAIN_MESSAGE));
JOptionPane.showMessageDialog(null," Keliling Persegi Panjang Adalah " + + (2*PANJANG+(2*LEBAR))+" Cm","Hasil", JOptionPane.PLAIN_MESSAGE);
}
else
{
JOptionPane.showMessageDialog(null,"www.sarlinnet.blogspot.com");
}
}
}
Sedikit info save coding ini sebagai kalkulator.java
Tidak ada komentar:
Posting Komentar