Forum Latihan Percabangan If Else
Source Code :
package progIfElse;
import java.util.Scanner;
public class progIfElse {
@SuppressWarnings("resource")
public static void main(String[] args) {
int jumlahbarang, harga;
double total, uang, diskon, kembali;
Scanner sc = new Scanner(System.in);
// Identitas
System.out.println("=======================================");
System.out.println("|| ||");
System.out.println("|| Nama : Talia Aprianti ||");
System.out.println("|| NPM : 22082010035 ||");
System.out.println("|| ||");
System.out.println("=======================================");
System.out.println("|| ||");
System.out.println("|| Selamat Datang ||");
System.out.println("|| Toko Barang Kami ||");
System.out.println("|| Harga 1 Barang = Rp. 50.000 ||");
System.out.println("|| ||");
System.out.println("=======================================");
System.out.println("");
// Program
System.out.print ("Jumlah Barang Yang Dibeli : ");
jumlahbarang = sc.nextInt();
harga = jumlahbarang * 50000;
System.out.println("");
System.out.println("Total Beli : Rp. "+harga);
System.out.println("");
System.out.println("--------------------------------------");
System.out.println("");
System.out.print("Uang Pelanggan : Rp. ");
uang = sc.nextDouble();
System.out.println("");
System.out.println("--------------------------------------");
// Pembelian < 100.000 = diskon 0%
if (harga <= 100000 ){
total = harga;
kembali = uang - total;
System.out.println("");
System.out.println("Uang Anda Anda : Rp. "+ uang);
System.out.println("Anda Mendapat Diskon 0%");
System.out.println("");
System.out.println("--------------------------------------");
System.out.println("");
System.out.println("Total Belanja Anda : Rp. "+ total);
if (kembali != 0) {
System.out.println("Kembalian Anda : Rp. "+kembali);
System.out.println("");
}else {
System.out.println("Uang Anda Pas");
System.out.println("");
}
System.out.println("=======================================");
System.out.println("|| ||");
System.out.println("|| Terima Kasih Telah Berbelanja ||");
System.out.println("|| ||");
System.out.println("=======================================");
// Pembelian 100.001 - 200.000 = diskon 5%
} else if (harga <= 200000){
diskon = 5.0/100 * harga;
total = harga - diskon;
kembali = uang - total;
System.out.println("");
System.out.println("Uang Anda Anda : Rp. "+ uang);
System.out.println("Anda Mendapat Diskon 5%");
System.out.println("");
System.out.println("--------------------------------------");
System.out.println("");
System.out.println("Total Belanja Anda : Rp. "+ total);
if (kembali != 0) {
System.out.println("Kembalian Anda : Rp. "+kembali);
System.out.println("");
}else {
System.out.println("Uang Anda Pas");
System.out.println("");
}
System.out.println("=======================================");
System.out.println("|| ||");
System.out.println("|| Terima Kasih Telah Berbelanja ||");
System.out.println("|| ||");
System.out.println("=======================================");
// Pembelian 200.001 - 300.000 = diskon 10%
} else if (harga <= 300000){
diskon = 10.0/100 * harga;
total = harga - diskon;
kembali = uang - total;
System.out.println("");
System.out.println("Uang Anda Anda : Rp. "+ uang);
System.out.println("Anda Mendapat Diskon 10%");
System.out.println("");
System.out.println("--------------------------------------");
System.out.println("");
System.out.println("Total Belanja Anda : Rp. "+ total);
if (kembali != 0) {
System.out.println("Kembalian Anda : Rp. "+kembali);
System.out.println("");
}else {
System.out.println("Uang Anda Pas");
System.out.println("");
}
System.out.println("=======================================");
System.out.println("|| ||");
System.out.println("|| Terima Kasih Telah Berbelanja ||");
System.out.println("|| ||");
System.out.println("=======================================");
// Pembelian 300.001 - 400.000 = diskon 15%
} else if (harga <= 400000){
diskon = 15.0/100 * harga;
total = harga - diskon;
kembali = uang - total;
System.out.println("");
System.out.println("Uang Anda Anda : Rp. "+ uang);
System.out.println("Anda Mendapat Diskon 15%");
System.out.println("");
System.out.println("--------------------------------------");
System.out.println("");
System.out.println("Total Belanja Anda : Rp. "+ total);
if (kembali != 0) {
System.out.println("Kembalian Anda : Rp. "+kembali);
System.out.println("");
}else {
System.out.println("Uang Anda Pas");
System.out.println("");
}
System.out.println("=======================================");
System.out.println("|| ||");
System.out.println("|| Terima Kasih Telah Berbelanja ||");
System.out.println("|| ||");
System.out.println("=======================================");
// Pembelian 400.001 - 500.000 = diskon 20%
} else if (harga <= 500000){
diskon = 20.0/100 * harga;
total = harga - diskon;
kembali = uang - total;
System.out.println("");
System.out.println("Uang Anda Anda : Rp. "+ uang);
System.out.println("Anda Mendapat Diskon 20%");
System.out.println("");
System.out.println("--------------------------------------");
System.out.println("");
System.out.println("Total Belanja Anda : Rp. "+ total);
if (kembali != 0) {
System.out.println("Kembalian Anda : Rp. "+kembali);
System.out.println("");
}else {
System.out.println("Uang Anda Pas");
System.out.println("");
}
System.out.println("=======================================");
System.out.println("|| ||");
System.out.println("|| Terima Kasih Telah Berbelanja ||");
System.out.println("|| ||");
System.out.println("=======================================");
// Pembelian > 500.000 = diskon 25%
} else {
diskon = 25.0/100 * harga;
total = harga - diskon;
kembali = uang - total;
System.out.println("");
System.out.println("Uang Anda Anda : Rp. "+ uang);
System.out.println("Anda Mendapat Diskon 25%");
System.out.println("");
System.out.println("--------------------------------------");
System.out.println("");
System.out.println("Total Belanja Anda : Rp. "+ total);
if (kembali != 0) {
System.out.println("Kembalian Anda : Rp. "+kembali);
System.out.println("");
}else {
System.out.println("Uang Anda Pas");
System.out.println("");
}
System.out.println("=======================================");
System.out.println("|| ||");
System.out.println("|| Terima Kasih Telah Berbelanja ||");
System.out.println("|| ||");
System.out.println("=======================================");
}
}
}
Screenshot :
Pembelian < 100.000 Diskon 0%
Komentar
Posting Komentar