Program Java Function
Program Memilih Menu Makanan dan Minuman
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.Scanner;
public class fungsi3{
public static void main(String[] args) {
Scanner input = new Scanner (System.in);
int pilih = 4;
do{
try {
System.out.println("---------------------------------------");
System.out.println("| SELAMAT DATANG DI DEPOT SERBA MAHAL |");
System.out.println("---------------------------------------");
System.out.println("| SILAHKAN PILIH MENU YANG ANDA PILIH |");
System.out.println("---------------------------------------");
System.out.println("======================================= ");
System.out.println("| 1. Daftar Menu Makanan |");
System.out.println("======================================= ");
System.out.println("| 2. Daftar Menu Minuman |");
System.out.println("======================================= ");
System.out.println("| 3. Keluar |");
System.out.println("======================================= ");
System.out.print("Pilih menu anda = ");
pilih = input.nextInt();
switch(pilih){
case 1: makanan(); break;
case 2: minuman(); break;
case 3: break;
default : System.out.println("Menu yang anda pilih tidak tersedia!!");
}
}catch(Exception e){
System.out.println("Maaf Hanya bisa Angka!!");
input.next();
}}while(pilih !=3);
}
private static void makanan(){
Scanner input = new Scanner (System.in);
BufferedReader input2 = new BufferedReader (new InputStreamReader (System.in));
int i = 0;
int pil ;
int hargatotal = 0;
int penampung = 0;
String menu[] = new String [100];
int harga[] = new int [100];
String keputusan="Y";
while (keputusan.equals("Y")||keputusan.equals("y"))
{
System.out.println("======================================= ");
System.out.println("| Daftar Menu Makanan dan Minuman |");
System.out.println("======================================= ");
System.out.println("| 1. Nasi Goreng = Rp 100.000 |");
System.out.println("| 2. Mie Goreng = Rp 100.000 |");
System.out.println("| 3. Cap Jay = Rp 90.000 |");
System.out.println("| 4. Ayam Goreng = Rp 200.000 |");
System.out.println("| 5. Ayam Bakar = Rp 200.000 |");
System.out.println("| 6. Mujaer Goreng = Rp 150.000 |");
System.out.println("| 7. Mujaer Bakar = Rp 150.000 |");
System.out.println("| 8. Gurame Goreng = Rp 250.000 |");
System.out.println("| 9. Gurame Bakar = Rp 250.000 |");
System.out.println("| 10. Sambal Terong = Rp 100.000 |");
System.out.println("| 11. Nasi Pecel = Rp 120.000 |");
System.out.println("| 12. Nasi Rawon = Rp 150.000 |");
System.out.println("| 13. Nasi Lele = Rp 170.000 |");
System.out.println("| 14. Nasi Campur = Rp 130.000 |");
System.out.println("| 15. Nasi Tempe Penyet = Rp 150.000 |");
System.out.println("| 16. Nasi Padang = Rp 190.000 |");
System.out.println("| 17. Nasi Peteng = Rp 190.000 |");
System.out.println("| 18. Soto = Rp 160.000 |");
System.out.println("| 19. Kare Ayam = Rp 150.000 |");
System.out.println("| 20. Krupuk = Rp 50.000 |");
System.out.println("---------------------------------------");
System.out.print("Pilih menu anda = ");
pil = input.nextInt();
if (pil==1){
menu[i] = "Nasi Goreng";
harga[i] = 100000;
} else if (pil==2) {
menu[i]= "Mie Goreng";
harga[i] = 100000;
} else if (pil==3) {
menu[i]= "Cap Jay";
harga[i] = 90000;
} else if (pil==4) {
menu[i]= "Ayam Goreng";
harga[i] = 200000;
} else if (pil==5) {
menu[i]= "Ayam Bakar";
harga[i] = 200000;
} else if (pil==6) {
menu[i]= "Mujaer Goreng";
harga[i] = 150000;
} else if (pil==7) {
menu[i]= "Mujaer Bakar";
harga[i] = 150000;
} else if (pil==8) {
menu[i]= "Gurame Goreng";
harga[i] = 250000;
} else if (pil==9) {
menu[i]= "Gurame Bakar";
harga[i] = 250000;
} else if (pil==10) {
menu[i]= "Sambal Terong";
harga[i] = 100000;
} else if (pil==11) {
menu[i]= "Nasi Pecel";
harga[i] = 120000;
} else if (pil==12) {
menu[i]= "Nasi Rawon";
harga[i] = 150000;
} else if (pil==13) {
menu[i]= "Nasi Lele";
harga[i] = 170000;
} else if (pil==14) {
menu[i]= "Nasi Campur";
harga[i] = 130000;
} else if (pil==15) {
menu[i]= "Nasi Tempe Penyet";
harga[i] = 150000;
} else if (pil==16) {
menu[i]= "Nasi Padang";
harga[i] = 190000;
} else if (pil==17) {
menu[i]= "Nasi Peteng";
harga[i] = 190000;
} else if (pil==18) {
menu[i]= "Soto";
harga[i] = 160000;
} else if (pil==19) {
menu[i]= "Kare Ayam";
harga[i] = 150000;
} else if (pil==20) {
menu[i]= "Krupuk";
harga[i] = 50000;
} else {
System.out.println("Maaf pilihan menu anda tidak tepat ");
menu[i]= "Tidak Ada";
}
System.out.println("Anda Memesan : "+menu[i]);
System.out.println("Harga : "+harga[i]);
System.out.print("Ingin Memesan Lagi ? Y/T : ");
try{
keputusan = input2.readLine();
}catch(IOException e){
System.out.println("Gagal Membaca Keyboard");
}
i++;}
System.out.println("");
System.out.println("Total Pesanan Anda : "+i);
for (int a = 0; a<i;a++){
System.out.print(menu[a]+", ");
}
System.out.println("");
for (int b = 0; b<i;b++){
hargatotal = hargatotal + harga[b];
}
System.out.println("Total : Rp."+hargatotal);
}
private static void minuman(){
Scanner input = new Scanner (System.in);
BufferedReader input2 = new BufferedReader (new InputStreamReader (System.in));
int i = 0;
int pil ;
int hargatotal = 0;
int penampung = 0;
String menu[] = new String [100];
int harga[] = new int [100];
String keputusan="Y";
while (keputusan.equals("Y")||keputusan.equals("y"))
{
System.out.println("======================================= ");
System.out.println("| Daftar Menu Minuman |");
System.out.println("======================================= ");
System.out.println("| 1. Es Kopi = Rp 30.000 |");
System.out.println("| 2. Kopi = Rp 30.000 |");
System.out.println("| 3. Es Jeruk = Rp 30.000 |");
System.out.println("| 4. Jeruk = Rp 30.000 |");
System.out.println("| 5. Es Teh = Rp 30.000 |");
System.out.println("| 6. Teh = Rp 30.000 |");
System.out.println("| 7. Aneka Jus = Rp 35.000 |");
System.out.println("| 8. Es Degan = Rp 40.000 |");
System.out.println("| 9. Soda Gembira = Rp 50.000 |");
System.out.println("| 10. Vodka = Rp 100.000 |");
System.out.println("---------------------------------------");
System.out.print("Pilih menu anda = ");
pil = input.nextInt();
if (pil==1) {
menu[i]= "Es Kopi";
harga[i] = 30000;
} else if (pil==2) {
menu[i]= "Kopi";
harga[i] = 30000;
} else if (pil==3) {
menu[i]= "Es Jeruk";
harga[i] = 30000;
} else if (pil==4) {
menu[i]= "Jeruk";
harga[i] = 30000;
} else if (pil==5) {
menu[i]= "Es Teh";
harga[i] = 30000;
} else if (pil==6) {
menu[i]= "Teh";
harga[i] = 30000;
} else if (pil==7) {
menu[i]= "Aneka Jus";
harga[i] = 35000;
} else if (pil==8) {
menu[i]= "Es Degan";
harga[i] = 40000;
} else if (pil==9) {
menu[i]= "Soda Gembira";
harga[i] = 50000;
} else if (pil==10) {
menu[i]= "Vodka";
harga[i] = 100000;
} else {
System.out.println("Maaf pilihan menu anda tidak tepat ");
menu[i]= "Tidak Ada";
}
System.out.println("Anda Memesan : "+menu[i]);
System.out.println("Harga : "+harga[i]);
System.out.print("Ingin Memesan Lagi ? Y/T : ");
try{
keputusan = input2.readLine();
}catch(IOException e){
System.out.println("Gagal Membaca Keyboard");
}
i++;}
System.out.println("");
System.out.println("Total Pesanan Anda : "+i);
for (int a = 0; a<i;a++){
System.out.print(menu[a]+", ");
}
System.out.println("");
for (int b = 0; b<i;b++){
hargatotal = hargatotal + harga[b];
}
System.out.println("Total : Rp."+hargatotal);
}
}
Hasil Output
Jika Memilih No.1 Maka Yang Muncul Adalah
Jika Memilih No.1-20 Maka Yang Muncul Adalah
Jika Memilih Y Maka Lanjut Memesan Makanan Lagi,
Jika Memilih T Maka Kembali Ke Menu Seperti Gambar Ke 1
Jika Memilih No.21 Sampai Seterunya Maka Yang Muncul Adalah
Jika Memilih Y Maka Lanjut Memesan Makanan Lagi,
Jika Memilih T Maka Kembali Ke Menu Seperti Gambar Ke 1
____________________________________________________________________________________________________________
Jika Memilih No.2 Maka Yang Muncul Adalah
Jika Memilih No.1-10 Maka Yang Muncul Adalah
Jika Memilih Y Maka Lanjut Memesan Minuman Lagi,
Jika Memilih T Maka Kembali Ke Menu Seperti Gambar Ke 1
Jika Memilih No.11 Sampai Seterunya Maka Yang Muncul Adalah
Jika Memilih Y Maka Lanjut Memesan Minunan Lagi,
Jika Memilih T Maka Kembali Ke Menu Seperti Gambar Ke 1
____________________________________________________________________________________________________________
Jika Memilih No.3 Maka Yang Muncul Adalah
Langsung Keluar Dari Program
Komentar
Posting Komentar