Nama : Novia Citra Fadhlilla
NPM : 22082010216
Kelas : E
Source Code :
package methodd;
import java.util.Scanner;
public class Methodd {
//Variabel Global
static int Harga[] = new int[20];
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 t = menu[j];
menu[j] = menu[j + 1];
menu[j + 1] = t;
int h = Harga[j];
Harga[j] = Harga[j + 1];
Harga[j + 1] = h;
}
}
}
return menu;
}
static String[][] search(String[] menu, int harga[], String cari) {
String hasil[][] = new String[10][4];
int idx = 0;
for (int i = 0; i < menu.length; i++) {
if (menu[i].indexOf(cari) >= 0) {
hasil[idx][0] = menu[i];
hasil[idx][1] = String.valueOf(harga[i]);
hasil[idx][2] = String.valueOf(harga[i + 3]);
hasil[idx][3] = String.valueOf(harga[i + 9]);
idx++;
}
}
return hasil;
}
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
String Makanan[] = new String[10];
String Minuman[] = new String[5];
String Snack[] = new String[5];
// Int harga[]= new Int[5];
//Inisialisasi Array
Snack[0] = "Chitato";
Harga[0] = 15000;
Snack[1] = "Lays";
Harga[1] = 18000;
Snack[2] = "Piattos";
Harga[2] = 12000;
Snack[3] = "Oreo";
Harga[3] = 9000;
Snack[4] = "Nabati";
Harga[4] = 6000;
Minuman[0] = "Es Teh";
Harga[3] = 4000;
Minuman[1] = "Es Jeruk";
Harga[4] = 5000;
Minuman[2] = "Teh Hangat";
Harga[5] = 3000;
Minuman[3] = "Jeruk Hangat";
Harga[6] = 4000;
Minuman[4] = "Aqua";
Harga[7] = 3000;
Makanan[0] = "Sate Ayam";
Harga[8] = 13000;
Makanan[1] = "Sate Kambing";
Harga[9] = 25000;
Makanan[2] = "Sate Kelopo";
Harga[10] = 13000;
Makanan[3] = "Gulai";
Harga[11] = 15000;
Makanan[4] = "Rawon";
Harga[12] = 12000;
Makanan[5] = "Soto Ayamn";
Harga[13] = 12000;
Makanan[6] = "Soto Daging";
Harga[14] = 12000;
Makanan[7] = "Rendang";
Harga[15] = 15000;
Makanan[8] = "Kare Ayam";
Harga[16] = 10000;
Makanan[9] = "Opor Ayam";
Harga[17] = 10000;
int pilih = 0;
do {
System.out.println("====== DAFTAR PILIHAN WARUNG BERKAH ======");
System.out.println("1.Pilihan Makanan");
System.out.println("2.Pilihan Minuman");
System.out.println("3.Pilihan Snack");
System.out.println("4.Keluar");
System.out.print("Pilih = ");
pilih = sc.nextInt();
switch (pilih) {
case 1:
System.out.println("1.Daftar Menu Makanan");
System.out.println("2.Cari Makanan");
System.out.print("3.Pilih = ");
int pilih2 = sc.nextInt();
switch (pilih2) {
case 1:
String[] urut = sort(Makanan);
System.out.println("Menu Makanan");
for (int i = 0; i < 10; i++) {
System.out.println(i + 1 + "." + urut[i]);
}
break;
case 2:
System.out.print("Cari = ");
String m = sc.next();
String hasilcari[][] = search(Makanan, Harga, m);
System.out.println("Hasil Pencarian");
for (int i = 0; i < hasilcari.length; i++) {
if (hasilcari[i][0] != null) {
System.out.println((i + 1) + "." + hasilcari[i][0] + " ");
System.out.println(Integer.parseInt(hasilcari[i][3]));
}
}
break;
}
break;
case 2:
System.out.println("1.Daftar Menu Minuman");
System.out.println("2.Cari Minuman");
System.out.print("3.Pilih = ");
pilih2 = sc.nextInt();
switch (pilih2) {
case 1:
String[] urut = sort(Minuman);
System.out.println("Menu Minuman");
for (int i = 0; i < urut.length; i++) {
System.out.println(i + 1 + "." + urut[i]);
}
System.out.println("");
break;
case 2:
System.out.print("Cari = ");
String m = sc.next();
String hasilcari[][] = search(Minuman, Harga, m);
System.out.println("Hasil Pencarian");
for (int i = 0; i < hasilcari.length; i++) {
if (hasilcari[i][0] != null) {
System.out.println((i + 1) + "." + hasilcari[i][0] + " ");
System.out.println(Integer.parseInt(hasilcari[i][2]));
}
}
break;
}
break;
case 3:
System.out.println("1.Daftar Menu Snack");
System.out.println("2.Cari Snack");
System.out.print("3.Pilih = ");
pilih2 = sc.nextInt();
switch (pilih2) {
case 1:
String[] urut = sort(Snack);
System.out.println("Menu Snack");
for (int i = 0; i < urut.length; i++) {
System.out.println(i + 1 + "." + urut[i]);
}
System.out.println("");
break;
case 2:
System.out.print("Cari = ");
String s = sc.next();
String hasilcari[][] = search(Snack, Harga, s);
System.out.println("Hasil Pencarian");
for (int i = 0; i < hasilcari.length; i++) {
if (hasilcari[i][0] != null) {
System.out.println((i + 1) + "." + hasilcari[i][0] + " ");
System.out.println(Integer.parseInt(hasilcari[i][1]));
}
}
break;
}
break;
case 4:
System.out.println("TERIMAKASIH");
break;
}
} while (pilih != 4);
}
}
Hasil Run :
====== DAFTAR PILIHAN WARUNG BERKAH ======
1.Pilihan Makanan
2.Pilihan Minuman
3.Pilihan Snack
4.Keluar
Pilih = 1
1.Daftar Menu Makanan
2.Cari Makanan
3.Pilih = 1
Menu Makanan
1.Gulai
2.Kare Ayam
3.Opor Ayam
4.Rawon
5.Rendang
6.Sate Ayam
7.Sate Kambing
8.Sate Kelopo
9.Soto Ayamn
10.Soto Daging
====== DAFTAR PILIHAN WARUNG BERKAH ======
1.Pilihan Makanan
2.Pilihan Minuman
3.Pilihan Snack
4.Keluar
Pilih = 1
1.Daftar Menu Makanan
2.Cari Makanan
3.Pilih = 2
Cari = Rawon
Hasil Pencarian
1.Rawon
12000
====== DAFTAR PILIHAN WARUNG BERKAH ======
1.Pilihan Makanan
2.Pilihan Minuman
3.Pilihan Snack
4.Keluar
Pilih = 4
TERIMAKASIH
BUILD SUCCESSFUL (total time: 17 seconds)