Forum Latihan Switch Case
Source Code :
import java.util.Scanner;
public class ProgSwitch {
public static void main(String[] args) {
// Deklarasi
String menu;
int porsi, tusuk, submenu1, member, submenu2;
// submenu;
double harga=0, uang, diskon, kembali, totalakhir;
Scanner sc = new Scanner(System.in);
System.out.println("======================================");
System.out.println("|| ||");
System.out.println("|| Selamat Datang ||");
System.out.println("|| Warung Sederhana ||");
System.out.println("|| ||");
System.out.println("======================================");
System.out.println("|| ||");
System.out.println("|| Menu Kami ||");
System.out.println("|| ||");
System.out.println("======================================");
System.out.println("|| Sate ||");
System.out.println("|| Pecel ||");
System.out.println("|| Penyetan ||");
System.out.println("======================================");
System.out.println("");
// Program
System.out.print("Pilih Menu : ");
menu = sc.nextLine();
System.out.println("");
switch(menu) {
case "Sate" :
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.0/100*harga;
totalakhir = harga - diskon;
System.out.println("Jadi Totalnya Adalah Rp. "+totalakhir );
System.out.print("Uang yang Dibayarkan : Rp. " );
uang = sc.nextDouble();
kembali = uang - totalakhir;
if(kembali >= 0) {
if(kembali != 0)
{
System.out.println("Uang Anda Kembali Rp. " +kembali );
System.out.println("Terima Kasih Telah Berbelanja" );
}else if (kembali == 0){
System.out.println("Uang Anda Pas" );
System.out.println("Terima Kasih Telah Berbelanja ^^" );
System.out.println("");
System.out.println("==============================");
}
}else {
System.out.print("Salah Menginput Uang" );
System.out.println("");
System.out.println("=================================");
}
}else if(member == 2){
System.out.println("Jadi Totalnya Adalah Rp. "+harga );
System.out.print("Uang yang Dibayarkan : Rp. " );
uang = sc.nextDouble();
kembali = uang - harga;
if(kembali >= 0) {
if(kembali != 0) {
System.out.println("Uang Anda Kembali Rp. "+kembali);
System.out.println("Terima Kasih Telah Berbelanja" );
System.out.println("");
System.out.println("==============================");
}else if (kembali == 0){
System.out.println("Uang Anda Pas" );
System.out.println("Terima Kasih Telah Berbelanja" );
System.out.println("");
System.out.println("==============================");
}
}else {
System.out.println("Salah Menginput Uang" );
System.out.println("");
System.out.println("==============================");
}
}
break;
case "Pecel" :
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.0/100*harga;
totalakhir = harga - diskon;
System.out.println("Jadi Totalnya Adalah Rp. "+totalakhir );
System.out.print("Uang yang Dibayarkan : Rp. " );
uang = sc.nextDouble();
kembali = uang - totalakhir;
if(kembali >= 0) {
if(kembali != 0)
{
System.out.println("Uang Anda Kembali Rp. "+kembali);
System.out.println("Terima Kasih Telah Berbelanja" );
}else if (kembali == 0){
System.out.println("Uang Anda Pas" );
System.out.println("Terima Kasih Telah Berbelanja ^^" );
System.out.println("");
System.out.println("==============================");
}
}else {
System.out.println("Salah Menginput Uang" );
System.out.println("");
System.out.println("==============================");
}
}else if(member == 2){
System.out.println("Jadi Totalnya Adalah Rp. "+harga );
System.out.print("Uang yang Dibayarkan : Rp. " );
uang = sc.nextDouble();
kembali = uang - harga;
if(kembali >= 0) {
if(kembali != 0) {
System.out.println("Uang Anda Kembali Rp. " +kembali );
System.out.println("Terima Kasih Telah Berbelanja" );
System.out.println("");
System.out.println("==============================");
}else if (kembali == 0){
System.out.println("Uang Anda Pas" );
System.out.println("Terima Kasih Telah Berbelanja" );
System.out.println("");
System.out.println("==============================");
}
}else {
System.out.println("Salah Menginput Uang" );
System.out.println("");
System.out.println("==============================");
}
}
break;
case "Penyetan" :
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
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.0/100*harga;
totalakhir = harga - diskon;
System.out.println("Jadi Totalnya Adalah Rp. "+totalakhir );
System.out.print("Uang yang Dibayarkan : Rp. " );
uang = sc.nextDouble();
kembali = uang - totalakhir;
if(kembali >= 0) {
if(kembali != 0){
System.out.println("Uang Anda Kembali Rp. " +kembali );
System.out.println("Terima Kasih Telah Berbelanja" );
}else if (kembali == 0){
System.out.println("Uang Anda Pas" );
System.out.println("Terima Kasih Telah Berbelanja ^^" );
System.out.println("");
System.out.println("=================================");
}
}else {
System.out.println("Salah Menginput Uang" );
System.out.println("");
System.out.println("=================================");
}
}else if(member == 2){
System.out.println("Jadi Totalnya Adalah Rp. "+harga );
System.out.print("Uang yang Dibayarkan : Rp. " );
uang = sc.nextDouble();
kembali = uang - harga;
if(kembali >= 0) {
if(kembali != 0) {
System.out.println("Uang Anda Kembali Rp. "+kembali);
System.out.println("Terima Kasih Telah Berbelanja" );
System.out.println("");
System.out.println("==============================");
}else if (kembali == 0){
System.out.println("Uang Anda Pas" );
System.out.println("Terima Kasih Telah Berbelanja" );
System.out.println("");
System.out.println("==============================");
}
}else {
System.out.println("Salah Menginput Uang" );
System.out.println("");
System.out.println("==============================");
}
}
break;
default :
System.out.println("Pilih Menu yang diatas yaa....");
}
}
}
Screenshot :
Jika Memesan Sate, memiliki Member dan Uang Kembali
Komentar
Posting Komentar