Perulangan Tunggal
public class NewClass {
public static void main(String[] args) {
NumberFormat hrg = NumberFormat.getInstance();
hrg.setMaximumFractionDigits(3);
Scanner sc = new Scanner(System.in);
int pilih, pilih2, jmlhmakanan, jmlhminum, kartu;
double totalhargasate=0,totalhargapecel=0, totalhargapenyetan=0, hrgdiskon,
uangpembeli, kembalian, nominaldiskon, totalhrg, totalhargateh=0,
totalhargasusu=0, totalhargaair=0, totalhargapop=0;
do{
System.out.println("\nWarung Simpel");
System.out.println("Menu Makanan");
System.out.println("1. Sate");
System.out.println("2. Pecel");
System.out.println("3. Penyetan");
System.out.println("4. Menu Minuman");
System.out.print("Pilih = ");
pilih = sc.nextInt();
switch(pilih){
case 1 :
System.out.println(" Jenis Sate");
System.out.println(" 1. Sate Ayam Rp.1,500 perTusuk");
System.out.println(" 2. Sate Kambing Rp.3,000 perTusuksate" );
System.out.print("Pilih Jenis Sate = ");
pilih2 = sc.nextInt();
switch (pilih2) {
case 1:
System.out.println("Sate Ayam");
System.out.print("Masukkan Jumlah Tusukan = ");
jmlhmakanan = sc.nextInt();
totalhargasate = jmlhmakanan * 1500;
break;
case 2:
System.out.println("Sate Kambing");
System.out.print("Masukkan Jumlah Tusukan = ");
jmlhmakanan = sc.nextInt();
totalhargasate = jmlhmakanan * 3000;
break;
default:
System.out.println("Pilihan Jenis Sate Salah!");
break;
}
break;
case 2 :
System.out.println(" Jenis Pecel");
System.out.println(" 1. Lauk Ayam Rp.13,000 perPorsi");
System.out.println(" 2. Lauk Empal Rp.15,000 perPorsi");
System.out.print("Pilih Jenis Lauk = ");
pilih2 = sc.nextInt();
switch (pilih2) {
case 1:
System.out.println("Pecel Lauk Ayam");
System.out.print("Masukkan Jumlah Porsi = ");
jmlhmakanan = sc.nextInt();
totalhargapecel = jmlhmakanan * 13000;
break;
case 2:
System.out.println("Pecel Lauk Empal");
System.out.print("Masukkan Jumlah Porsi = ");
jmlhmakanan = sc.nextInt();
totalhargapecel = jmlhmakanan * 15000;
break;
default:
System.out.println("Pilihan Jenis Pecel Salah!");
break;
}
break;
case 3 :
System.out.println(" Jenis Penyetan");
System.out.println(" 1. Lauk Tahu/Tempe Rp.5,000 perPorsi");
System.out.println(" 2. Lauk Telur Rp.7,000 perPorsi");
System.out.println(" 3. Lauk Ayam Rp.10,000 perPorsi");
System.out.print("Pilih Jenis Lauk = ");
pilih2 = sc.nextInt();
switch (pilih2) {
case 1:
System.out.println("Penyetan Lauk Tahu/Tempe");
System.out.print("Masukkan Jumlah Porsi = ");
jmlhmakanan = sc.nextInt();
totalhargapenyetan = jmlhmakanan * 5000;
break;
case 2:
System.out.println("Penyetan Lauk Telur");
System.out.print("Masukkan Jumlah Porsi = ");
jmlhmakanan = sc.nextInt();
totalhargapenyetan = jmlhmakanan * 7000;
break;
case 3:
System.out.println("Penyetan Lauk Ayam");
System.out.print("Masukkan Jumlah Porsi = ");
jmlhmakanan = sc.nextInt();
totalhargapenyetan = jmlhmakanan * 10000;
break;
default:
System.out.println("Pilihan Jenis Penyetan Salah!");
break;
}
break;
}
}while(pilih != 4);
do{
System.out.println("\nMenu Minuman");
System.out.println("1. Es Teh Rp.4,000");
System.out.println("2. Es Susu Rp.4,000");
System.out.println("3. Air Putih Rp.2,000");
System.out.println("4. Pop Ice Rp.5,000");
System.out.println("5. Pembayaran");
System.out.print("Pilih = ");
pilih = sc.nextInt();
switch(pilih){
case 1 :
System.out.print("Masukkan Jumlah Es Teh = ");
jmlhminum = sc.nextInt();
totalhargateh = jmlhminum * 4000;
break;
case 2 :
System.out.print("Masukkan Jumlah Es Susu = ");
jmlhminum = sc.nextInt();
totalhargasusu = jmlhminum * 4000;
break;
case 3 :
System.out.print("Masukkan Jumlah Air Putih = ");
jmlhminum = sc.nextInt();
totalhargaair = jmlhminum * 2000;
break;
case 4 :
System.out.print("Masukkan Jumlah Pop Ice = ");
jmlhminum = sc.nextInt();
totalhargapop = jmlhminum * 5000;
break;
case 5 :
totalhrg = totalhargasate + totalhargapecel + totalhargapenyetan + totalhargateh + totalhargasusu + totalhargaair + totalhargapop;
System.out.println("\nApakah Ada Kartu Member?");
System.out.println(" 1. Ada");
System.out.println(" 2. Tidak");
System.out.print("Pilih = ");
kartu = sc.nextInt();
System.out.println("");
switch (kartu) {
case 1:
System.out.println("Mendapat Diskon 5%");
System.out.println("Harga Sebelum Diskon = Rp." + hrg.format(totalhrg));
// Menghitung Diskonan
nominaldiskon = totalhrg * 5 / 100;
hrgdiskon = totalhrg - nominaldiskon;
System.out.println("Harga Setelah Diskon = Rp." + hrg.format(hrgdiskon));
System.out.print("Masukkan Uang Pembeli = Rp.");
uangpembeli = sc.nextDouble();
if (uangpembeli >= totalhrg) {
kembalian = uangpembeli - hrgdiskon;
System.out.println("Kembalian = Rp." + hrg.format(kembalian));
} else{
System.out.println("Uang Pembeli Kurang!");
}
break;
case 2:
System.out.println("Tidak Mendapat Diskon");
System.out.println("Total Harga = Rp." + hrg.format(totalhrg));
System.out.print("Masukkan Uang Pembeli = Rp.");
uangpembeli = sc.nextDouble();
if (uangpembeli >= totalhrg) {
kembalian = uangpembeli - totalhrg;
System.out.println("Kembalian = Rp." + hrg.format(kembalian));
} else{
System.out.println("Uang Pembeli Kurang!");
}
break;
default:
System.out.println("Pemilihan Salah!");
break;
}
break;
default :
System.out.println("Pilihan Salah!");
break;
}
}while(pilih != 5);
}
}
Comments
Post a Comment