diskon if else
package percabangan;
import java.util.Scanner;
public class diskon {
public static void main(String[] args) {
Scanner input = new Scanner(System.in);
int harga, jumlah, totalJumlah, totalAfterDiskon, noMember;
double diskon, diskonAfterMember;
boolean statusMember;
System.out.print("Masukkan harga: ");
harga = input.nextInt();
System.out.print("Masukkan jumlah beli anda: ");
jumlah = input.nextInt();
totalJumlah = harga * jumlah;
System.out.println("Total: " + totalJumlah);
if (totalJumlah >= 100000 && totalJumlah <= 200000) {
diskon = 0.1 * totalJumlah;
totalAfterDiskon = totalJumlah - (int)diskon;
System.out.println("Harga setelah diskon 10%: " + totalAfterDiskon);
} else if (totalJumlah >= 200001 && totalJumlah <= 300000) {
diskon = 0.2 * totalJumlah;
totalAfterDiskon = totalJumlah - (int)diskon;
System.out.println("Harga setelah diskon 20%: " + totalAfterDiskon);
} else if (totalJumlah >= 300001 && totalJumlah <= 400000) {
diskon = 0.3* totalJumlah;
totalAfterDiskon = totalJumlah - (int)diskon;
System.out.println("Harga setelah diskon 30%: " + totalAfterDiskon);
} else {
System.out.println("Tidak mendapat diskon");
totalAfterDiskon = totalJumlah;
}
System.out.print("Masukkan status member: ");
noMember = input.nextInt();
if (noMember == 1) {
statusMember = true;
if (statusMember) {
diskonAfterMember = totalAfterDiskon * 0.95;
System.out.println("diskonAfterMember: " + diskonAfterMember);
} else {
System.out.println("total Akhir" + totalAfterDiskon);
}
} else if (noMember == 0) {
statusMember = false;
System.out.println("total Akhir: " + totalAfterDiskon);
}
}
}
Comments
Post a Comment