Latihan Switch Case "Program Kasir Rumah Makan"
Nama ; Rayhan Qalby Ramadhan
NPM : 21082010008
Source Code :
package switchcase;
import java.text.NumberFormat;
import java.util.Scanner;
public class RumahMakan {
public static void main(String[] args) {
NumberFormat hrg = NumberFormat.getInstance();
hrg.setMaximumFractionDigits(3);
Scanner sc = new Scanner(System.in);
int pilih, pilih2, jumlahmakanan, kartumember;
double totalharga, hargadiskon, uangpembeli, uangkembali, nominaldiskon;
System.out.println("---------- SELAMAT DATANG ----------");
System.out.println("------- RUMAH MAKAN PAK KIRUN ------");
System.out.println("--------ANDA PUAS KAMI SENANG--------");
System.out.println("Menu Makanan");
System.out.println(" 1.Sate");
System.out.println(" 2.Pecel");
System.out.println(" 3.Penyetan");
System.out.print("Pilih = ");
pilih = sc.nextInt();
System.out.println("----------------------");
switch(pilih){
case 1 :
System.out.println("Jenis Sate");
System.out.println(" 1. Sate Ayam Madura");
System.out.println(" 2. Sate Kambing Malang");
System.out.print("Pilih Jenis Sate = ");
pilih2 = sc.nextInt();
//Sate Ayam Madura
if(pilih2==1){
System.out.println("Sate Ayam Madura");
System.out.print("Masukkan Jumlah Tusuk = ");
jumlahmakanan = sc.nextInt();
totalharga = jumlahmakanan * 1500;
System.out.println("--------------------");
System.out.println("Apakah Ada Kartu Member");
System.out.println(" 1.Ada");
System.out.println(" 2.Tidak Ada");
System.out.print("Pilih = ");
kartumember = sc.nextInt();
System.out.println("------------------------");
if(kartumember==1){
System.out.println("Selamat Anda Mendapatkan Diskon 5%");
System.out.println("Harga Sebelum Diskon = Rp. "+hrg.format(totalharga));
//Menghitung Diskon
nominaldiskon = totalharga * 5/100;
hargadiskon = totalharga - nominaldiskon;
System.out.println("Harga Setelah Diskon = Rp. "+hrg.format(hargadiskon));
System.out.print("Masukkan Uang Pembeli = Rp. ");
uangpembeli = sc.nextDouble();
if(uangpembeli>=totalharga){
uangkembali = uangpembeli - hargadiskon;
System.out.println("Uang Kembali = Rp. "+hrg.format(uangkembali));
}else{
System.out.println("Uang Pembeli Kurang!!");
}
}else if(kartumember==2){
System.out.println("Tidak Mendapatkan Diskon");
System.out.println("Total Harga = Rp. "+hrg.format(totalharga));
System.out.print("Masukkan Uang Pembeli = Rp. ");
uangpembeli = sc.nextDouble();
if(uangpembeli>=totalharga){
uangkembali = uangpembeli - totalharga;
System.out.println("Uang Kembali = Rp. "+hrg.format(uangkembali));
}else{
System.out.println("Uang Pembeli Kurang!!");
}
}else{
System.out.println("Pemilihan Salah!!");
}
}
//Sate Kambing Malang
if(pilih2==2){
System.out.println("Sate Kambing Malang");
System.out.print("Masukkan Jumlah Tusuk = ");
jumlahmakanan = sc.nextInt();
totalharga = jumlahmakanan * 3000;
System.out.println("--------------------");
System.out.println("Apakah Ada Kartu Member");
System.out.println(" 1.Ada");
System.out.println(" 2.Tidak Ada");
System.out.print("Pilih = ");
kartumember = sc.nextInt();
System.out.println("------------------------");
if(kartumember==1){
System.out.println("Selamat Anda Mendapatkan Diskon 5%");
System.out.println("Harga Sebelum Diskon = Rp. "+hrg.format(totalharga));
//Menghitung Diskon
nominaldiskon = totalharga * 5/100;
hargadiskon = totalharga - nominaldiskon;
System.out.println("Harga Setelah Diskon = Rp. "+hrg.format(hargadiskon));
System.out.print("Masukkan Uang Pembeli = Rp. ");
uangpembeli = sc.nextDouble();
if(uangpembeli>=totalharga){
uangkembali = uangpembeli - hargadiskon;
System.out.println("Uang Kembali = Rp. "+hrg.format(uangkembali));
}else{
System.out.println("Uang Pembeli Kurang!!");
}
}else if(kartumember==2){
System.out.println("Tidak Mendapatkan Diskon");
System.out.println("Total Harga = Rp. "+hrg.format(totalharga));
System.out.print("Masukkan Uang Pembeli = Rp. ");
uangpembeli = sc.nextDouble();
if(uangpembeli>=totalharga){
uangkembali = uangpembeli - totalharga;
System.out.println("Uang Kembali = Rp. "+hrg.format(uangkembali));
}else{
System.out.println("Uang Pembeli Kurang!!");
}
}else{
System.out.println("Pemilihan Salah!!");
}
}
else{
System.out.println("Maaf Jenis Sate Yang Dipilih Tidak Ada");
}
break;
case 2 :
System.out.println("Jenis Pecel Lamongan");
System.out.println(" 1. Lauk Ayam");
System.out.println(" 2. Lauk Empal");
System.out.print("Pilih Jenis Lauk = ");
pilih2 = sc.nextInt();
//Jenis Lauk Ayam
if(pilih2==1){
System.out.println("Pecel Lamongan Lauk Ayam");
System.out.print("Masukkan Jumlah Porsi = ");
jumlahmakanan = sc.nextInt();
totalharga = jumlahmakanan * 13000;
System.out.println("--------------------");
System.out.println("Apakah Ada Kartu Member");
System.out.println(" 1.Ada");
System.out.println(" 2.Tidak Ada");
System.out.print("Pilih = ");
kartumember = sc.nextInt();
System.out.println("------------------------");
if(kartumember==1){
System.out.println("Selamat Anda Mendapatkan Diskon 5%");
System.out.println("Harga Sebelum Diskon = Rp. "+hrg.format(totalharga));
//Menghitung Diskon
nominaldiskon = totalharga * 5/100;
hargadiskon = totalharga - nominaldiskon;
System.out.println("Harga Setelah Diskon = Rp. "+hrg.format(hargadiskon));
System.out.print("Masukkan Uang Pembeli = Rp. ");
uangpembeli = sc.nextDouble();
if(uangpembeli>=totalharga){
uangkembali = uangpembeli - hargadiskon;
System.out.println("Uang Kembali = Rp. "+hrg.format(uangkembali));
}else{
System.out.println("Uang Pembeli Kurang!!");
}
}else if(kartumember==2){
System.out.println("Tidak Mendapatkan Diskon");
System.out.println("Total Harga = Rp. "+hrg.format(totalharga));
System.out.print("Masukkan Uang Pembeli = Rp. ");
uangpembeli = sc.nextDouble();
if(uangpembeli>=totalharga){
uangkembali = uangpembeli - totalharga;
System.out.println("Uang Kembali = Rp. "+hrg.format(uangkembali));
}else{
System.out.println("Uang Pembeli Kurang!!");
}
}else{
System.out.println("Pemilihan Salah!!");
}
}
//Jenis Lauk Empal
if(pilih2==2){
System.out.println("Pecel Lamongan Lauk Empal");
System.out.print("Masukkan Jumlah Porsi = ");
jumlahmakanan = sc.nextInt();
totalharga = jumlahmakanan * 15000;
System.out.println("--------------------");
System.out.println("Apakah Ada Kartu Member");
System.out.println(" 1.Ada");
System.out.println(" 2.Tidak Ada");
System.out.print("Pilih = ");
kartumember = sc.nextInt();
System.out.println("------------------------");
if(kartumember==1){
System.out.println("Selamat Anda Mendapatkan Diskon 5%");
System.out.println("Harga Sebelum Diskon = Rp. "+hrg.format(totalharga));
//Menghitung Diskon
nominaldiskon = totalharga * 5/100;
hargadiskon = totalharga - nominaldiskon;
System.out.println("Harga Setelah Diskon = Rp. "+hrg.format(hargadiskon));
System.out.print("Masukkan Uang Pembeli = Rp. ");
uangpembeli = sc.nextDouble();
if(uangpembeli>=totalharga){
uangkembali = uangpembeli - hargadiskon;
System.out.println("Uang Kembali = Rp. "+hrg.format(uangkembali));
}else{
System.out.println("Uang Pembeli Kurang!!");
}
}else if(kartumember==2){
System.out.println("Tidak Mendapatkan Diskon");
System.out.println("Total Harga = Rp. "+hrg.format(totalharga));
System.out.print("Masukkan Uang Pembeli = Rp. ");
uangpembeli = sc.nextDouble();
if(uangpembeli>=totalharga){
uangkembali = uangpembeli - totalharga;
System.out.println("Uang Kembali = Rp. "+hrg.format(uangkembali));
}else{
System.out.println("Uang Pembeli Kurang!!");
}
}else{
System.out.println("Pemilihan Salah!!");
}
}
else{
System.out.println("Maaf Jenis Pecel Lamongan Tidak Tersedia");
}
break;
case 3 :
System.out.println("Jenis Penyetan Reog");
System.out.println(" 1. Lauk Tahu/Tempe");
System.out.println(" 2. Lauk Telur");
System.out.println(" 3. Lauk Ayam");
System.out.print("Pilih Jenis Lauk = ");
pilih2 = sc.nextInt();
switch(pilih2){
case 1 :
System.out.println("Penyetan Reog Lauk Tahu/Tempe");
System.out.print("Masukkan Jumlah Porsi = ");
jumlahmakanan = sc.nextInt();
totalharga = jumlahmakanan * 5000;
System.out.println("--------------------");
System.out.println("Apakah Ada Kartu Member");
System.out.println(" 1.Ada");
System.out.println(" 2.Tidak Ada");
System.out.print("Pilih = ");
kartumember = sc.nextInt();
System.out.println("------------------------");
if(kartumember==1){
System.out.println("Selamat Anda Mendapatkan Diskon 5%");
System.out.println("Harga Sebelum Diskon = Rp. "+hrg.format(totalharga));
//Menghitung Diskon
nominaldiskon = totalharga * 5/100;
hargadiskon = totalharga - nominaldiskon;
System.out.println("Harga Setelah Diskon = Rp. "+hrg.format(hargadiskon));
System.out.print("Masukkan Uang Pembeli = Rp. ");
uangpembeli = sc.nextDouble();
if(uangpembeli>=totalharga){
uangkembali = uangpembeli - hargadiskon;
System.out.println("Uang Kembali = Rp. "+hrg.format(uangkembali));
}else{
System.out.println("Uang Pembeli Kurang!!");
}
}else if(kartumember==2){
System.out.println("Tidak Mendapatkan Diskon");
System.out.println("Total Harga = Rp. "+hrg.format(totalharga));
System.out.print("Masukkan Uang Pembeli = Rp. ");
uangpembeli = sc.nextDouble();
if(uangpembeli>=totalharga){
uangkembali = uangpembeli - totalharga;
System.out.println("Uang Kembali = Rp. "+hrg.format(uangkembali));
}else{
System.out.println("Uang Pembeli Kurang!!");
}
}else{
System.out.println("Pemilihan Salah!!");
}
break;
case 2 :
System.out.println("Penyetan Reog Lauk Telur");
System.out.print("Masukkan Jumlah Porsi = ");
jumlahmakanan = sc.nextInt();
totalharga = jumlahmakanan * 7000;
System.out.println("--------------------");
System.out.println("Apakah Ada Kartu Member");
System.out.println(" 1.Ada");
System.out.println(" 2.Tidak Ada");
System.out.print("Pilih = ");
kartumember = sc.nextInt();
System.out.println("------------------------");
if(kartumember==1){
System.out.println("Selamat Anda Mendapatkan Diskon 5%");
System.out.println("Harga Sebelum Diskon = Rp. "+hrg.format(totalharga));
//Menghitung Diskon
nominaldiskon = totalharga * 5/100;
hargadiskon = totalharga - nominaldiskon;
System.out.println("Harga Setelah Diskon = Rp. "+hrg.format(hargadiskon));
System.out.print("Masukkan Uang Pembeli = Rp. ");
uangpembeli = sc.nextDouble();
if(uangpembeli>=totalharga){
uangkembali = uangpembeli - hargadiskon;
System.out.println("Uang Kembali = Rp. "+hrg.format(uangkembali));
}else{
System.out.println("Uang Pembeli Kurang!!");
}
}else if(kartumember==2){
System.out.println("Tidak Mendapatkan Diskon");
System.out.println("Total Harga = Rp. "+hrg.format(totalharga));
System.out.print("Masukkan Uang Pembeli = Rp. ");
uangpembeli = sc.nextDouble();
if(uangpembeli>=totalharga){
uangkembali = uangpembeli - totalharga;
System.out.println("Uang Kembali = Rp. "+hrg.format(uangkembali));
}else{
System.out.println("Uang Pembeli Kurang!!");
}
}else{
System.out.println("Pemilihan Salah!!");
}
break;
case 3 :
System.out.println("Penyetan Reog Lauk Ayam");
System.out.print("Masukkan Jumlah Porsi = ");
jumlahmakanan = sc.nextInt();
totalharga = jumlahmakanan * 10000;
System.out.println("--------------------");
System.out.println("Apakah Ada Kartu Member");
System.out.println(" 1.Ada");
System.out.println(" 2.Tidak Ada");
System.out.print("Pilih = ");
kartumember = sc.nextInt();
System.out.println("------------------------");
if(kartumember==1){
System.out.println("Selamat Anda Mendapatkan Diskon 5%");
System.out.println("Harga Sebelum Diskon = Rp. "+hrg.format(totalharga));
//Menghitung Diskon
nominaldiskon = totalharga * 5/100;
hargadiskon = totalharga - nominaldiskon;
System.out.println("Harga Setelah Diskon = Rp. "+hrg.format(hargadiskon));
System.out.print("Masukkan Uang Pembeli = Rp. ");
uangpembeli = sc.nextDouble();
if(uangpembeli>=totalharga){
uangkembali = uangpembeli - hargadiskon;
System.out.println("Uang Kembali = Rp. "+hrg.format(uangkembali));
}else{
System.out.println("Uang Pembeli Kurang!!");
}
}else if(kartumember==2){
System.out.println("Tidak Mendapatkan Diskon");
System.out.println("Total Harga = Rp. "+hrg.format(totalharga));
System.out.print("Maukkan Uang Pembeli = Rp. ");
uangpembeli = sc.nextDouble();
if(uangpembeli>=totalharga){
uangkembali = uangpembeli - totalharga;
System.out.println("Uang Kembali = Rp. "+hrg.format(uangkembali));
}else{
System.out.println("Uang Pembeli Kurang!!");
}
}else{
System.out.println("Pemilihan Salah!!");
}
break;
default:
System.out.println("Maaf Jenis Penyetan Reog Tidak Tersedia");
break;
}
break;
default:
System.out.println("Menu Tidak Ada");
break;
}
System.out.println("Terima Kasih");
System.out.println("Selamat Datang Kembali");
}
}
Comments
Post a Comment