Untitled

mail@pastecode.io avatar
unknown
plain_text
13 days ago
1.5 kB
1
Indexable
Never
import java.util.Scanner;

public class HitungTotalPembelianMinuman {
    public static void main(String[] args) {
        
        Scanner input = new Scanner(System.in);
        int kodeMinuman, kuantitas;
        double harga = 0, total, diskon = 0, totalAkhir;

        
        System.out.print("Masukkan kode minuman (1: Milo, 2: Kopi, 3: Teh Botol, 4: Jus Mangga): ");
        kodeMinuman = input.nextInt();
        System.out.print("Masukkan kuantitas: ");
        kuantitas = input.nextInt();

        
        switch (kodeMinuman) {
            case 1:
                harga = 7500;  
                break;
            case 2:
                harga = 4000;  
                break;
            case 3:
                harga = 3500;  
                break;
            case 4:
                harga = 5000;  
                break;
            default:
                System.out.println("Kode minuman tidak valid!");
                System.exit(0);  
        }

       
        total = harga * kuantitas;

        
        if (total > 100000) {
            diskon = 0.15 * total;  
        } else if (total >= 50000 && total <= 100000) {
            diskon = 0.075 * total;  
        }

        
        totalAkhir = total - diskon;

        
        System.out.println("Total pembelian: Rp " + total);
        System.out.println("Diskon: Rp " + diskon);
        System.out.println("Total yang harus dibayar: Rp " + totalAkhir);

        
        input.close();
    }
}
Leave a Comment