Skip to content

Instantly share code, notes, and snippets.

@nyancodeid
Created February 4, 2021 10:53
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save nyancodeid/0fcabb12e24414ffd2a581fce47271d3 to your computer and use it in GitHub Desktop.
Save nyancodeid/0fcabb12e24414ffd2a581fce47271d3 to your computer and use it in GitHub Desktop.
Tugas Praktikum 3.8 - 2
/**
* @author Ryan Aunur Rassyid
**/
import java.io.*;
public class RyanAunurR_T382 {
public static void main(String[] args) {
BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));
final int DISKON_5_PERSEN = 5;
final int DISKON_10_PERSEN = 10;
final int DISKON_15_PERSEN = 15;
int noTransaksi, totalBelanja = 0;
try {
System.out.print("No. Transaksi : ");
noTransaksi = Integer.parseInt(reader.readLine());
System.out.print("Total Belanja : ");
totalBelanja = Integer.parseInt(reader.readLine());
int discount = 0;
int potonganBayar = 0;
if (totalBelanja > 50_000) {
discount += 10;
}
if (noTransaksi <= 50) {
discount += 5;
}
switch (discount) {
case DISKON_5_PERSEN:
potonganBayar = (int) (totalBelanja * ((double) DISKON_5_PERSEN / 100));
break;
case DISKON_10_PERSEN:
potonganBayar = (int) (totalBelanja * ((double) DISKON_10_PERSEN / 100));
break;
case DISKON_15_PERSEN:
potonganBayar = (int) (totalBelanja * ((double) DISKON_15_PERSEN / 100));
break;
}
int totalBayar = totalBelanja - potonganBayar;
System.out.println("\nPotongan\t: Rp. " + potonganBayar + " (" + discount + "%)");
System.out.println("Total Bayar : Rp. " + (totalBayar));
} catch (Exception e) {
System.out.println("Harap masukkan data dengan benar.");
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment