import java.util.Scanner;
class discount2
{ public static void main(String[] azz)
{ Scanner sc = new Scanner(System.in);
int kode, qty, hrg = 0, total = 0, n = 0;
double disc = 0.0, bayar;
String jwb, nmbarang = "";
System.out.print("Mulai transaksi [y/t] ? ");
jwb = sc.next();
while(jwb.equals("y"))
{ System.out.print("Kode barang : ");
kode = sc.nextInt();
System.out.print("Banyak barang : ");
qty = sc.nextInt();
switch(kode)
{ case 111 : hrg = 1500;
nmbarang = "Indomie";
break;
case 112 : hrg = 11000;
nmbarang = "Gula pasir";
break;
case 113 : hrg = 6000;
nmbarang = "Tepung terigu";
break;
default : System.out.println("Kode tidak dikenal");
}
total += hrg * qty;
System.out.println("Nama barang : "+nmbarang+"\t harga : Rp."+hrg);
n++;
System.out.print("Input barang lagi [y/t] ?");
jwb = sc.next();
}
if(total>200000)
{disc = 0.05;
disc = total * 0.05;
bayar = total - disc;
}else
if (total>=200000)
{disc = 0.02;
disc = total * 0.02;
bayar = total - disc;
}else
if (total<200000)
{disc = 0;
disc = total * 0;
bayar = total - disc;
}else{
disc= 0;
disc = total * disc;
bayar = total - disc;
}
System.out.println("Total harga : Rp."+total);
System.out.println("Diskon : Rp."+disc);
System.out.println("Total bayar : Rp."+bayar);
}}
OUT PUT :
class discount2
{ public static void main(String[] azz)
{ Scanner sc = new Scanner(System.in);
int kode, qty, hrg = 0, total = 0, n = 0;
double disc = 0.0, bayar;
String jwb, nmbarang = "";
System.out.print("Mulai transaksi [y/t] ? ");
jwb = sc.next();
while(jwb.equals("y"))
{ System.out.print("Kode barang : ");
kode = sc.nextInt();
System.out.print("Banyak barang : ");
qty = sc.nextInt();
switch(kode)
{ case 111 : hrg = 1500;
nmbarang = "Indomie";
break;
case 112 : hrg = 11000;
nmbarang = "Gula pasir";
break;
case 113 : hrg = 6000;
nmbarang = "Tepung terigu";
break;
default : System.out.println("Kode tidak dikenal");
}
total += hrg * qty;
System.out.println("Nama barang : "+nmbarang+"\t harga : Rp."+hrg);
n++;
System.out.print("Input barang lagi [y/t] ?");
jwb = sc.next();
}
if(total>200000)
{disc = 0.05;
disc = total * 0.05;
bayar = total - disc;
}else
if (total>=200000)
{disc = 0.02;
disc = total * 0.02;
bayar = total - disc;
}else
if (total<200000)
{disc = 0;
disc = total * 0;
bayar = total - disc;
}else{
disc= 0;
disc = total * disc;
bayar = total - disc;
}
System.out.println("Total harga : Rp."+total);
System.out.println("Diskon : Rp."+disc);
System.out.println("Total bayar : Rp."+bayar);
}}
OUT PUT :
No comments:
Post a Comment