Pemrograman 10 (Method)
Source Code:
package method;
import java.util.Scanner;
public class LatMethod {
static int harga[]=new int[16];
static String[] sort(String[]menu){
for (int i = 0; i < menu.length ; i++) {
for (int j = 0; j < menu.length-1; j++) {
if(menu[j].compareToIgnoreCase(menu[j+1])>0){
String m=menu[j];
menu[j]=menu[j+1];
menu[j+1]=m;
int h=harga[j];
harga[j]=harga[j+1];
harga[j+1]=h;
}
}
}
return menu;
}
static String[][] search(String[] makanan, int harga[], String cari){
String[][] hasil=new String[6][6];
int idx=0;
for (int i = 0; i < makanan.length; i++) {
if(makanan[i].indexOf(cari)>=0){
hasil[idx][0]=makanan[i];
hasil[idx][1]=String.valueOf(harga[i]);
idx++;
}
}
return hasil;
}
static String[][] search(String[] minuman,String cari, int harga[]){
String[][] hasil=new String[5][5];
int a=0;
for (int i = 0; i < minuman.length; i++) {
if(minuman[i].indexOf(cari)>=0){
hasil[a][0]=minuman[i];
hasil[a][1]=String.valueOf(harga[i]);
a++;
}
}
return hasil;
}
static String[][] search(int harga[], String cari,String[] camilan){
String[][] hasil=new String[5][5];
int b=0;
for (int i = 0; i < camilan.length; i++) {
if(camilan[i].indexOf(cari)>=0){
hasil[b][0]=camilan[i];
hasil[b][1]=String.valueOf(harga[i]);
b++;
}
}
return hasil;
}
public static void main(String[] args) {
Scanner N = new Scanner(System.in);
String makanan[]=new String[6];
String minuman[]=new String[5];
String camilan[]=new String[5];
//Daftar Menu Makanan
harga[0] = 13000; makanan[0]="Nasi Goreng";
harga[1] = 25000; makanan[1]="Ayam Bakar";
harga[2] = 3000; makanan[2]="Bebek Sinjay";
harga[3] = 15000; makanan[3]="Spaghetti";
harga[4] = 13000; makanan[4]="Bakso Sapi";
harga[5] = 20000; makanan[5]="Rendang";
//Daftar Menu Minuman
harga[0] = 10000; minuman[0]="Susu Sapi";
harga[1] = 12000; minuman[1]="Jus Jeruk";
harga[2] = 5000; minuman[2]="Air Mineral";
harga[3] = 14000; minuman[3]="Jus Alpukat";
harga[4] = 10000; minuman[4]="Es Teh";
//Daftar Menu Camilan
harga[0] = 10000; camilan[0]="Es Cream";
harga[1] = 12000; camilan[1]="Dimsum";
harga[2] = 10000; camilan[2]="Sosis Bakar";
harga[3] = 15000; camilan[3]="Roti Bakar";
harga[4] = 12000; camilan[4]="Lumpia";
int pilih=0;
System.out.println("-----------------------------");
System.out.println("SELAMAT DATANG DI WARUNG KU");
System.out.println("-----------------------------");
do{
System.out.println("");
System.out.println("PILIHAN MENU");
System.out.println("1.Daftar Menu Makanan");
System.out.println("2.Daftar Menu Minuman");
System.out.println("3.Daftar Menu Camilan");
System.out.println("4.Exit");
System.out.println("-----------------------------");
System.out.print("Pilih = ");
pilih = N.nextInt();
switch(pilih){
case 1:
System.out.println("-----------------------------");
System.out.println("\tLIST MENU");
System.out.println("-----------------------------");
System.out.println("1.Daftar Makanan");
System.out.println("2.Cari Makanan");
System.out.print("Pilih = ");
int pilih2 = N.nextInt();
switch(pilih2){
case 1:
String[] urut=sort(makanan);
System.out.println("-----------------------------");
System.out.println("\tDAFTAR MENU MAKANAN");
System.out.println("-----------------------------");
System.out.println("MENU\t\t| HARGA");
System.out.println("");
for (int i = 0; i < 5; i++) {
System.out.println((i+1)+"."+urut[i] + "\t| " + "Rp. " + harga[i]);
}
break;
case 2:
System.out.print("Cari Makanan = ");
String c = N.next();
String hasilcari[][] = search(makanan,harga,c);
System.out.println("\tHASIL PENCARIAN");
System.out.println("-----------------------------");
System.out.println("MENU\t\t| HARGA");
for (int i = 0; i < hasilcari.length; i++) {
if(hasilcari[i][0]!=null)
System.out.println((i+1)+"."+hasilcari[i][0]+ "\t| " +" Rp "+hasilcari[i][1]);
}
break;
}
break;
case 2:
System.out.println("");
System.out.println("\tLIST MENU");
System.out.println("1.Daftar Minuman");
System.out.println("2.Cari Minuman");
System.out.print("Pilih = ");
pilih2 = N.nextInt();
switch(pilih2){
case 1:
String[] urut=sort(minuman);
System.out.println("-----------------------------");
System.out.println("\tDAFTAR MENU MINUMAN");
System.out.println("-----------------------------");
System.out.println("MENU\t\t| HARGA");
System.out.println("");
for (int i = 0; i < 5; i++) {
System.out.println((i+1)+"."+urut[i] + "\t| " + "Rp. " + harga[i]);
}
break;
case 2:
System.out.print("Cari Minuman = ");
String c = N.next();
String hasilcari[][] = search(minuman,harga,c);
System.out.println("\tHASIL PENCARIAN");
System.out.println("-----------------------------");
System.out.println("MENU\t\t| HARGA");
for (int i = 0; i < hasilcari.length; i++) {
if(hasilcari[i][0]!=null)
System.out.println((i+1)+"."+hasilcari[i][0]+ "\t| " +" Rp "+hasilcari[i][1]);
}
break;
}
break;
case 3:
System.out.println("-----------------------------");
System.out.println("\tLIST MENU");
System.out.println("-----------------------------");
System.out.println("1.Daftar Camilan");
System.out.println("2.Cari Camilan");
System.out.print("Pilih = ");
pilih2 = N.nextInt();
switch(pilih2){
case 1:
String[] urut=sort(camilan);
System.out.println("-----------------------------");
System.out.println("\tDAFTAR MENU Camilan");
System.out.println("-----------------------------");
System.out.println("MENU\t\t| HARGA");
System.out.println("");
for (int i = 0; i < 5; i++) {
System.out.println((i+1)+"."+urut[i] + "\t| " + "Rp. " + harga[i]);
}
break;
case 2:
System.out.print("Cari Camilan = ");
String c = N.next();
String hasilcari[][] = search(camilan,harga,c);
System.out.println("\tHASIL PENCARIAN");
System.out.println("-----------------------------");
System.out.println("MENU\t\t| HARGA");
for (int i = 0; i < hasilcari.length; i++) {
if(hasilcari[i][0]!=null)
System.out.println((i+1)+"."+hasilcari[i][0]+ "\t| " +" Rp "+hasilcari[i][1]);
}
}
break;
}
}while(pilih!=4);
System.out.println("-----------------------------");
System.out.println("\tTERIMA KASIH");
System.out.println("-----------------------------");
}
}
Output:
Komentar
Posting Komentar