Skip to content

Instantly share code, notes, and snippets.

@rafirh
Created December 15, 2023 14:23
Show Gist options
  • Save rafirh/637cc140858191d7b954089592044dd5 to your computer and use it in GitHub Desktop.
Save rafirh/637cc140858191d7b954089592044dd5 to your computer and use it in GitHub Desktop.
import java.io.*;
import java.util.*;
public class Solution {
public static String formatRupiah(int nominal) {
String strNominal = String.valueOf(nominal);
String strNominalFormatted = "";
int counter = 0;
for (int i = strNominal.length() - 1; i >= 0; i--) {
strNominalFormatted = strNominal.charAt(i) + strNominalFormatted;
counter++;
if (counter == 3 && i != 0) {
strNominalFormatted = "." + strNominalFormatted;
counter = 0;
}
}
return strNominalFormatted;
}
public static void main(String[] args) {
/* Enter your code here. Read input from STDIN. Print output to STDOUT. Your class should be named Solution. */
Scanner scanner = new Scanner(System.in);
int menu = Integer.parseInt(scanner.nextLine());
int jumlah = Integer.parseInt(scanner.nextLine());
int hargaNasiGoreng = 20000;
int hargaMieGoreng = 30000;
int total = 0;
String namaMenu = "";
int hargaMenu = 0;
if (menu == 1) {
total = hargaNasiGoreng * jumlah;
namaMenu = "Nasi Goreng";
hargaMenu = hargaNasiGoreng;
} else if (menu == 2) {
total = hargaMieGoreng * jumlah;
namaMenu = "Mie Goreng";
hargaMenu = hargaMieGoreng;
}
if (jumlah > 20) {
total = total - (total * 20 / 100);
}
System.out.println("Nama Pesanan\t= " + namaMenu);
System.out.println("Jumlah Pesanan\t= " + jumlah);
System.out.println("Harga Pesanan\t= " + formatRupiah(hargaMenu));
System.out.println("Total Pesanan\t= " + formatRupiah(total));
if (jumlah < 2) {
System.out.println("belanja lagi dong");
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment