PROGRAM 1 :
import javax.swing.*;
public class Insifelsif2 {
public static void main (String[] args){
String
quant = JOptionPane.showInputDialog("Quantity ?");
String
harga = JOptionPane.showInputDialog("Harga barang ?");
float
iquant = Float.parseFloat(quant);
float
iharga = Float.parseFloat(harga);
float jumlah = iquant * iharga;
float diskon=0;
String ket=null;
if ((100000<=jumlah)&&(jumlah<=300000)){
diskon
= jumlah * 10 /100;
ket
= "diskon 10 %";
}else{
if
((300000<=jumlah)&&(jumlah<=500000)){
diskon
= jumlah * 20 /100;
ket
= "diskon 20 %";
}else{
if
((500000<=jumlah)&&(jumlah<=700000)){
diskon
= jumlah * 30 /100;
ket
= "diskon 30 %";
}
else {
if
(100000<jumlah){
diskon
= jumlah * 40 /100;
ket
= "diskon 40 %";
}
}
}
}
float bayar;
bayar = jumlah - diskon;
System.out.println("Quantity = "+quant);
System.out.println("Harga = RP."+harga);
System.out.println("Jumlah = RP."+(int)jumlah);
System.out.println("diskon = RP."+(int)diskon);
System.out.println("bayar = RP."+(int)bayar);
System.out.println("Keterangan = "+ket);
}}
OUTPUT :
PROGRAM 2 :
import
javax.swing.*;
public class menu
{
public static void main (String
[] args){
float luas=0;
String pil = JOptionPane.showInputDialog(
"Menu
bangun \n"+
"----------------------------------\n"+
"1. Luas
segitiga \n"+
"2. persegi
panjang \n"+
"3. Bujur
sangkar\n"+
"4.
exit");
int upil =
Integer.parseInt(pil);
switch (upil){
case 1 :
float alas =
Float.parseFloat(JOptionPane.showInputDialog("Alas ?"));
float tinggi =
Float.parseFloat(JOptionPane.showInputDialog("Tinggi ?"));
luas=(alas*tinggi)/2;
break;
case 2 :
float panjang =
Float.parseFloat(JOptionPane.showInputDialog("panjang ?"));
float lebar =
Float.parseFloat(JOptionPane.showInputDialog("lebar ?"));
luas = panjang *
lebar;
break;
case 3 :
float sisi =
Float.parseFloat(JOptionPane.showInputDialog("panjang Sisi ?"));
luas=sisi*sisi;
break;
default :
JOptionPane.showMessageDialog(null,"Terimakasih","konfirmasi",1);
System.exit(0);
}
System.out.print("Luasnya
= "+luas);
}
}
OUTPUT :
No comments:
Post a Comment