Forum Latihan Perulangan Tunggal
Source Code :
public class ProgLooping {
public static void main(String[] args) {
// Deklarasi
int menu, porsi, tusuk, submenu1, member, submenu2, pesanan = 1, harga=0, diskon, totalakhir, bayar = 0;
Scanner sc = new Scanner(System.in);
System.out.println("");
System.out.println(" Selamat Datang ");
System.out.println(" Warung Sederhana ");
System.out.println("====================================");
System.out.println("Menu Kami");
System.out.println("====================================");
System.out.println("1. Sate ");
System.out.println("2. Pecel ");
System.out.println("3. Penyetan ");
System.out.println("====================================");
System.out.println("");
for(int proses = 0; proses < pesanan; proses++){
System.out.print("Pilih Menu (Menggunakan Angka): ");
menu = sc.nextInt();
switch(menu){
case 1 :
System.out.println("");
System.out.println("====================================");
System.out.println("1. Ayam = Rp. 1.500/Tusuk ");
System.out.println("2. Kambing = Rp. 3.000/Tusuk ");
System.out.println("====================================");
System.out.println("");
System.out.print("Pilih Sate Apa (Menggunakan Angka): ");
submenu1 = sc.nextInt();
if(submenu1 == 1) {
System.out.println("Anda Memilih Sate Ayam");
System.out.print("Berapa tusuk : ");
tusuk = sc.nextInt();
harga = tusuk * 1500;
System.out.println("Total Belanja Anda : Rp."+harga);
} else if (submenu1 == 2) {
System.out.println("Anda Memilih Sate Kambing");
System.out.print("Berapa tusuk : ");
tusuk = sc.nextInt();
harga = tusuk * 3000;
System.out.println("Total Belanja Anda : Rp."+harga);
System.out.println("");
} else {
System.out.println("");
System.out.print("Tidak ada sate itu");
}
// Proses Pembayaran
System.out.println("");
System.out.println("=========================================");
System.out.println("");
System.out.println("Apakah Punya Member ?" );
System.out.println("1. Ya" );
System.out.println("2. Tidak");
System.out.print("Klik Angka : " );
member = sc.nextInt();
System.out.println("");
if(member == 1) {
System.out.println("=========================================");
System.out.println("");
System.out.println("Selamat Anda Mendapatkan Diskon 5%" );
diskon = 5/100*harga;
totalakhir = harga - diskon;
bayar = bayar + totalakhir;
System.out.println("Jadi Totalnya Adalah Rp. "+totalakhir );
}else if(member == 2){
bayar = bayar + harga;
System.out.println("Jadi Totalnya Adalah Rp. "+harga );
}else {
System.out.println("Salah Menginput Uang" );
System.out.println("");
System.out.println("=========================================");
}
break;
case 2 :
System.out.println("");
System.out.println("====================================");
System.out.println("1. Lauk Ayam = Rp. 13.000/Porsi ");
System.out.println("2. Lauk Empal = Rp. 15.000/Porsi ");
System.out.println("====================================");
System.out.println("");
System.out.print("Pilih Lauk Apa (Menggunakan Angka): ");
submenu1 = sc.nextInt();
if(submenu1 == 1) {
System.out.println("Anda Memilih Lauk Ayam");
System.out.print("Berapa porsi : ");
porsi = sc.nextInt();
harga = porsi * 13000;
System.out.println("Total Belanja Anda : Rp."+harga);
} else if (submenu1 == 2) {
System.out.println("Anda Memilih Lauk Empal");
System.out.print("Berapa porsi : ");
porsi = sc.nextInt();
harga = porsi * 150000;
System.out.println("Total Belanja Anda : Rp."+harga);
} else {
System.out.println("");
System.out.print("Tidak ada Lauk itu");
}
// Proses Pembayaran
System.out.println("");
System.out.println("=========================================");
System.out.println("");
System.out.println("Apakah Punya Member ?" );
System.out.println("1. Ya" );
System.out.println("2. Tidak");
System.out.print("Klik Angka : " );
member = sc.nextInt();
System.out.println("");
if(member == 1) {
System.out.println("=========================================");
System.out.println("");
System.out.println("Selamat Anda Mendapatkan Diskon 5%" );
diskon = 5/100*harga;
totalakhir = harga - diskon;
bayar = bayar + totalakhir;
System.out.println("Jadi Totalnya Adalah Rp. "+totalakhir );
}else if(member == 2){
bayar = bayar + harga;
System.out.println("Jadi Totalnya Adalah Rp. "+harga );
}else {
System.out.println("Salah Menginput Uang" );
System.out.println("");
System.out.println("=========================================");
}
break;
case 3 :
System.out.println("");
System.out.println("====================================");
System.out.println("1. Lauk Tahu&Tempe = Rp. 5.000/Porsi");
System.out.println("2. Lauk Telur = Rp. 7.000/Porsi ");
System.out.println("3. Lauk Ayam = Rp. 10.000/Porsi ");
System.out.println("====================================");
System.out.println("");
System.out.print("Pilih Lauk Diatas (Menggunakan Angka) : ");
submenu2 = sc.nextInt();
switch(submenu2) {
case 1 :
System.out.println("Anda Memilih Lauk Tahu & Tempe");
System.out.print("Berapa Porsi : ");
porsi = sc.nextInt();
harga = porsi*5000;
System.out.println("Total Belanja Anda : Rp."+harga);
break;
case 2 :
System.out.println("Anda Memilih Lauk Telur");
System.out.print("Berapa Porsi : ");
porsi = sc.nextInt();
harga = porsi*7000;
System.out.println("Total Belanja Anda : Rp."+harga);
break;
case 3 :
System.out.println("Anda Memilih Lauk Ayam");
System.out.print("Berapa Porsi : ");
porsi = sc.nextInt();
harga = porsi*10000;
System.out.println("Total Belanja Anda : Rp."+harga);
break;
default :
System.out.println("Tidak Ada Lauk Itu....");
}
// Proses Pembayaran Penyetan
System.out.println("");
System.out.println("=========================================");
System.out.println("");
System.out.println("Apakah Punya Member ?" );
System.out.println("1. Ya" );
System.out.println("2. Tidak");
System.out.print("Klik Angka : " );
member = sc.nextInt();
System.out.println("");
if(member == 1) {
System.out.println("=========================================");
System.out.println("");
System.out.println("Selamat Anda Mendapatkan Diskon 5%" );
diskon = 5/100*harga;
totalakhir = harga - diskon;
bayar = bayar + totalakhir;
System.out.println("Jadi Totalnya Adalah Rp. "+totalakhir );
}else if(member == 2){
bayar = bayar + harga;
System.out.println("Jadi Totalnya Adalah Rp. "+harga );
}else {
System.out.println("Salah Menginput Uang" );
System.out.println("");
System.out.println("=========================================");
}
break;
default :
System.out.println("Pilih Menu yang diatas yaa....");
break;
}//tutup switch case utama
System.out.println("");
System.out.print("Apakah Mau Memesan Lagi? (ya/tidak) : ");
String jawab = sc.next();
switch(jawab){
case "ya":
pesanan++;
break;
case "tidak":
break;
default:
System.out.print("Ketik Ya/Tidak saja");
break;
}//tutup switch untuk loop
}// tutupnya for
System.out.println("Total anda memesan : "+pesanan);
System.out.println("Uang yang harus dibayar : Rp. "+bayar);
}
}
Komentar
Posting Komentar