percabangan if else
Source kode
package tugas.bp;
import java.util.Scanner;
public class TugasBp {
public static void main(String[] args) {
Scanner scan = new Scanner(System.in);
int totalpembelian, setelahdiskon, harga, jumlahbaju, diskon, hasil, uangpembeli, kembalian;
harga= 20000;
diskon=0;
System.out.println("SELAMAT DATANG DAN BERBELANJA DI BUTIK KAMI");
System.out.println("=============================================");
//input jumlah barang
System.out.print("MASUKAN JUMLAH BAJU YANG DIBELI: ");
jumlahbaju=scan.nextInt();
totalpembelian= jumlahbaju*harga;
//totalpembayaran sebelum diskon
System.out.println("Harga baju sebelum diskon:Rp"+totalpembelian);
//proses diskon
if (totalpembelian<100000){
System.out.println("maaf anda tidak mendapatkan diskon");
}
else if (totalpembelian>=100000 && totalpembelian<=200000){
diskon= totalpembelian*5/100;
}
else if (totalpembelian>200001 && totalpembelian<=300000){
diskon= totalpembelian*10/100;
}
else if (totalpembelian>300001 && totalpembelian<=400000){
diskon = totalpembelian*15/100;
}
else if (totalpembelian>400001 && totalpembelian<=500000){
diskon= totalpembelian*20/100;
}
else if (totalpembelian>500000){
diskon= totalpembelian*25/100;
}
//proses penghitungan diskon
hasil=totalpembelian-diskon;
System.out.println("total belanja:Rp "+totalpembelian);
System.out.println("diskon anda:Rp"+diskon);
System.out.println("total belanja setelah diskon:Rp"+hasil);
//proses pembayaran
System.out.print("masukan uang anda:Rp ");
uangpembeli= scan.nextInt();
kembalian= uangpembeli-hasil;
if(uangpembeli==hasil){
System.out.println("uang anda pas");
}
else if(uangpembeli>hasil){
System.out.println("uang anda kembali:Rp"+kembalian);
}
System.out.println("=============================================");
System.out.println("terimakasih telah berbelanja di butik kami :D");
}
}
Komentar
Posting Komentar